From 60cdf88114233c4385585f4ce497e9332619f05f Mon Sep 17 00:00:00 2001 From: Jeremy Smart Date: Mon, 6 Oct 2025 15:54:15 -0400 Subject: [PATCH] add {Box, (Unique){Rc, Arc}}::(try_)map --- library/alloc/src/boxed.rs | 80 ++++++ library/alloc/src/lib.rs | 2 + library/alloc/src/rc.rs | 253 +++++++++++++++++ library/alloc/src/sync.rs | 257 ++++++++++++++++++ .../ty-variance-issue-124423.stderr | 3 +- .../ty-variance-issue-127971.stderr | 3 +- tests/ui/privacy/suggest-box-new.stderr | 10 +- .../suggestions/multi-suggestion.ascii.stderr | 4 +- .../multi-suggestion.unicode.stderr | 4 +- 9 files changed, 603 insertions(+), 13 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 49ff768bed1b2..bee8c6c1d4d56 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -192,11 +192,15 @@ use core::fmt; use core::future::Future; use core::hash::{Hash, Hasher}; use core::marker::{Tuple, Unsize}; +#[cfg(not(no_global_oom_handling))] +use core::mem::MaybeUninit; use core::mem::{self, SizedTypeProperties}; use core::ops::{ AsyncFn, AsyncFnMut, AsyncFnOnce, CoerceUnsized, Coroutine, CoroutineState, Deref, DerefMut, DerefPure, DispatchFromDyn, LegacyReceiver, }; +#[cfg(not(no_global_oom_handling))] +use core::ops::{Residual, Try}; use core::pin::{Pin, PinCoerceUnsized}; use core::ptr::{self, NonNull, Unique}; use core::task::{Context, Poll}; @@ -385,6 +389,82 @@ impl Box { pub fn try_new_zeroed() -> Result>, AllocError> { Box::try_new_zeroed_in(Global) } + + /// Maps the value in a box, reusing the allocation if possible. + /// + /// `f` is called on the value in the box, and the result is returned, also boxed. + /// + /// Note: this is an associated function, which means that you have + /// to call it as `Box::map(b, f)` instead of `b.map(f)`. This + /// is so that there is no conflict with a method on the inner type. + /// + /// # Examples + /// + /// ``` + /// #![feature(smart_pointer_try_map)] + /// + /// let b = Box::new(7); + /// let new = Box::map(b, |i| i + 7); + /// assert_eq!(*new, 14); + /// ``` + #[cfg(not(no_global_oom_handling))] + #[unstable(feature = "smart_pointer_try_map", issue = "144419")] + pub fn map(this: Self, f: impl FnOnce(T) -> U) -> Box { + if size_of::() == size_of::() && align_of::() == align_of::() { + let (value, allocation) = Box::take(this); + Box::write( + unsafe { mem::transmute::>, Box>>(allocation) }, + f(value), + ) + } else { + Box::new(f(*this)) + } + } + + /// Attempts to map the value in a box, reusing the allocation if possible. + /// + /// `f` is called on the value in the box, and if the operation succeeds, the result is + /// returned, also boxed. + /// + /// Note: this is an associated function, which means that you have + /// to call it as `Box::try_map(b, f)` instead of `b.try_map(f)`. This + /// is so that there is no conflict with a method on the inner type. + /// + /// # Examples + /// + /// ``` + /// #![feature(smart_pointer_try_map)] + /// + /// let b = Box::new(7); + /// let new = Box::try_map(b, u32::try_from).unwrap(); + /// assert_eq!(*new, 7); + /// ``` + #[cfg(not(no_global_oom_handling))] + #[unstable(feature = "smart_pointer_try_map", issue = "144419")] + pub fn try_map( + this: Self, + f: impl FnOnce(T) -> R, + ) -> >>::TryType + where + R: Try, + R::Residual: Residual>, + { + if size_of::() == size_of::() && align_of::() == align_of::() { + let (value, allocation) = Box::take(this); + try { + Box::write( + unsafe { + mem::transmute::>, Box>>( + allocation, + ) + }, + f(value)?, + ) + } + } else { + try { Box::new(f(*this)?) } + } + } } impl Box { diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 87ad5b0ce30e6..ec3a421d69a6c 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -146,7 +146,9 @@ #![feature(trusted_fused)] #![feature(trusted_len)] #![feature(trusted_random_access)] +#![feature(try_blocks)] #![feature(try_trait_v2)] +#![feature(try_trait_v2_residual)] #![feature(try_with_capacity)] #![feature(tuple_trait)] #![feature(ub_checks)] diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 2b62b92d43886..a9cc2b262dd62 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -255,6 +255,8 @@ use core::marker::{PhantomData, Unsize}; use core::mem::{self, ManuallyDrop, align_of_val_raw}; use core::num::NonZeroUsize; use core::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn, LegacyReceiver}; +#[cfg(not(no_global_oom_handling))] +use core::ops::{Residual, Try}; use core::panic::{RefUnwindSafe, UnwindSafe}; #[cfg(not(no_global_oom_handling))] use core::pin::Pin; @@ -639,6 +641,93 @@ impl Rc { pub fn pin(value: T) -> Pin> { unsafe { Pin::new_unchecked(Rc::new(value)) } } + + /// Maps the value in an `Rc`, reusing the allocation if possible. + /// + /// `f` is called on a reference to the value in the `Rc`, and the result is returned, also in + /// an `Rc`. + /// + /// Note: this is an associated function, which means that you have + /// to call it as `Rc::map(r, f)` instead of `r.map(f)`. This + /// is so that there is no conflict with a method on the inner type. + /// + /// # Examples + /// + /// ``` + /// #![feature(smart_pointer_try_map)] + /// + /// use std::rc::Rc; + /// + /// let r = Rc::new(7); + /// let new = Rc::map(r, |i| i + 7); + /// assert_eq!(*new, 14); + /// ``` + #[cfg(not(no_global_oom_handling))] + #[unstable(feature = "smart_pointer_try_map", issue = "144419")] + pub fn map(this: Self, f: impl FnOnce(&T) -> U) -> Rc { + if size_of::() == size_of::() + && align_of::() == align_of::() + && Rc::is_unique(&this) + { + unsafe { + let ptr = Rc::into_raw(this); + let value = ptr.read(); + let mut allocation = Rc::from_raw(ptr.cast::>()); + + Rc::get_mut_unchecked(&mut allocation).write(f(&value)); + allocation.assume_init() + } + } else { + Rc::new(f(&*this)) + } + } + + /// Attempts to map the value in an `Rc`, reusing the allocation if possible. + /// + /// `f` is called on a reference to the value in the `Rc`, and if the operation succeeds, the + /// result is returned, also in an `Rc`. + /// + /// Note: this is an associated function, which means that you have + /// to call it as `Rc::try_map(r, f)` instead of `r.try_map(f)`. This + /// is so that there is no conflict with a method on the inner type. + /// + /// # Examples + /// + /// ``` + /// #![feature(smart_pointer_try_map)] + /// + /// use std::rc::Rc; + /// + /// let b = Rc::new(7); + /// let new = Rc::try_map(b, |&i| u32::try_from(i)).unwrap(); + /// assert_eq!(*new, 7); + /// ``` + #[cfg(not(no_global_oom_handling))] + #[unstable(feature = "smart_pointer_try_map", issue = "144419")] + pub fn try_map( + this: Self, + f: impl FnOnce(&T) -> R, + ) -> >>::TryType + where + R: Try, + R::Residual: Residual>, + { + if size_of::() == size_of::() + && align_of::() == align_of::() + && Rc::is_unique(&this) + { + unsafe { + let ptr = Rc::into_raw(this); + let value = ptr.read(); + let mut allocation = Rc::from_raw(ptr.cast::>()); + + Rc::get_mut_unchecked(&mut allocation).write(f(&value)?); + try { allocation.assume_init() } + } + } else { + try { Rc::new(f(&*this)?) } + } + } } impl Rc { @@ -3991,6 +4080,128 @@ impl UniqueRc { pub fn new(value: T) -> Self { Self::new_in(value, Global) } + + /// Maps the value in a `UniqueRc`, reusing the allocation if possible. + /// + /// `f` is called on a reference to the value in the `UniqueRc`, and the result is returned, + /// also in a `UniqueRc`. + /// + /// Note: this is an associated function, which means that you have + /// to call it as `UniqueRc::map(u, f)` instead of `u.map(f)`. This + /// is so that there is no conflict with a method on the inner type. + /// + /// # Examples + /// + /// ``` + /// #![feature(smart_pointer_try_map)] + /// #![feature(unique_rc_arc)] + /// + /// use std::rc::UniqueRc; + /// + /// let r = UniqueRc::new(7); + /// let new = UniqueRc::map(r, |i| i + 7); + /// assert_eq!(*new, 14); + /// ``` + #[cfg(not(no_global_oom_handling))] + #[unstable(feature = "smart_pointer_try_map", issue = "144419")] + pub fn map(this: Self, f: impl FnOnce(T) -> U) -> UniqueRc { + if size_of::() == size_of::() + && align_of::() == align_of::() + && UniqueRc::weak_count(&this) == 0 + { + unsafe { + let ptr = UniqueRc::into_raw(this); + let value = ptr.read(); + let mut allocation = UniqueRc::from_raw(ptr.cast::>()); + + allocation.write(f(value)); + allocation.assume_init() + } + } else { + UniqueRc::new(f(UniqueRc::unwrap(this))) + } + } + + /// Attempts to map the value in a `UniqueRc`, reusing the allocation if possible. + /// + /// `f` is called on a reference to the value in the `UniqueRc`, and if the operation succeeds, + /// the result is returned, also in a `UniqueRc`. + /// + /// Note: this is an associated function, which means that you have + /// to call it as `UniqueRc::try_map(u, f)` instead of `u.try_map(f)`. This + /// is so that there is no conflict with a method on the inner type. + /// + /// # Examples + /// + /// ``` + /// #![feature(smart_pointer_try_map)] + /// #![feature(unique_rc_arc)] + /// + /// use std::rc::UniqueRc; + /// + /// let b = UniqueRc::new(7); + /// let new = UniqueRc::try_map(b, u32::try_from).unwrap(); + /// assert_eq!(*new, 7); + /// ``` + #[cfg(not(no_global_oom_handling))] + #[unstable(feature = "smart_pointer_try_map", issue = "144419")] + pub fn try_map( + this: Self, + f: impl FnOnce(T) -> R, + ) -> >>::TryType + where + R: Try, + R::Residual: Residual>, + { + if size_of::() == size_of::() + && align_of::() == align_of::() + && UniqueRc::weak_count(&this) == 0 + { + unsafe { + let ptr = UniqueRc::into_raw(this); + let value = ptr.read(); + let mut allocation = UniqueRc::from_raw(ptr.cast::>()); + + allocation.write(f(value)?); + try { allocation.assume_init() } + } + } else { + try { UniqueRc::new(f(UniqueRc::unwrap(this))?) } + } + } + + #[cfg(not(no_global_oom_handling))] + fn unwrap(this: Self) -> T { + let this = ManuallyDrop::new(this); + let val: T = unsafe { ptr::read(&**this) }; + + let _weak = Weak { ptr: this.ptr, alloc: Global }; + + val + } +} + +impl UniqueRc { + #[cfg(not(no_global_oom_handling))] + unsafe fn from_raw(ptr: *const T) -> Self { + let offset = unsafe { data_offset(ptr) }; + + // Reverse the offset to find the original RcInner. + let rc_ptr = unsafe { ptr.byte_sub(offset) as *mut RcInner }; + + Self { + ptr: unsafe { NonNull::new_unchecked(rc_ptr) }, + _marker: PhantomData, + _marker2: PhantomData, + alloc: Global, + } + } + + #[cfg(not(no_global_oom_handling))] + fn into_raw(this: Self) -> *const T { + let this = ManuallyDrop::new(this); + Self::as_ptr(&*this) + } } impl UniqueRc { @@ -4041,6 +4252,40 @@ impl UniqueRc { Rc::from_inner_in(this.ptr, alloc) } } + + #[cfg(not(no_global_oom_handling))] + fn weak_count(this: &Self) -> usize { + this.inner().weak() - 1 + } + + #[cfg(not(no_global_oom_handling))] + fn inner(&self) -> &RcInner { + // SAFETY: while this UniqueRc is alive we're guaranteed that the inner pointer is valid. + unsafe { self.ptr.as_ref() } + } + + #[cfg(not(no_global_oom_handling))] + fn as_ptr(this: &Self) -> *const T { + let ptr: *mut RcInner = NonNull::as_ptr(this.ptr); + + // SAFETY: This cannot go through Deref::deref or UniqueRc::inner because + // this is required to retain raw/mut provenance such that e.g. `get_mut` can + // write through the pointer after the Rc is recovered through `from_raw`. + unsafe { &raw mut (*ptr).value } + } + + #[inline] + #[cfg(not(no_global_oom_handling))] + fn into_inner_with_allocator(this: Self) -> (NonNull>, A) { + let this = mem::ManuallyDrop::new(this); + (this.ptr, unsafe { ptr::read(&this.alloc) }) + } + + #[inline] + #[cfg(not(no_global_oom_handling))] + unsafe fn from_inner_in(ptr: NonNull>, alloc: A) -> Self { + Self { ptr, _marker: PhantomData, _marker2: PhantomData, alloc } + } } impl UniqueRc { @@ -4059,6 +4304,14 @@ impl UniqueRc { } } +#[cfg(not(no_global_oom_handling))] +impl UniqueRc, A> { + unsafe fn assume_init(self) -> UniqueRc { + let (ptr, alloc) = UniqueRc::into_inner_with_allocator(self); + unsafe { UniqueRc::from_inner_in(ptr.cast(), alloc) } + } +} + #[unstable(feature = "unique_rc_arc", issue = "112566")] impl Deref for UniqueRc { type Target = T; diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 5927d03646928..570aef036c795 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -22,6 +22,8 @@ use core::marker::{PhantomData, Unsize}; use core::mem::{self, ManuallyDrop, align_of_val_raw}; use core::num::NonZeroUsize; use core::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn, LegacyReceiver}; +#[cfg(not(no_global_oom_handling))] +use core::ops::{Residual, Try}; use core::panic::{RefUnwindSafe, UnwindSafe}; use core::pin::{Pin, PinCoerceUnsized}; use core::ptr::{self, NonNull}; @@ -650,6 +652,97 @@ impl Arc { )?)) } } + + /// Maps the value in an `Arc`, reusing the allocation if possible. + /// + /// `f` is called on a reference to the value in the `Arc`, and the result is returned, also in + /// an `Arc`. + /// + /// Note: this is an associated function, which means that you have + /// to call it as `Arc::map(a, f)` instead of `r.map(a)`. This + /// is so that there is no conflict with a method on the inner type. + /// + /// # Examples + /// + /// ``` + /// #![feature(smart_pointer_try_map)] + /// + /// use std::sync::Arc; + /// + /// let r = Arc::new(7); + /// let new = Arc::map(r, |i| i + 7); + /// assert_eq!(*new, 14); + /// ``` + #[cfg(not(no_global_oom_handling))] + #[unstable(feature = "smart_pointer_try_map", issue = "144419")] + pub fn map(this: Self, f: impl FnOnce(&T) -> U) -> Arc { + if size_of::() == size_of::() + && align_of::() == align_of::() + && Arc::is_unique(&this) + { + unsafe { + use core::mem::MaybeUninit; + + let ptr = Arc::into_raw(this); + let value = ptr.read(); + let mut allocation = Arc::from_raw(ptr.cast::>()); + + Arc::get_mut_unchecked(&mut allocation).write(f(&value)); + allocation.assume_init() + } + } else { + Arc::new(f(&*this)) + } + } + + /// Attempts to map the value in an `Arc`, reusing the allocation if possible. + /// + /// `f` is called on a reference to the value in the `Arc`, and if the operation succeeds, the + /// result is returned, also in an `Arc`. + /// + /// Note: this is an associated function, which means that you have + /// to call it as `Arc::try_map(a, f)` instead of `a.try_map(f)`. This + /// is so that there is no conflict with a method on the inner type. + /// + /// # Examples + /// + /// ``` + /// #![feature(smart_pointer_try_map)] + /// + /// use std::sync::Arc; + /// + /// let b = Arc::new(7); + /// let new = Arc::try_map(b, |&i| u32::try_from(i)).unwrap(); + /// assert_eq!(*new, 7); + /// ``` + #[cfg(not(no_global_oom_handling))] + #[unstable(feature = "smart_pointer_try_map", issue = "144419")] + pub fn try_map( + this: Self, + f: impl FnOnce(&T) -> R, + ) -> >>::TryType + where + R: Try, + R::Residual: Residual>, + { + if size_of::() == size_of::() + && align_of::() == align_of::() + && Arc::is_unique(&this) + { + unsafe { + use core::mem::MaybeUninit; + + let ptr = Arc::into_raw(this); + let value = ptr.read(); + let mut allocation = Arc::from_raw(ptr.cast::>()); + + Arc::get_mut_unchecked(&mut allocation).write(f(&value)?); + try { allocation.assume_init() } + } + } else { + try { Arc::new(f(&*this)?) } + } + } } impl Arc { @@ -4404,6 +4497,128 @@ impl UniqueArc { pub fn new(value: T) -> Self { Self::new_in(value, Global) } + + /// Maps the value in a `UniqueArc`, reusing the allocation if possible. + /// + /// `f` is called on a reference to the value in the `UniqueArc`, and the result is returned, + /// also in a `UniqueArc`. + /// + /// Note: this is an associated function, which means that you have + /// to call it as `UniqueArc::map(u, f)` instead of `u.map(f)`. This + /// is so that there is no conflict with a method on the inner type. + /// + /// # Examples + /// + /// ``` + /// #![feature(smart_pointer_try_map)] + /// #![feature(unique_rc_arc)] + /// + /// use std::sync::UniqueArc; + /// + /// let r = UniqueArc::new(7); + /// let new = UniqueArc::map(r, |i| i + 7); + /// assert_eq!(*new, 14); + /// ``` + #[cfg(not(no_global_oom_handling))] + #[unstable(feature = "smart_pointer_try_map", issue = "144419")] + pub fn map(this: Self, f: impl FnOnce(T) -> U) -> UniqueArc { + if size_of::() == size_of::() + && align_of::() == align_of::() + && UniqueArc::weak_count(&this) == 0 + { + unsafe { + let ptr = UniqueArc::into_raw(this); + let value = ptr.read(); + let mut allocation = UniqueArc::from_raw(ptr.cast::>()); + + allocation.write(f(value)); + allocation.assume_init() + } + } else { + UniqueArc::new(f(UniqueArc::unwrap(this))) + } + } + + /// Attempts to map the value in a `UniqueArc`, reusing the allocation if possible. + /// + /// `f` is called on a reference to the value in the `UniqueArc`, and if the operation succeeds, + /// the result is returned, also in a `UniqueArc`. + /// + /// Note: this is an associated function, which means that you have + /// to call it as `UniqueArc::try_map(u, f)` instead of `u.try_map(f)`. This + /// is so that there is no conflict with a method on the inner type. + /// + /// # Examples + /// + /// ``` + /// #![feature(smart_pointer_try_map)] + /// #![feature(unique_rc_arc)] + /// + /// use std::sync::UniqueArc; + /// + /// let b = UniqueArc::new(7); + /// let new = UniqueArc::try_map(b, u32::try_from).unwrap(); + /// assert_eq!(*new, 7); + /// ``` + #[cfg(not(no_global_oom_handling))] + #[unstable(feature = "smart_pointer_try_map", issue = "144419")] + pub fn try_map( + this: Self, + f: impl FnOnce(T) -> R, + ) -> >>::TryType + where + R: Try, + R::Residual: Residual>, + { + if size_of::() == size_of::() + && align_of::() == align_of::() + && UniqueArc::weak_count(&this) == 0 + { + unsafe { + let ptr = UniqueArc::into_raw(this); + let value = ptr.read(); + let mut allocation = UniqueArc::from_raw(ptr.cast::>()); + + allocation.write(f(value)?); + try { allocation.assume_init() } + } + } else { + try { UniqueArc::new(f(UniqueArc::unwrap(this))?) } + } + } + + #[cfg(not(no_global_oom_handling))] + fn unwrap(this: Self) -> T { + let this = ManuallyDrop::new(this); + let val: T = unsafe { ptr::read(&**this) }; + + let _weak = Weak { ptr: this.ptr, alloc: Global }; + + val + } +} + +impl UniqueArc { + #[cfg(not(no_global_oom_handling))] + unsafe fn from_raw(ptr: *const T) -> Self { + let offset = unsafe { data_offset(ptr) }; + + // Reverse the offset to find the original ArcInner. + let rc_ptr = unsafe { ptr.byte_sub(offset) as *mut ArcInner }; + + Self { + ptr: unsafe { NonNull::new_unchecked(rc_ptr) }, + _marker: PhantomData, + _marker2: PhantomData, + alloc: Global, + } + } + + #[cfg(not(no_global_oom_handling))] + fn into_raw(this: Self) -> *const T { + let this = ManuallyDrop::new(this); + Self::as_ptr(&*this) + } } impl UniqueArc { @@ -4457,6 +4672,40 @@ impl UniqueArc { Arc::from_inner_in(this.ptr, alloc) } } + + #[cfg(not(no_global_oom_handling))] + fn weak_count(this: &Self) -> usize { + this.inner().weak.load(Acquire) - 1 + } + + #[cfg(not(no_global_oom_handling))] + fn inner(&self) -> &ArcInner { + // SAFETY: while this UniqueArc is alive we're guaranteed that the inner pointer is valid. + unsafe { self.ptr.as_ref() } + } + + #[cfg(not(no_global_oom_handling))] + fn as_ptr(this: &Self) -> *const T { + let ptr: *mut ArcInner = NonNull::as_ptr(this.ptr); + + // SAFETY: This cannot go through Deref::deref or UniqueArc::inner because + // this is required to retain raw/mut provenance such that e.g. `get_mut` can + // write through the pointer after the Rc is recovered through `from_raw`. + unsafe { &raw mut (*ptr).data } + } + + #[inline] + #[cfg(not(no_global_oom_handling))] + fn into_inner_with_allocator(this: Self) -> (NonNull>, A) { + let this = mem::ManuallyDrop::new(this); + (this.ptr, unsafe { ptr::read(&this.alloc) }) + } + + #[inline] + #[cfg(not(no_global_oom_handling))] + unsafe fn from_inner_in(ptr: NonNull>, alloc: A) -> Self { + Self { ptr, _marker: PhantomData, _marker2: PhantomData, alloc } + } } impl UniqueArc { @@ -4487,6 +4736,14 @@ impl UniqueArc { } } +#[cfg(not(no_global_oom_handling))] +impl UniqueArc, A> { + unsafe fn assume_init(self) -> UniqueArc { + let (ptr, alloc) = UniqueArc::into_inner_with_allocator(self); + unsafe { UniqueArc::from_inner_in(ptr.cast(), alloc) } + } +} + #[unstable(feature = "unique_rc_arc", issue = "112566")] impl Deref for UniqueArc { type Target = T; diff --git a/tests/ui/parallel-rustc/ty-variance-issue-124423.stderr b/tests/ui/parallel-rustc/ty-variance-issue-124423.stderr index 7ba89f75bd1b5..81ba66c42faa3 100644 --- a/tests/ui/parallel-rustc/ty-variance-issue-124423.stderr +++ b/tests/ui/parallel-rustc/ty-variance-issue-124423.stderr @@ -278,10 +278,9 @@ note: if you're trying to build a new `Box<_, _>` consider using one of the foll Box::::new_uninit Box::::new_zeroed Box::::try_new - and 22 others --> $SRC_DIR/alloc/src/boxed.rs:LL:COL error: aborting due to 30 previous errors Some errors have detailed explanations: E0121, E0224, E0261, E0412, E0599. -For more information about an error, try `rustc --explain E0121`. +For more information about an error, try `rustc --explain E0121`. \ No newline at end of file diff --git a/tests/ui/parallel-rustc/ty-variance-issue-127971.stderr b/tests/ui/parallel-rustc/ty-variance-issue-127971.stderr index 9929d3ee22ced..55d52d35f4a8d 100644 --- a/tests/ui/parallel-rustc/ty-variance-issue-127971.stderr +++ b/tests/ui/parallel-rustc/ty-variance-issue-127971.stderr @@ -104,10 +104,9 @@ note: if you're trying to build a new `Box<_, _>` consider using one of the foll Box::::new_uninit Box::::new_zeroed Box::::try_new - and 22 others --> $SRC_DIR/alloc/src/boxed.rs:LL:COL error: aborting due to 11 previous errors Some errors have detailed explanations: E0121, E0224, E0261, E0599. -For more information about an error, try `rustc --explain E0121`. +For more information about an error, try `rustc --explain E0121`. \ No newline at end of file diff --git a/tests/ui/privacy/suggest-box-new.stderr b/tests/ui/privacy/suggest-box-new.stderr index 37b2989dcc148..7df293e1e1d94 100644 --- a/tests/ui/privacy/suggest-box-new.stderr +++ b/tests/ui/privacy/suggest-box-new.stderr @@ -63,7 +63,7 @@ LL - x: (), LL - })), LL + wtf: Some(Box::new_in(_, _)), | - = and 12 other candidates + = and 13 other candidates help: consider using the `Default` trait | LL - wtf: Some(Box(U { @@ -118,7 +118,7 @@ LL + let _ = Box::new_zeroed(); LL - let _ = Box {}; LL + let _ = Box::new_in(_, _); | - = and 13 other candidates + = and 14 other candidates help: consider using the `Default` trait | LL - let _ = Box {}; @@ -141,12 +141,12 @@ LL - let _ = Box:: {}; LL + let _ = Box::::new_in(_, _); | LL - let _ = Box:: {}; -LL + let _ = Box::::into_inner(_); +LL + let _ = Box::::map(_, _); | LL - let _ = Box:: {}; -LL + let _ = Box::::write(_, _); +LL + let _ = Box::::into_inner(_); | - = and 4 other candidates + = and 5 other candidates help: consider using the `Default` trait | LL - let _ = Box:: {}; diff --git a/tests/ui/suggestions/multi-suggestion.ascii.stderr b/tests/ui/suggestions/multi-suggestion.ascii.stderr index 9c8867a17711e..4bd6c19e0829b 100644 --- a/tests/ui/suggestions/multi-suggestion.ascii.stderr +++ b/tests/ui/suggestions/multi-suggestion.ascii.stderr @@ -63,7 +63,7 @@ LL - x: (), LL - })), LL + wtf: Some(Box::new_in(_, _)), | - = and 12 other candidates + = and 13 other candidates help: consider using the `Default` trait | LL - wtf: Some(Box(U { @@ -118,7 +118,7 @@ LL + let _ = Box::new_zeroed(); LL - let _ = Box {}; LL + let _ = Box::new_in(_, _); | - = and 13 other candidates + = and 14 other candidates help: consider using the `Default` trait | LL - let _ = Box {}; diff --git a/tests/ui/suggestions/multi-suggestion.unicode.stderr b/tests/ui/suggestions/multi-suggestion.unicode.stderr index 4fdab51493e26..b11570f34161c 100644 --- a/tests/ui/suggestions/multi-suggestion.unicode.stderr +++ b/tests/ui/suggestions/multi-suggestion.unicode.stderr @@ -63,7 +63,7 @@ LL - x: (), LL - })), LL + wtf: Some(Box::new_in(_, _)), │ - ╰ and 12 other candidates + ╰ and 13 other candidates help: consider using the `Default` trait ╭╴ LL - wtf: Some(Box(U { @@ -118,7 +118,7 @@ LL + let _ = Box::new_zeroed(); LL - let _ = Box {}; LL + let _ = Box::new_in(_, _); │ - ╰ and 13 other candidates + ╰ and 14 other candidates help: consider using the `Default` trait ╭╴ LL - let _ = Box {};