Skip to content

Ergonomic ref-counting: RFC decision and preview #107

@nikomatsakis

Description

@nikomatsakis
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