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:
The feature gate is not yet confirmed. Possible options include:
or reusing the existing ergonomic ref-counting gate:
#![feature(ergonomic_clones)]
cc @nikomatsakis
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:
Share means “clone-as-alias”.
Share does 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 possible minimal shape is:
pub trait Share: Clone {
fn share(&self) -> Self {
Clone::clone(self)
}
}
The exact public location, feature gate, default method body, and initial impl set still need confirmation.
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> {}
These should be confirmed before implementation, especially the sender-like impl set.
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>
String
Box<T>
HashMap<K, V>
BTreeMap<K, V>
- owned arrays
- other owned collection types where
clone() creates independent owned storage
Steps
Unresolved questions
Implementation history
- Initial tracking issue: this issue.
Tracking Issue for
SharetraitThis is a tracking issue for the unstable
Sharetrait, proposed as part of the 2026 ergonomic ref-counting project goal.Project goal:
The feature gate is not yet confirmed. Possible options include:
#![feature(share_trait)]or reusing the existing ergonomic ref-counting gate:
#![feature(ergonomic_clones)]cc @nikomatsakis
Summary
The
Sharetrait 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 toclone(), 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 possible minimal shape is:
The exact public location, feature gate, default method body, and initial impl set still need confirmation.
Scope
This tracking issue is only for the
Sharetrait part of ergonomic ref-counting.Candidate initial impls
The project-goal sketch lists the following initial candidates:
Additional sender-like candidates to evaluate:
These should be confirmed before implementation, especially the sender-like impl set.
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>clone()creates independent owned storageSteps
Confirm feature gate.
share_traitfeature gate.ergonomic_clonesinstead.Decide public location and module organization.
Shareshould live nearClone, for example incore::clone.core,alloc, andstd.Shareshould not be added to the prelude initially.Add the unstable trait API.
pub trait Share: Clone.fn share(&self) -> Self.Clone::clone(self)orself.clone().Add
Sharefor shared references.impl<T: ?Sized> Share for &T {}..share()on shared references.Add
ShareforRc<T>.impl<T: ?Sized> Share for Rc<T> {}.Rc::ptr_eq.Add
ShareforArc<T>.impl<T: ?Sized> Share for Arc<T> {}.Arc::ptr_eq.Evaluate channel sender impls.
std::sync::mpsc::Sender<T>should implementShare.std::sync::mpsc::SyncSender<T>should implementShare.Audit impl
Add tests.
Add documentation.
Shareis for clone-as-alias types.share()is equivalent toclone()for implementors.Arc<T>,Rc<T>, shared references, and channel senders.Vec<T>,String, andBox<T>.Stabilization PR, after implementation experience and API review.
Unresolved questions
share_traitgate, or reuseergonomic_clones?Sharelive publicly?Share?Shareremain out of the prelude during experimentation?Clone::clone(self)?Shareis semantic, not cost-based?Weak<T>forRc/Arcbe considered later, or explicitly left out?Implementation history