Skip to content

Add unstable Share trait#156828

Merged
rust-bors[bot] merged 13 commits into
rust-lang:mainfrom
P8L1:share-trait-core-bootstrap
May 24, 2026
Merged

Add unstable Share trait#156828
rust-bors[bot] merged 13 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
46 tasks
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the F-ergonomic_clones `#![feature(ergonomic_clones)]` label May 22, 2026
Comment thread compiler/rustc_feature/src/unstable.rs Outdated
@SimonSapin
Copy link
Copy Markdown
Contributor

@bors r+ rollup

Additions are unstable and match https://rust-lang.github.io/rust-project-goals/2026/ergonomic-rc.html#the-share-trait

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 23, 2026

📌 Commit 2f953da has been approved by SimonSapin

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 23, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request May 23, 2026
…=SimonSapin

Add unstable Share trait

Tracking issue: rust-lang#156756

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

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

This PR adds a separate unstable feature gate:

```rust
#![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
rust-bors Bot pushed a commit that referenced this pull request May 23, 2026
Rollup of 4 pull requests

Successful merges:

 - #156736 (Fix jump to def link generation on primitive type associated methods)
 - #156828 (Add unstable Share trait)
 - #156830 (Add `#[doc(alias = "phi")]` for float `GOLDEN_RATIO` constants)
 - #156860 (Fix Pieter-Louis Schoeman mailmap entry)
rust-bors Bot pushed a commit that referenced this pull request May 24, 2026
…uwer

Rollup of 6 pull requests

Successful merges:

 - #156769 (Use print instead of po in debuginfo path test)
 - #156784 (Fix reborrow_info early return skipping field validation)
 - #156827 (float_literal_f32_fallback: Don't suggest invalid code)
 - #156828 (Add unstable Share trait)
 - #156830 (Add `#[doc(alias = "phi")]` for float `GOLDEN_RATIO` constants)
 - #156860 (Fix Pieter-Louis Schoeman mailmap entry)
@rust-bors rust-bors Bot merged commit eb68b36 into rust-lang:main May 24, 2026
11 checks passed
@rustbot rustbot added this to the 1.98.0 milestone May 24, 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

5 participants