Auto merge of #108476 - saethlin:remove-library-rustc-box, r=thomcc
Remove or document uses of #[rustc_box] in library r? `@thomcc` Only one of these uses is tested for in the rustc-perf benchmark suite. The impact there on compile time is somewhat dramatic, but I am inclined to make this change as a simplification to the library and wait for people to complain if it explodes their compilation time. I think in the absence of data or reports from users about what code paths really matter, if we are optimizing for compilation time, it's hard to argue against using `#[rustc_box]` everywhere we currently call `Box::new`.
This commit is contained in:
commit
64165aac68
@ -283,9 +283,7 @@ impl<T> Box<T> {
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn pin(x: T) -> Pin<Box<T>> {
|
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,
|
/// 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> {
|
|||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T: Default> Default for Box<T> {
|
impl<T: Default> Default for Box<T> {
|
||||||
/// Creates a `Box<T>`, with the `Default` value for T.
|
/// Creates a `Box<T>`, with the `Default` value for T.
|
||||||
|
#[inline]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
#[rustc_box]
|
|
||||||
Box::new(T::default())
|
Box::new(T::default())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1252,6 +1250,7 @@ impl<T: Default> Default for Box<T> {
|
|||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||||
impl<T> const Default for Box<[T]> {
|
impl<T> const Default for Box<[T]> {
|
||||||
|
#[inline]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let ptr: Unique<[T]> = Unique::<[T; 0]>::dangling();
|
let ptr: Unique<[T]> = Unique::<[T; 0]>::dangling();
|
||||||
Box(ptr, Global)
|
Box(ptr, Global)
|
||||||
@ -1262,6 +1261,7 @@ impl<T> const Default for Box<[T]> {
|
|||||||
#[stable(feature = "default_box_extra", since = "1.17.0")]
|
#[stable(feature = "default_box_extra", since = "1.17.0")]
|
||||||
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||||
impl const Default for Box<str> {
|
impl const Default for Box<str> {
|
||||||
|
#[inline]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
// SAFETY: This is the same as `Unique::cast<U>` but with an unsized `U = str`.
|
// SAFETY: This is the same as `Unique::cast<U>` but with an unsized `U = str`.
|
||||||
let ptr: Unique<str> = unsafe {
|
let ptr: Unique<str> = unsafe {
|
||||||
@ -1616,7 +1616,6 @@ impl<T, const N: usize> From<[T; N]> for Box<[T]> {
|
|||||||
/// println!("{boxed:?}");
|
/// println!("{boxed:?}");
|
||||||
/// ```
|
/// ```
|
||||||
fn from(array: [T; N]) -> Box<[T]> {
|
fn from(array: [T; N]) -> Box<[T]> {
|
||||||
#[rustc_box]
|
|
||||||
Box::new(array)
|
Box::new(array)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,8 @@ macro_rules! vec {
|
|||||||
);
|
);
|
||||||
($($x:expr),+ $(,)?) => (
|
($($x:expr),+ $(,)?) => (
|
||||||
$crate::__rust_force_expr!(<[_]>::into_vec(
|
$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]
|
#[rustc_box]
|
||||||
$crate::boxed::Box::new([$($x),+])
|
$crate::boxed::Box::new([$($x),+])
|
||||||
))
|
))
|
||||||
|
@ -3131,10 +3131,7 @@ impl<T, const N: usize> From<[T; N]> for Vec<T> {
|
|||||||
/// ```
|
/// ```
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
fn from(s: [T; N]) -> Vec<T> {
|
fn from(s: [T; N]) -> Vec<T> {
|
||||||
<[T]>::into_vec(
|
<[T]>::into_vec(Box::new(s))
|
||||||
#[rustc_box]
|
|
||||||
Box::new(s),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user