Files
rust/library/alloc
Jonathan Brouwer eb68b36521 Rollup merge of #156828 - P8L1:share-trait-core-bootstrap, r=SimonSapin
Add unstable Share trait

Tracking issue: rust-lang/rust#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
2026-05-24 08:27:21 +02:00
..