What Is New in Rust 1.32
| Category | Highlights |
|---|---|
| New Features | dbg! macro, system allocator as default, uniform paths for imports, literal matcher and ? repetition in macro_rules, const fn expansion, endian-aware byte-array conversions. |
| Improvements | Module system polish, Cargo alias for check (cargo c) and registry URL usernames, minor macro ergonomics. |
How does the new dbg! macro simplify debugging in Rust?
The dbg! macro prints the source location, expression, and its value while returning the original value.
In practice you can replace noisy println! or eprintln! statements with a single macro call:
fn main() {
let x = 5;
dbg!(x);
}
The output includes the file and line number, e.g., [src/main.rs:4] x = 5, and the macro evaluates to x, so it fits seamlessly into existing expressions.
What is the impact of switching the default allocator to the system allocator?
Rust 1.32 now uses the platform's native allocator instead of jemalloc by default.
This reduces binary size by roughly 300 KB and aligns memory-allocation behavior with other native tools, which can simplify profiling and debugging on all platforms.
If you still need jemalloc, add the jemallocator crate and declare a global allocator:
jemallocator = "0.1.8"
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
Most teams will see no functional change; the switch mainly affects binary size and allocator-specific tuning.
How do uniform paths change the way we write use statements?
Uniform paths allow import paths to be written the same way as ordinary paths, removing the need for leading self, super, or crate in many cases.
For example, importing enum variants becomes straightforward:
enum Color { Red, Green, Blue }
use Color::*;
This works because the compiler now resolves the path uniformly, simplifying module hierarchies and reducing boilerplate.
What macro enhancements were introduced in Rust 1.32?
Rust 1.32 adds a literal matcher and the optional repetition operator ? to macro_rules! macros.
The literal matcher lets a macro accept any literal type:
macro_rules! m {
($lt:literal) => {};
}
m!("string");
m!(42);
m!('c');
The ? operator matches zero or one repetitions, complementing * and + for more flexible pattern matching.
Frequently Asked Questions
Can I keep using jemalloc after upgrading to Rust 1.32?
Yes, add the jemallocator crate and annotate a static with #[global_allocator] as shown in the release notes.
Does the dbg! macro affect release builds?
It is compiled out in release mode when the debug_assertions cfg is disabled, so there is no runtime cost.
Do I need to change any existing Cargo commands?
No, existing commands work unchanged; cargo c is just a new alias for cargo check.
How do I write a macro that accepts any literal?
Use the $lt:literal matcher inside macro_rules as demonstrated in the documentation.
What is the syntax for the new optional repetition operator?
Place a question mark after the pattern, for example $(a)? matches zero or one a token.
Are the new endian conversion functions stable?
Yes, all integral numeric primitives now have to_ne_bytes, from_ne_bytes, and their le/be variants.