Skip to content

Commit 5448123

Browse files
committed
Remove or justify use of #[rustc_box]
1 parent 34e6673 commit 5448123

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

library/alloc/src/boxed.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,7 @@ impl<T> Box<T> {
283283
#[must_use]
284284
#[inline(always)]
285285
pub fn pin(x: T) -> Pin<Box<T>> {
286-
(#[rustc_box]
287-
Box::new(x))
288-
.into()
286+
Box::new(x).into()
289287
}
290288

291289
/// Allocates memory on the heap then places `x` into it,
@@ -1242,8 +1240,8 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Box<T, A> {
12421240
#[stable(feature = "rust1", since = "1.0.0")]
12431241
impl<T: Default> Default for Box<T> {
12441242
/// Creates a `Box<T>`, with the `Default` value for T.
1243+
#[inline]
12451244
fn default() -> Self {
1246-
#[rustc_box]
12471245
Box::new(T::default())
12481246
}
12491247
}
@@ -1252,6 +1250,7 @@ impl<T: Default> Default for Box<T> {
12521250
#[stable(feature = "rust1", since = "1.0.0")]
12531251
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
12541252
impl<T> const Default for Box<[T]> {
1253+
#[inline]
12551254
fn default() -> Self {
12561255
let ptr: Unique<[T]> = Unique::<[T; 0]>::dangling();
12571256
Box(ptr, Global)
@@ -1262,6 +1261,7 @@ impl<T> const Default for Box<[T]> {
12621261
#[stable(feature = "default_box_extra", since = "1.17.0")]
12631262
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
12641263
impl const Default for Box<str> {
1264+
#[inline]
12651265
fn default() -> Self {
12661266
// SAFETY: This is the same as `Unique::cast<U>` but with an unsized `U = str`.
12671267
let ptr: Unique<str> = unsafe {
@@ -1616,7 +1616,6 @@ impl<T, const N: usize> From<[T; N]> for Box<[T]> {
16161616
/// println!("{boxed:?}");
16171617
/// ```
16181618
fn from(array: [T; N]) -> Box<[T]> {
1619-
#[rustc_box]
16201619
Box::new(array)
16211620
}
16221621
}

library/alloc/src/macros.rs

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ macro_rules! vec {
4848
);
4949
($($x:expr),+ $(,)?) => (
5050
$crate::__rust_force_expr!(<[_]>::into_vec(
51+
// This rustc_box is not required, but it produces a dramatic improvement in compile
52+
// time when constructing arrays with many elements.
5153
#[rustc_box]
5254
$crate::boxed::Box::new([$($x),+])
5355
))

library/alloc/src/vec/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -3131,10 +3131,7 @@ impl<T, const N: usize> From<[T; N]> for Vec<T> {
31313131
/// ```
31323132
#[cfg(not(test))]
31333133
fn from(s: [T; N]) -> Vec<T> {
3134-
<[T]>::into_vec(
3135-
#[rustc_box]
3136-
Box::new(s),
3137-
)
3134+
<[T]>::into_vec(Box::new(s))
31383135
}
31393136

31403137
#[cfg(test)]

0 commit comments

Comments
 (0)