Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update fork to upstream's 2025-01-16 status #237

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
57 changes: 22 additions & 35 deletions library/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion library/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ codegen-units = 10000
[profile.release.package]
addr2line.debug = 0
addr2line.opt-level = "s"
adler.debug = 0
adler2.debug = 0
gimli.debug = 0
gimli.opt-level = "s"
miniz_oxide.debug = 0
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2021"

[dependencies]
core = { path = "../core" }
compiler_builtins = { version = "=0.1.138", features = ['rustc-dep-of-std'] }
compiler_builtins = { version = "=0.1.143", features = ['rustc-dep-of-std'] }
safety = { path = "../contracts/safety" }

[dev-dependencies]
Expand Down
3 changes: 1 addition & 2 deletions library/alloc/benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
#![feature(iter_next_chunk)]
#![feature(repr_simd)]
#![feature(slice_partition_dedup)]
#![cfg_attr(bootstrap, feature(strict_provenance))]
#![cfg_attr(not(bootstrap), feature(strict_provenance_lints))]
#![feature(strict_provenance_lints)]
#![feature(test)]
#![deny(fuzzy_provenance_casts)]

Expand Down
5 changes: 1 addition & 4 deletions library/alloc/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ use core::hint;
#[cfg(not(test))]
use core::ptr::{self, NonNull};

#[cfg(test)]
mod tests;

extern "Rust" {
// These are the magic symbols to call the global allocator. rustc generates
// them to call `__rg_alloc` etc. if there is a `#[global_allocator]` attribute
Expand Down Expand Up @@ -342,7 +339,7 @@ unsafe impl Allocator for Global {
}
}

/// The allocator for unique pointers.
/// The allocator for `Box`.
#[cfg(all(not(no_global_oom_handling), not(test)))]
#[lang = "exchange_malloc"]
#[inline]
Expand Down
64 changes: 52 additions & 12 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ use core::error::{self, Error};
use core::fmt;
use core::future::Future;
use core::hash::{Hash, Hasher};
#[cfg(not(bootstrap))]
use core::marker::PointerLike;
use core::marker::{Tuple, Unsize};
use core::marker::{PointerLike, Tuple, Unsize};
use core::mem::{self, SizedTypeProperties};
use core::ops::{
AsyncFn, AsyncFnMut, AsyncFnOnce, CoerceUnsized, Coroutine, CoroutineState, Deref, DerefMut,
Expand Down Expand Up @@ -227,14 +225,35 @@ pub use thin::ThinBox;
#[fundamental]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_insignificant_dtor]
#[cfg_attr(not(bootstrap), doc(search_unbox))]
#[doc(search_unbox)]
// The declaration of the `Box` struct must be kept in sync with the
// compiler or ICEs will happen.
pub struct Box<
T: ?Sized,
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
>(Unique<T>, A);

/// Constructs a `Box<T>` by calling the `exchange_malloc` lang item and moving the argument into
/// the newly allocated memory. This is an intrinsic to avoid unnecessary copies.
///
/// This is the surface syntax for `box <expr>` expressions.
#[cfg(not(bootstrap))]
#[rustc_intrinsic]
#[rustc_intrinsic_must_be_overridden]
#[unstable(feature = "liballoc_internals", issue = "none")]
pub fn box_new<T>(_x: T) -> Box<T> {
unreachable!()
}

/// Transition function for the next bootstrap bump.
#[cfg(bootstrap)]
#[unstable(feature = "liballoc_internals", issue = "none")]
#[inline(always)]
pub fn box_new<T>(x: T) -> Box<T> {
#[rustc_box]
Box::new(x)
}

impl<T> Box<T> {
/// Allocates memory on the heap and then places `x` into it.
///
Expand All @@ -252,8 +271,7 @@ impl<T> Box<T> {
#[rustc_diagnostic_item = "box_new"]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub fn new(x: T) -> Self {
#[rustc_box]
Box::new(x)
return box_new(x);
}

/// Constructs a new box with uninitialized contents.
Expand Down Expand Up @@ -763,6 +781,26 @@ impl<T> Box<[T]> {
};
unsafe { Ok(RawVec::from_raw_parts_in(ptr.as_ptr(), len, Global).into_box(len)) }
}

/// Converts the boxed slice into a boxed array.
///
/// This operation does not reallocate; the underlying array of the slice is simply reinterpreted as an array type.
///
/// If `N` is not exactly equal to the length of `self`, then this method returns `None`.
#[unstable(feature = "slice_as_array", issue = "133508")]
#[inline]
#[must_use]
pub fn into_array<const N: usize>(self) -> Option<Box<[T; N]>> {
if self.len() == N {
let ptr = Self::into_raw(self) as *mut [T; N];

// SAFETY: The underlying array of a slice has the exact same layout as an actual array `[T; N]` if `N` is equal to the slice's length.
let me = unsafe { Box::from_raw(ptr) };
Some(me)
} else {
None
}
}
}

impl<T, A: Allocator> Box<[T], A> {
Expand Down Expand Up @@ -1027,6 +1065,8 @@ impl<T: ?Sized> Box<T> {
/// memory problems. For example, a double-free may occur if the
/// function is called twice on the same raw pointer.
///
/// The raw pointer must point to a block of memory allocated by the global allocator.
///
/// The safety conditions are described in the [memory layout] section.
///
/// # Examples
Expand Down Expand Up @@ -1130,6 +1170,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
/// memory problems. For example, a double-free may occur if the
/// function is called twice on the same raw pointer.
///
/// The raw pointer must point to a block of memory allocated by `alloc`
///
/// # Examples
///
Expand Down Expand Up @@ -1502,7 +1543,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
/// [`as_ptr`]: Self::as_ptr
#[unstable(feature = "box_as_ptr", issue = "129090")]
#[rustc_never_returns_null_ptr]
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
#[rustc_as_ptr]
#[inline]
pub fn as_mut_ptr(b: &mut Self) -> *mut T {
// This is a primitive deref, not going through `DerefMut`, and therefore not materializing
Expand Down Expand Up @@ -1551,7 +1592,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
/// [`as_ptr`]: Self::as_ptr
#[unstable(feature = "box_as_ptr", issue = "129090")]
#[rustc_never_returns_null_ptr]
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
#[rustc_as_ptr]
#[inline]
pub fn as_ptr(b: &Self) -> *const T {
// This is a primitive deref, not going through `DerefMut`, and therefore not materializing
Expand Down Expand Up @@ -1987,7 +2028,7 @@ impl<Args: Tuple, F: Fn<Args> + ?Sized, A: Allocator> Fn<Args> for Box<F, A> {
}
}

#[unstable(feature = "async_fn_traits", issue = "none")]
#[stable(feature = "async_closure", since = "1.85.0")]
impl<Args: Tuple, F: AsyncFnOnce<Args> + ?Sized, A: Allocator> AsyncFnOnce<Args> for Box<F, A> {
type Output = F::Output;
type CallOnceFuture = F::CallOnceFuture;
Expand All @@ -1997,7 +2038,7 @@ impl<Args: Tuple, F: AsyncFnOnce<Args> + ?Sized, A: Allocator> AsyncFnOnce<Args>
}
}

#[unstable(feature = "async_fn_traits", issue = "none")]
#[stable(feature = "async_closure", since = "1.85.0")]
impl<Args: Tuple, F: AsyncFnMut<Args> + ?Sized, A: Allocator> AsyncFnMut<Args> for Box<F, A> {
type CallRefFuture<'a>
= F::CallRefFuture<'a>
Expand All @@ -2009,7 +2050,7 @@ impl<Args: Tuple, F: AsyncFnMut<Args> + ?Sized, A: Allocator> AsyncFnMut<Args> f
}
}

#[unstable(feature = "async_fn_traits", issue = "none")]
#[stable(feature = "async_closure", since = "1.85.0")]
impl<Args: Tuple, F: AsyncFn<Args> + ?Sized, A: Allocator> AsyncFn<Args> for Box<F, A> {
extern "rust-call" fn async_call(&self, args: Args) -> Self::CallRefFuture<'_> {
F::async_call(self, args)
Expand Down Expand Up @@ -2134,6 +2175,5 @@ impl<E: Error> Error for Box<E> {
}
}

#[cfg(not(bootstrap))]
#[unstable(feature = "pointer_like_trait", issue = "none")]
impl<T> PointerLike for Box<T> {}
4 changes: 2 additions & 2 deletions library/alloc/src/boxed/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl<T: Clone> From<&[T]> for Box<[T]> {
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "box_from_mut_slice", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "box_from_mut_slice", since = "1.84.0")]
impl<T: Clone> From<&mut [T]> for Box<[T]> {
/// Converts a `&mut [T]` into a `Box<[T]>`
///
Expand Down Expand Up @@ -171,7 +171,7 @@ impl From<&str> for Box<str> {
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "box_from_mut_slice", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "box_from_mut_slice", since = "1.84.0")]
impl From<&mut str> for Box<str> {
/// Converts a `&mut str` into a `Box<str>`
///
Expand Down
Loading
Loading