What Is New in Rust 1.62
| Category | Highlights |
|---|---|
| New Features | cargo add command, #[default] on enum variants, bare-metal x86_64-unknown-none target |
| Improvements | Futex-based Mutex/Condvar/RwLock on Linux (5-byte Mutex), Tier-2 promotion of x86_64-unknown-none |
How can I add dependencies directly from the command line with Cargo?
In Rust 1.62 you can add new crates without editing Cargo.toml by using the new cargo add subcommand.
- Basic addition:
cargo add log - Specify features:
cargo add serde --features derive - Pin a version:
cargo add nom@5
This matters if you want to prototype quickly or automate dependency updates in CI pipelines.
How do I derive Default for enums in Rust 1.62?
You can now annotate a unit variant with #[default] and keep the automatic #[derive(Default)] implementation.
#[derive(Default)]\nenum Maybe {\n #[default]\n Nothing,\n Something(T),\n}
Only variants without fields are allowed to be the default, which simplifies boilerplate for many option-like enums.
What performance gains do the new Linux mutex implementations bring?
The standard library now uses a raw futex-based lock on Linux, shrinking the internal state of Mutex to just 5 bytes.
- No hidden heap allocation - the lock lives entirely on the stack.
- Reduced memory footprint improves cache locality for high-contention workloads.
- Future work may further shrink
CondvarandRwLocksimilarly.
In practice this matters for low-level services, embedded daemons, or any code that creates many synchronization primitives.
How do I target bare-metal x86_64 with the new Tier-2 support?
Rust 1.62 promotes the x86_64-unknown-none target to Tier 2, making it easy to build OS-less binaries.
rustup target add x86_64-unknown-none\nrustc --target x86_64-unknown-none my_no_std_program.rs
This matters if you are writing kernels, bootloaders, or other no_std environments; the target is now officially supported and receives regular updates.
Frequently Asked Questions
What command updates Rust to the latest stable version?
rustup update stable
Can I use cargo add to specify a version range?
Yes you can add a dependency with a specific version like cargo add nom@5
Which enum variants can be marked #[default]?
Only unit variants without fields can be annotated with #[default]
How much memory does a Mutex now occupy on Linux?
In Rust 1.62 a Mutex needs only 5 bytes for its internal state on Linux
Do I need to enable any feature to use the x86_64-unknown-none target?
No extra feature flags are required; just add the target with rustup target add x86_64-unknown-none and compile with --target
Are there any breaking changes in Rust 1.62?
The release does not introduce breaking changes; existing code should compile unchanged