Remove or justify use of #[rustc_box]

This commit is contained in:
Ben Kimock 2023-02-25 20:05:27 -05:00
parent 34e6673a04
commit 5448123a11
3 changed files with 7 additions and 9 deletions

View File

@ -283,9 +283,7 @@ pub fn new_zeroed() -> Box<mem::MaybeUninit<T>> {
#[must_use]
#[inline(always)]
pub fn pin(x: T) -> Pin<Box<T>> {
(#[rustc_box]
Box::new(x))
.into()
Box::new(x).into()
}
/// Allocates memory on the heap then places `x` into it,
@ -1242,8 +1240,8 @@ fn drop(&mut self) {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Default> Default for Box<T> {
/// Creates a `Box<T>`, with the `Default` value for T.
#[inline]
fn default() -> Self {
#[rustc_box]
Box::new(T::default())
}
}
@ -1252,6 +1250,7 @@ fn default() -> Self {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
impl<T> const Default for Box<[T]> {
#[inline]
fn default() -> Self {
let ptr: Unique<[T]> = Unique::<[T; 0]>::dangling();
Box(ptr, Global)
@ -1262,6 +1261,7 @@ fn default() -> Self {
#[stable(feature = "default_box_extra", since = "1.17.0")]
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
impl const Default for Box<str> {
#[inline]
fn default() -> Self {
// SAFETY: This is the same as `Unique::cast<U>` but with an unsized `U = str`.
let ptr: Unique<str> = unsafe {
@ -1616,7 +1616,6 @@ fn from(s: Box<str, A>) -> Self {
/// println!("{boxed:?}");
/// ```
fn from(array: [T; N]) -> Box<[T]> {
#[rustc_box]
Box::new(array)
}
}

View File

@ -48,6 +48,8 @@ macro_rules! vec {
);
($($x:expr),+ $(,)?) => (
$crate::__rust_force_expr!(<[_]>::into_vec(
// This rustc_box is not required, but it produces a dramatic improvement in compile
// time when constructing arrays with many elements.
#[rustc_box]
$crate::boxed::Box::new([$($x),+])
))

View File

@ -3131,10 +3131,7 @@ fn from(s: &mut [T]) -> Vec<T> {
/// ```
#[cfg(not(test))]
fn from(s: [T; N]) -> Vec<T> {
<[T]>::into_vec(
#[rustc_box]
Box::new(s),
)
<[T]>::into_vec(Box::new(s))
}
#[cfg(test)]