Immobile Types and Guaranteed Destructors in Rust
A new era for memory management in Rust programming language
1New Type Traits in Rust
Rust is introducing new traits called Move and Forget to control how types behave in memory. These traits determine whether types can be relocated in memory and guarantee that their destructors will run. The Move trait specifies if a type can be moved, while the Forget trait ensures destructors must execute. These changes will particularly benefit async programming and areas like the Linux kernel, bringing significant improvements to memory safety and type system expressiveness.
2Current Limitations
Currently Rust assumes all types are movable and can be forgotten via mem::forget. However, this causes issues with self-referential types and certain operations. Async futures often contain self-referential structures that become unsafe when moved. The existing Pin solution addresses these problems but introduces significant complexity. The new traits aim to provide a more elegant solution to these challenges while maintaining Rust's safety guarantees.
3Move Trait Details
The Move trait determines whether a type can be relocated in memory. Defined as #[lang = "move"] unsafe auto trait Move { }, it encodes movability as a type property rather than a place property. Types that don't implement Move (!Move) are marked as immobile and must maintain a stable memory address. This approach offers a simpler and more intuitive solution compared to the current Pin system, especially for complex memory management scenarios.
4Forget Trait Functionality
The Forget trait controls whether types can be forgotten. An implementation like unsafe impl !Forget for ScopedTaskHandle { } specifies that ScopedTaskHandle cannot be forgotten and its destructor must run. This enables patterns currently impossible in safe Rust, such as safe scoped spawning in async programming. It also improves safety for critical operations like transactions that require guaranteed cleanup procedures.
5Impact on Linux Kernel
These changes are particularly significant for Rust's use in the Linux kernel. Safe management of self-referential types is crucial for kernel-level code. While the current Pin system introduces complexity in such environments, the new Move trait provides a simpler and safer alternative. This enhancement will strengthen Rust's position in system programming and make it more attractive for operating system development.
6Async Programming Improvements
The new traits will bring important benefits to async programming. Patterns like scoped spawn, currently impossible to implement safely, will become feasible. In cases where tasks need to borrow from parent scopes, the Forget trait guarantees destructor execution. This makes async code more predictable and safer, addressing one of the current pain points in Rust's async ecosystem.
7Migration and Compatibility
Introducing these traits will require a careful migration process. Stable traits like Future that depend on Pin will need separate updates. The Rust team is prioritizing backward compatibility while implementing these changes. The 2026-2027 roadmap includes completing MVPs for these features and conducting real-world testing, particularly focusing on the Linux kernel use case.
8Industry Impact and Future
These changes will reinforce Rust's leadership in memory safety. They'll increase Rust's adoption in system programming and high-performance applications. Critical domains like finance, automotive software, and embedded systems will particularly benefit from these advancements. The 2026-2027 roadmap goals represent a significant step forward in shaping Rust's future as a systems programming language.