Skip to content

Ergonomic ref-counting #107

Description

@nikomatsakis
Metadata
Point of contact @nikomatsakis
Team(s) compiler, lang, lang-docs, libs-api
Goal document 2026/ergonomic-rc

Summary

Implement and prototype two foundational improvements for ergonomic ref-counting: (1) a Share trait that semantically identifies types where cloning creates an alias to the same underlying value, and (2) move expressions (move($expr)) that allow precise control over what closures capture and when. These changes lay groundwork for future ergonomic improvements while delivering immediate value, with prototypes targeted for summer 2026.

Tasks and status


Note: we have updated the body to match the 2026 goal. Your original text is preserved below.

Details

Metadata
Point of contact @nikomatsakis
Team(s) compiler, lang, lang-docs, libs-api
Goal document 2026/ergonomic-rc

Summary

Implement and prototype two foundational improvements for ergonomic ref-counting: (1) a Share trait that semantically identifies types where cloning creates an alias to the same underlying value, and (2) move expressions (move($expr)) that allow precise control over what closures capture and when. These changes lay groundwork for future ergonomic improvements while delivering immediate value, with prototypes targeted for summer 2026.

Needs contributor: This is a medium complexity problem. @nikomatsakis would like to mentor this goal with either an experienced contributor or a cohort of folks who know Rust but not the compiler. It is estimated that the goal will take about 6 months to implement for a cohort with minimal compiler hacking experience.

Tasks and status


Note: we have updated the body to match the 2026 goal. Your original text is preserved below.

Metadata
Point of contact @nikomatsakis
Team(s) compiler, lang
Goal document 2025h2/ergonomic-rc

Summary

We propose to write an alternative RFC for ergonomic ref-counting that makes lightweight cloning automatic and hold design meetings so the lang team can compare both approaches. This work builds on RFC #3680, which proposed a new keyword, use, that could be used with closures (use || ...) and expressions like x.use to help address a longstanding problem: working with ref-counted data structures like Arc<T> is verbose and confusing.

The 2025H1 work delivered .use syntax that works technically, but community feedback on the RFC pointed out a tension: if we're trying to improve ergonomics, why add more required syntax? We'll write an RFC exploring the automatic approach, complete the implementation work needed to support it, and run design meetings to help the lang team decide. This will tell us about the impact on user experience and performance, how well we can catch problematic cases, and which approach works better for Rust developers working with ref-counted data.

Tasks and status


Note: we have updated the body to match the 2025h2 goal. Your original text is preserved below.

Metadata
Point of contact @spastorino
Team(s) lang
Goal document 2025h1/ergonomic-rc

Summary

  • Deliver a nightly implementation of the experimental use syntax for ergonomic ref-counting.
  • RFC decision on the above

Tasks and status

  • Implementation (@spastorino)
  • Reviews (@nikomatsakis)
  • Lang-team champion (lang Team)
  • Author RFC (@joshtriplett)
  • Introduce x.use and use || syntax and UseCloned trait (Ergonomic ref counting rust#134797).
  • Modify codegen so that we guarantee that x.use will do a copy if X: Copy is true after monomorphization. Right now the desugaring to clone occurs before monomorphization and hence it will call the clone method even for those instances where X is a Copy type.
  • Convert x.use to a move rather than a clone if this is a last-use.
  • Make x equivalent to x.use but with an (allow-by-default) lint to signal that something special is happened.

Metadata

Metadata

Assignees

Type

No type

Projects

Status
Project goal

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions