rust-lang / rust-lang/rust

Tracking issue: `Move` trait

Open
#149,607 8 comments 101 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

B-experimental C-tracking-issue I-lang-radar T-lang T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

This is a tracking issue for experimental work related to the Move auto 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 Move that 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-trait Move with default bounds:

#[lang = "default_trait"]
unsafe auto trait Move {}

By default all types implement Move which 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 Move trait and enabling the compiler to enforce those checks. We’re intentionally not (yet) focusing on backwards-compatibility with existing traits, migrating existing uses of Pin, 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 !Move types 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:

  • A new item kind pin in lvalues, e.g. &pin x, &pin mut x, &pin const x.
  • A one-off overload of Rust’s Drop trait, e.g. fn drop(&pin mut self).
  • A new item kind pin in 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 Move is the better direction. We’re filing for a lang experiment so we can prove this by implementing it.

Further Reading

Contacts

Some relevant contacts:

Steps

Unresolved Questions

Implementation History

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

This is a broad tracking issue rather than a self-contained task, and it names no source file or test. Start by reading the linked Move trait experiment and PR #146201, then choose one unchecked step such as dev-guide, Reference, or style-guide documentation. Done means completing that separately scoped contribution and updating the relevant checklist item.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.