Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions library/alloc/src/boxed/thin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,12 @@ impl<T: ?Sized + Error> Error for ThinBox<T> {
self.deref().source()
}
}

#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "thin_box", issue = "92791")]
impl<T> From<T> for ThinBox<T> {
#[inline(always)]
fn from(value: T) -> Self {
Self::new(value)
}
}
9 changes: 9 additions & 0 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3816,6 +3816,15 @@ impl<T: ?Sized, A: Allocator> AsMut<T> for UniqueRc<T, A> {
#[unstable(feature = "unique_rc_arc", issue = "112566")]
impl<T: ?Sized, A: Allocator> Unpin for UniqueRc<T, A> {}

#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "unique_rc_arc", issue = "112566")]
impl<T> From<T> for UniqueRc<T> {
#[inline(always)]
fn from(value: T) -> Self {
Self::new(value)
}
}

#[unstable(feature = "unique_rc_arc", issue = "112566")]
impl<T: ?Sized + PartialEq, A: Allocator> PartialEq for UniqueRc<T, A> {
/// Equality for two `UniqueRc`s.
Expand Down
9 changes: 9 additions & 0 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4242,6 +4242,15 @@ impl<T: ?Sized, A: Allocator> AsMut<T> for UniqueArc<T, A> {
}
}

#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "unique_rc_arc", issue = "112566")]
impl<T> From<T> for UniqueArc<T> {
#[inline(always)]
fn from(value: T) -> Self {
Self::new(value)
}
}

#[unstable(feature = "unique_rc_arc", issue = "112566")]
impl<T: ?Sized, A: Allocator> Unpin for UniqueArc<T, A> {}

Expand Down
10 changes: 10 additions & 0 deletions library/core/src/cell/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,16 @@ impl<T: fmt::Debug, F> fmt::Debug for LazyCell<T, F> {
}
}

#[stable(feature = "from_wrapper_impls", since = "CURRENT_RUSTC_VERSION")]
impl<T, F> From<T> for LazyCell<T, F> {
/// Constructs a `LazyCell` that starts already initialized
/// with the provided value.
#[inline]
fn from(value: T) -> Self {
Self { state: UnsafeCell::new(State::Init(value)) }
}
}

#[cold]
#[inline(never)]
const fn panic_poisoned() -> ! {
Expand Down
8 changes: 8 additions & 0 deletions library/core/src/mem/manually_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,11 @@ impl<T: ?Sized> DerefMut for ManuallyDrop<T> {

#[unstable(feature = "deref_pure_trait", issue = "87121")]
unsafe impl<T: ?Sized> DerefPure for ManuallyDrop<T> {}

#[stable(feature = "from_wrapper_impls", since = "CURRENT_RUSTC_VERSION")]
impl<T> From<T> for ManuallyDrop<T> {
#[inline(always)]
fn from(value: T) -> Self {
Self::new(value)
}
}
8 changes: 8 additions & 0 deletions library/core/src/panic/unwind_safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,11 @@ impl<S: AsyncIterator> AsyncIterator for AssertUnwindSafe<S> {
self.0.size_hint()
}
}

#[stable(feature = "from_wrapper_impls", since = "CURRENT_RUSTC_VERSION")]
impl<T> From<T> for AssertUnwindSafe<T> {
#[inline(always)]
fn from(value: T) -> Self {
Self(value)
}
}
14 changes: 6 additions & 8 deletions library/std/src/backtrace/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ fn generate_fake_frames() -> Vec<BacktraceFrame> {
#[test]
fn test_debug() {
let backtrace = Backtrace {
inner: Inner::Captured(LazyLock::preinit(Capture {
actual_start: 1,
frames: generate_fake_frames(),
})),
inner: Inner::Captured(
(Capture { actual_start: 1, frames: generate_fake_frames() }).into(),
),
};

#[rustfmt::skip]
Expand All @@ -66,10 +65,9 @@ fn test_debug() {
#[test]
fn test_frames() {
let backtrace = Backtrace {
inner: Inner::Captured(LazyLock::preinit(Capture {
actual_start: 1,
frames: generate_fake_frames(),
})),
inner: Inner::Captured(
(Capture { actual_start: 1, frames: generate_fake_frames() }).into(),
),
};

let frames = backtrace.frames();
Expand Down
22 changes: 13 additions & 9 deletions library/std/src/sync/lazy_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,6 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> {
LazyLock { once: Once::new(), data: UnsafeCell::new(Data { f: ManuallyDrop::new(f) }) }
}

/// Creates a new lazy value that is already initialized.
#[inline]
#[cfg(test)]
pub(crate) fn preinit(value: T) -> LazyLock<T, F> {
let once = Once::new();
once.call_once(|| {});
LazyLock { once, data: UnsafeCell::new(Data { value: ManuallyDrop::new(value) }) }
}

/// Consumes this `LazyLock` returning the stored value.
///
/// Returns `Ok(value)` if `Lazy` is initialized and `Err(f)` otherwise.
Expand Down Expand Up @@ -401,6 +392,19 @@ impl<T: fmt::Debug, F> fmt::Debug for LazyLock<T, F> {
}
}

#[stable(feature = "from_wrapper_impls", since = "CURRENT_RUSTC_VERSION")]
impl<T, F> From<T> for LazyLock<T, F> {
/// Constructs a `LazyLock` that starts already initialized
/// with the provided value.
#[inline]
fn from(value: T) -> Self {
LazyLock {
once: Once::new_complete(),
data: UnsafeCell::new(Data { value: ManuallyDrop::new(value) }),
}
}
}

#[cold]
#[inline(never)]
fn panic_poisoned() -> ! {
Expand Down
7 changes: 7 additions & 0 deletions library/std/src/sync/poison/once.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ impl Once {
Once { inner: sys::Once::new() }
}

/// Creates a new `Once` value that starts already completed.
#[inline]
#[must_use]
pub(crate) const fn new_complete() -> Once {
Once { inner: sys::Once::new_complete() }
}

/// Performs an initialization routine once and only once. The given closure
/// will be executed if this is the first time `call_once` has been called,
/// and otherwise the routine will *not* be invoked.
Expand Down
5 changes: 5 additions & 0 deletions library/std/src/sys/sync/once/futex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ impl Once {
Once { state_and_queued: Futex::new(INCOMPLETE) }
}

#[inline]
pub const fn new_complete() -> Once {
Once { state_and_queued: Futex::new(COMPLETE) }
}

#[inline]
pub fn is_completed(&self) -> bool {
// Use acquire ordering to make all initialization changes visible to the
Expand Down
5 changes: 5 additions & 0 deletions library/std/src/sys/sync/once/no_threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ impl Once {
Once { state: Cell::new(State::Incomplete) }
}

#[inline]
pub const fn new_complete() -> Once {
Once { state: Cell::new(State::Complete) }
}

#[inline]
pub fn is_completed(&self) -> bool {
self.state.get() == State::Complete
Expand Down
5 changes: 5 additions & 0 deletions library/std/src/sys/sync/once/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ impl Once {
Once { state_and_queue: AtomicPtr::new(ptr::without_provenance_mut(INCOMPLETE)) }
}

#[inline]
pub const fn new_complete() -> Once {
Once { state_and_queue: AtomicPtr::new(ptr::without_provenance_mut(COMPLETE)) }
}

#[inline]
pub fn is_completed(&self) -> bool {
// An `Acquire` load is enough because that makes all the initialization
Expand Down
Loading