Rust项目提出在类型系统中引入三项新特征,以扩展类型的可操作能力[1]。这些特征分别为Move(表示类型可在内存中重定位)、Destruct(表示类型可隐式丢弃)和Forget(表示类型可通过mem::forget遗忘),允许类型选择退出历史上默认的移动和遗忘行为[1]。
该提案旨在解决自引用类型和需要保证析构函数执行的类型所面临的问题[1]。其中,实现!Move类型将使不可移动性成为类型属性而非位置属性,相比现有的Pin机制更为简洁[1]。同时,实现!Forget允许类型保证析构函数必然运行,这将解锁safe scoped spawn等编程模式[1]。
这项工作遵循Sized特征层级工作的先例,放宽了"所有类型都可以移动"和"所有类型都可以被遗忘"这两个长期假设[1]。根据计划,该工作将在编译器中实现最小可行产品、编写RFC规范,并在Linux内核中进行实际验证[1]。该提案明确范围外不涉及今年对Future特征的改动或更新[1]。
The Rust project has proposed introducing three new traits to describe the operational capabilities of types: Move, Destruct, and Forget.[1] These traits would allow types to opt out of historically default behaviors—specifically, the ability to be moved in memory, implicitly discarded, or forgotten through mem::forget.[1]
The Move trait would enable immobile types by making non-moveability a type property rather than a positional attribute, offering a more elegant solution compared to the existing Pin mechanism.[1] Meanwhile, the Forget trait would permit types to prevent being forgotten, guaranteeing that destructors execute and unlocking patterns such as safe scoped spawn.[1] This work follows precedent established by the Sized trait hierarchy, relaxing the assumptions that all types can be moved and all types can be forgotten.[1]
The initiative addresses challenges faced by self-referential types and types requiring guaranteed destructor execution.[1] Implementation plans include developing a minimal viable product in the compiler, writing an RFC, and validating the approach in the Linux kernel.[1] The project has clarified that modifications or updates to the Future trait are explicitly out of scope for this year.[1]