Skip to content

Add unstable Share trait#156828

Open
P8L1 wants to merge 12 commits into
rust-lang:mainfrom
P8L1:share-trait-core-bootstrap
Open

Add unstable Share trait#156828
P8L1 wants to merge 12 commits into
rust-lang:mainfrom
P8L1:share-trait-core-bootstrap

Conversation

@P8L1
Copy link
Copy Markdown
Contributor

@P8L1 P8L1 commented May 22, 2026

Tracking issue: #156756

This adds an initial unstable Share trait for clone-as-alias types, as part of the 2026 ergonomic ref-counting project goal.

pub trait Share: Clone {
    fn share(&self) -> Self {
        Clone::clone(self)
    }
}

This PR adds a separate unstable feature gate:

#![feature(share_trait)]

and places the trait next to Clone in core::clone.

Implemented initial impls:

  • impl<T: ?Sized> Share for &T
  • impl<T: ?Sized, A: Allocator + Clone> Share for Rc<T, A>
  • impl<T: ?Sized, A: Allocator + Clone> Share for Arc<T, A>
  • impl<T> Share for std::sync::mpsc::Sender<T>
  • impl<T> Share for std::sync::mpsc::SyncSender<T>

The PR deliberately does not add Share to the prelude.

r? @nikomatsakis
@rustbot label F-ergonomic_clones

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 22, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 22, 2026

nikomatsakis is currently at their maximum review capacity.
They may take a while to respond.

@P8L1 P8L1 mentioned this pull request May 22, 2026
51 tasks
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the F-ergonomic_clones `#![feature(ergonomic_clones)]` label May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-ergonomic_clones `#![feature(ergonomic_clones)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants