-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Tracking issue: Move trait #149607
Copy link
Copy link
Open
Labels
B-experimentalBlocker: In-tree experiment; RFC pending, not yet approved or unneeded (requires FCP to stabilize).Blocker: In-tree experiment; RFC pending, not yet approved or unneeded (requires FCP to stabilize).C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCI-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.T-langRelevant to the language teamRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
B-experimentalBlocker: In-tree experiment; RFC pending, not yet approved or unneeded (requires FCP to stabilize).Blocker: In-tree experiment; RFC pending, not yet approved or unneeded (requires FCP to stabilize).C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCI-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.T-langRelevant to the language teamRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Projects
Status
No status
This is a tracking issue for experimental work related to the
Moveauto trait.The feature gate for the issue is
TODO.About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Discussion comments will get marked as off-topic or deleted.
Repeated discussions on the tracking issue may lead to the tracking issue getting locked.
Background
We’d like to propose an experiment for a new trait auto-trait
Movethat determines whether a type can be freely moved around or must keep a stable memory location. This is intended to be a safe and simple language-level alternative to the existing pinning system. At the heart of this is a new auto-traitMovewith default bounds:By default all types implement
Movewhich enables them to change memory locations, which is how Rust behaves today. But if a type chooses to implement!Move, the compiler will guarantee that that type will have a stable location in memory until it is has finished dropping.This work will initially only focus on introducing the
Movetrait and enabling the compiler to enforce those checks. We’re intentionally not (yet) focusing on backwards-compatibility with existing traits, migrating existing uses ofPin, or more advanced features like move-constructors.@lcnr and I recently ran an experiment for this in the compiler, proving that this work should be feasible. We were initially quite concerned with potential performance regressions, but on further investigation we determined this should be manageable.
Relationship to other experiments
In-place initialization
This work compliments Project Goal 2025H2: In-place initialization, which enables types to be constructed in a stable memory location. This makes it possible to return
!Movetypes directly from constructors without needing to copy data, which is done by writing data to an out-pointer rather than being copied out of a function.Pin ergonomics
This work is an alternative to Project Goal 2025H2: Continue Experimentation with Pin Ergonomics, which includes the following extensions:
pinin lvalues, e.g.&pin x,&pin mut x,&pin const x.Droptrait, e.g.fn drop(&pin mut self).pinin patterns, e.g.&pin <pat>.We will refrain from litigating the differences between proposals here. But suffice to say: we are aware of this proposal and we believe that
Moveis the better direction. We’re filing for a lang experiment so we can prove this by implementing it.Further Reading
Movetrait perf test #146201 lcnr, 2025Contacts
Some relevant contacts:
Steps
Unresolved Questions
Implementation History