Use #[rustc_box] in alloc instead of box syntax
This commit is contained in:
parent
cfc21deebd
commit
535e28b6c6
@ -192,7 +192,25 @@ impl<T> Box<T> {
|
|||||||
/// ```
|
/// ```
|
||||||
/// let five = Box::new(5);
|
/// let five = Box::new(5);
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg(not(no_global_oom_handling))]
|
#[cfg(all(not(no_global_oom_handling), not(bootstrap)))]
|
||||||
|
#[inline(always)]
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[must_use]
|
||||||
|
pub fn new(x: T) -> Self {
|
||||||
|
#[rustc_box]
|
||||||
|
Box::new(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Allocates memory on the heap and then places `x` into it.
|
||||||
|
///
|
||||||
|
/// This doesn't actually allocate if `T` is zero-sized.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// let five = Box::new(5);
|
||||||
|
/// ```
|
||||||
|
#[cfg(all(not(no_global_oom_handling), bootstrap))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
@ -259,7 +277,9 @@ pub fn new_zeroed() -> Box<mem::MaybeUninit<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>> {
|
||||||
(box x).into()
|
(#[cfg_attr(not(bootstrap), rustc_box)]
|
||||||
|
Box::new(x))
|
||||||
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Allocates memory on the heap then places `x` into it,
|
/// Allocates memory on the heap then places `x` into it,
|
||||||
@ -1186,7 +1206,8 @@ fn drop(&mut self) {
|
|||||||
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.
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
box T::default()
|
#[cfg_attr(not(bootstrap), rustc_box)]
|
||||||
|
Box::new(T::default())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1550,7 +1571,8 @@ fn from(s: Box<str, A>) -> Self {
|
|||||||
/// println!("{boxed:?}");
|
/// println!("{boxed:?}");
|
||||||
/// ```
|
/// ```
|
||||||
fn from(array: [T; N]) -> Box<[T]> {
|
fn from(array: [T; N]) -> Box<[T]> {
|
||||||
box array
|
#[cfg_attr(not(bootstrap), rustc_box)]
|
||||||
|
Box::new(array)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@
|
|||||||
#![feature(allocator_internals)]
|
#![feature(allocator_internals)]
|
||||||
#![feature(allow_internal_unstable)]
|
#![feature(allow_internal_unstable)]
|
||||||
#![feature(associated_type_bounds)]
|
#![feature(associated_type_bounds)]
|
||||||
#![feature(box_syntax)]
|
#![cfg_attr(bootstrap, feature(box_syntax))]
|
||||||
#![feature(cfg_sanitize)]
|
#![feature(cfg_sanitize)]
|
||||||
#![feature(const_deref)]
|
#![feature(const_deref)]
|
||||||
#![feature(const_mut_refs)]
|
#![feature(const_mut_refs)]
|
||||||
@ -170,6 +170,7 @@
|
|||||||
#![feature(rustc_attrs)]
|
#![feature(rustc_attrs)]
|
||||||
#![feature(slice_internals)]
|
#![feature(slice_internals)]
|
||||||
#![feature(staged_api)]
|
#![feature(staged_api)]
|
||||||
|
#![feature(stmt_expr_attributes)]
|
||||||
#![cfg_attr(test, feature(test))]
|
#![cfg_attr(test, feature(test))]
|
||||||
#![feature(unboxed_closures)]
|
#![feature(unboxed_closures)]
|
||||||
#![feature(unsized_fn_params)]
|
#![feature(unsized_fn_params)]
|
||||||
|
@ -34,7 +34,28 @@
|
|||||||
/// be mindful of side effects.
|
/// be mindful of side effects.
|
||||||
///
|
///
|
||||||
/// [`Vec`]: crate::vec::Vec
|
/// [`Vec`]: crate::vec::Vec
|
||||||
#[cfg(all(not(no_global_oom_handling), not(test)))]
|
#[cfg(all(not(no_global_oom_handling), not(test), not(bootstrap)))]
|
||||||
|
#[macro_export]
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[rustc_diagnostic_item = "vec_macro"]
|
||||||
|
#[allow_internal_unstable(rustc_attrs, liballoc_internals)]
|
||||||
|
macro_rules! vec {
|
||||||
|
() => (
|
||||||
|
$crate::__rust_force_expr!($crate::vec::Vec::new())
|
||||||
|
);
|
||||||
|
($elem:expr; $n:expr) => (
|
||||||
|
$crate::__rust_force_expr!($crate::vec::from_elem($elem, $n))
|
||||||
|
);
|
||||||
|
($($x:expr),+ $(,)?) => (
|
||||||
|
$crate::__rust_force_expr!(<[_]>::into_vec(
|
||||||
|
#[rustc_box]
|
||||||
|
$crate::boxed::Box::new([$($x),+])
|
||||||
|
))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a `Vec` containing the arguments (bootstrap version).
|
||||||
|
#[cfg(all(not(no_global_oom_handling), not(test), bootstrap))]
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[rustc_diagnostic_item = "vec_macro"]
|
#[rustc_diagnostic_item = "vec_macro"]
|
||||||
@ -65,7 +86,7 @@ macro_rules! vec {
|
|||||||
$crate::vec::from_elem($elem, $n)
|
$crate::vec::from_elem($elem, $n)
|
||||||
);
|
);
|
||||||
($($x:expr),*) => (
|
($($x:expr),*) => (
|
||||||
$crate::slice::into_vec(box [$($x),*])
|
$crate::slice::into_vec($crate::boxed::Box::new([$($x),*]))
|
||||||
);
|
);
|
||||||
($($x:expr,)*) => (vec![$($x),*])
|
($($x:expr,)*) => (vec![$($x),*])
|
||||||
}
|
}
|
||||||
|
@ -2983,12 +2983,15 @@ fn from(s: &mut [T]) -> 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(box s)
|
<[T]>::into_vec(
|
||||||
|
#[cfg_attr(not(bootstrap), rustc_box)]
|
||||||
|
Box::new(s),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn from(s: [T; N]) -> Vec<T> {
|
fn from(s: [T; N]) -> Vec<T> {
|
||||||
crate::slice::into_vec(box s)
|
crate::slice::into_vec(Box::new(s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user