Repository navigation
Description
Tracking Issue for Share trait
This is a tracking issue for the unstable Share trait, proposed as part of the 2026 ergonomic ref-counting project goal.
Project goal:
- https://rust-lang.github.io/rust-project-goals/2026/ergonomic-rc.html
- Ergonomic ref-counting goals#107
The feature gate is:
#![feature(share_trait)]Summary
The Share trait identifies types where cloning creates another alias, handle, or reference to the same underlying value.
The intended distinction is semantic, not operational:
Sharemeans “clone-as-alias”.Sharedoes not merely mean “cheap clone”, “O(1) clone”, or “allocation-free clone”.
For implementors, share() would be equivalent to clone(), but it communicates that the old and new values are connected to the same underlying value or resource rather than being independent owned copies.
A minimal shape is:
pub trait Share: Clone {
final fn share(&self) -> Self {
Clone::clone(self)
}
}Scope
This tracking issue is only for the Share trait part of ergonomic ref-counting.
Candidate initial impls
The project-goal sketch lists the following initial candidates:
impl<T: ?Sized> Share for Arc<T> {}
impl<T: ?Sized> Share for Rc<T> {}
impl<T: ?Sized> Share for &T {}
impl<T> Share for std::sync::mpsc::Sender<T> {}Additional sender-like candidates to evaluate:
impl<T> Share for std::sync::mpsc::SyncSender<T> {}Non-examples
The following should not implement Share, because cloning creates an independent owned value rather than another alias/handle/reference to the same underlying value:
Vec<T>StringBox<T>HashMap<K, V>BTreeMap<K, V>- owned arrays
- other owned collection types where
clone()creates independent owned storage
Steps
-
Confirm feature gate.
- Decide whether to use a new
share_traitfeature gate. - Connect the feature gate to the correct tracking issue.
- Decide whether to use a new
-
Decide public location and module organization.
- Confirm whether
Shareshould live nearClone, for example incore::clone. - Confirm public re-export expectations from
core,alloc, andstd. - Confirm that
Shareshould not be added to the prelude initially.
- Confirm whether
-
Add the unstable trait API.
- Add
pub trait Share: Clone. - Add
fn share(&self) -> Self. - Confirm whether the default body should use
Clone::clone(self)orself.clone(). - Add unstable attributes and feature-gate diagnostics.
- Add
-
Add
Sharefor shared references.- Add
impl<T: ?Sized> Share for &T {}. - Add tests for
.share()on shared references. - Confirm that mutable references are not candidates.
- Add
-
Add
ShareforRc<T>.- Add
impl<T: ?Sized> Share for Rc<T> {}. - Add tests showing that sharing preserves allocation identity, for example with
Rc::ptr_eq. - Add tests showing observable shared state where appropriate.
- Add
-
Add
ShareforArc<T>.- Add
impl<T: ?Sized> Share for Arc<T> {}. - Add tests showing that sharing preserves allocation identity, for example with
Arc::ptr_eq. - Add tests showing observable shared state where appropriate.
- Add
-
Evaluate channel sender impls.
- Confirm whether
std::sync::mpsc::Sender<T>should implementShare. - Confirm whether
std::sync::mpsc::SyncSender<T>should implementShare. - Add tests showing that both handles send to the same receiver.
- Confirm whether
-
Audit impl
-
Add tests.
- Feature-gate tests.
- Method-availability tests.
- Positive impl tests for accepted candidates.
- Negative tests for non-implementors if desired.
- Documentation tests where appropriate.
-
Add documentation.
- Document that
Shareis for clone-as-alias types. - Document that
share()is equivalent toclone()for implementors. - Document that the distinction is semantic rather than cost-based.
- Include examples such as
Arc<T>,Rc<T>, shared references, and channel senders. - Include non-examples such as
Vec<T>,String, andBox<T>.
- Document that
-
Make Share trait final
-
Libs team ACP
-
Stabilization PR, after implementation experience and API review.
Unresolved questions
- Are there any object-safety or dyn-compatibility concerns worth documenting?
Implementation history
- Initial tracking issue: this issue.
- Initial implementation PR: Add unstable Share trait #156828
Activity
P8L1 commentedon May 19, 2026
Rollup merge of rust-lang#156828 - P8L1:share-trait-core-bootstrap, r…
Rollup merge of rust-lang#156828 - P8L1:share-trait-core-bootstrap, r…
Rollup merge of rust-lang#157655 - P8L1:share-trait-final-docs, r=nik…
Rollup merge of rust-lang#157655 - P8L1:share-trait-final-docs, r=nik…
Rollup merge of rust-lang#157655 - P8L1:share-trait-final-docs, r=nik…
Rollup merge of rust-lang#157655 - P8L1:share-trait-final-docs, r=nik…
Unrolled build for #157655
Rollup merge of #157655 - P8L1:share-trait-final-docs, r=nikomatsakis