diff options
| author | bors <bors@rust-lang.org> | 2024-12-15 08:26:19 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-12-15 08:26:19 +0000 |
| commit | 87139bd9cfb999eff4025ff3d2ab5659c8082678 (patch) | |
| tree | 58ab98db8194b97261795bf2784a098579f7629f /library/std | |
| parent | 4790a435cbcb55c94ccdef51bf7a9b2e55824528 (diff) | |
| parent | 2d2225950fa193add623c430d2d2beb61a798e95 (diff) | |
Auto merge of #133223 - zachs18:uniquerc-impls, r=Noratrieb
`UniqueRc` trait impls UniqueRc tracking Issue: #112566 Stable traits: (i.e. impls behind only the `unique_rc_arc` feature gate) * Support the same formatting as `Rc`: * `fmt::Debug` and `fmt::Display` delegate to the pointee. * `fmt::Pointer` prints the address of the pointee. * Add explicit `!Send` and `!Sync` impls, to mirror `Rc`. * Borrowing traits: `Borrow`, `BorrowMut`, `AsRef`, `AsMut` * `Rc` does not implement `BorrowMut` and `AsMut`, but `UniqueRc` can. * Unconditional `Unpin`, like other heap-allocated types. * Comparison traits `(Partial)Ord` and `(Partial)Eq` delegate to the pointees. * `PartialEq for UniqueRc` does not do `Rc`'s specialization shortcut for pointer equality when `T: Eq`, since by definition two `UniqueRc`s cannot share an allocation. * `Hash` delegates to the pointee. * `AsRawFd`, `AsFd`, `AsHandle`, `AsSocket` delegate to the pointee like `Rc`. * Sidenote: The bounds on `T` for the existing `Pointer<T>` impls for specifically `AsRawFd` and `AsSocket` do not allow `T: ?Sized`. For the added `UniqueRc` impls I allowed `T: ?Sized` for all four traits, but I did not change the existing (stable) impls. Unstable traits: * `DispatchFromDyn`, allows using `UniqueRc<Self>` as a method receiver under `feature(arbitrary_self_types)`. * Existing `PinCoerceUnsized for UniqueRc` is generalized to allow non-`Global` allocators, like `Rc`. * `DerefPure`, allows using `UniqueRc` in deref-patterns under `feature(deref_patterns)`, like `Rc`. For documentation, `Rc` only has documentation on the comparison traits' methods, so I copied/adapted the documentation for those, and left the rest without impl-specific docs. ~~Edit: Marked as draft while I figure out `UnwindSafe`.~~ Edit: Ignoring `UnwindSafe` for this PR
Diffstat (limited to 'library/std')
| -rw-r--r-- | library/std/src/lib.rs | 1 | ||||
| -rw-r--r-- | library/std/src/os/fd/owned.rs | 8 | ||||
| -rw-r--r-- | library/std/src/os/fd/raw.rs | 8 | ||||
| -rw-r--r-- | library/std/src/os/windows/io/handle.rs | 8 | ||||
| -rw-r--r-- | library/std/src/os/windows/io/socket.rs | 8 |
5 files changed, 33 insertions, 0 deletions
diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 1cbf51463ea..2b97f73f79a 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -373,6 +373,7 @@ #![feature(thin_box)] #![feature(try_reserve_kind)] #![feature(try_with_capacity)] +#![feature(unique_rc_arc)] #![feature(vec_into_raw_parts)] // tidy-alphabetical-end // diff --git a/library/std/src/os/fd/owned.rs b/library/std/src/os/fd/owned.rs index 388b8a88a1a..abb13b75f50 100644 --- a/library/std/src/os/fd/owned.rs +++ b/library/std/src/os/fd/owned.rs @@ -428,6 +428,14 @@ impl<T: AsFd + ?Sized> AsFd for crate::rc::Rc<T> { } } +#[unstable(feature = "unique_rc_arc", issue = "112566")] +impl<T: AsFd + ?Sized> AsFd for crate::rc::UniqueRc<T> { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + (**self).as_fd() + } +} + #[stable(feature = "asfd_ptrs", since = "1.64.0")] impl<T: AsFd + ?Sized> AsFd for Box<T> { #[inline] diff --git a/library/std/src/os/fd/raw.rs b/library/std/src/os/fd/raw.rs index 0d99d5492a2..22f5528248a 100644 --- a/library/std/src/os/fd/raw.rs +++ b/library/std/src/os/fd/raw.rs @@ -266,6 +266,14 @@ impl<T: AsRawFd> AsRawFd for crate::rc::Rc<T> { } } +#[unstable(feature = "unique_rc_arc", issue = "112566")] +impl<T: AsRawFd + ?Sized> AsRawFd for crate::rc::UniqueRc<T> { + #[inline] + fn as_raw_fd(&self) -> RawFd { + (**self).as_raw_fd() + } +} + #[stable(feature = "asrawfd_ptrs", since = "1.63.0")] impl<T: AsRawFd> AsRawFd for Box<T> { #[inline] diff --git a/library/std/src/os/windows/io/handle.rs b/library/std/src/os/windows/io/handle.rs index a4fa94e2b96..76f5f549dd2 100644 --- a/library/std/src/os/windows/io/handle.rs +++ b/library/std/src/os/windows/io/handle.rs @@ -485,6 +485,14 @@ impl<T: AsHandle + ?Sized> AsHandle for crate::rc::Rc<T> { } } +#[unstable(feature = "unique_rc_arc", issue = "112566")] +impl<T: AsHandle + ?Sized> AsHandle for crate::rc::UniqueRc<T> { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + (**self).as_handle() + } +} + #[stable(feature = "as_windows_ptrs", since = "1.71.0")] impl<T: AsHandle + ?Sized> AsHandle for Box<T> { #[inline] diff --git a/library/std/src/os/windows/io/socket.rs b/library/std/src/os/windows/io/socket.rs index 272641ea6c7..c6d7bad9440 100644 --- a/library/std/src/os/windows/io/socket.rs +++ b/library/std/src/os/windows/io/socket.rs @@ -279,6 +279,14 @@ impl<T: AsSocket> AsSocket for crate::rc::Rc<T> { } } +#[unstable(feature = "unique_rc_arc", issue = "112566")] +impl<T: AsSocket + ?Sized> AsSocket for crate::rc::UniqueRc<T> { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + (**self).as_socket() + } +} + #[stable(feature = "as_windows_ptrs", since = "1.71.0")] impl<T: AsSocket> AsSocket for Box<T> { #[inline] |
