Skip to content

Commit e3ec0fa

Browse files
committed
Merge commit 'd68749d7bde7bfc55fc5ac2315fb551c8d9db667' into sync-2025-01-16
2 parents 2b2baa8 + d68749d commit e3ec0fa

File tree

318 files changed

+9866
-4885
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

318 files changed

+9866
-4885
lines changed

library/Cargo.lock

Lines changed: 22 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

library/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ codegen-units = 10000
3232
[profile.release.package]
3333
addr2line.debug = 0
3434
addr2line.opt-level = "s"
35-
adler.debug = 0
35+
adler2.debug = 0
3636
gimli.debug = 0
3737
gimli.opt-level = "s"
3838
miniz_oxide.debug = 0

library/alloc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ edition = "2021"
1010

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

1616
[dev-dependencies]

library/alloc/benches/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
#![feature(iter_next_chunk)]
55
#![feature(repr_simd)]
66
#![feature(slice_partition_dedup)]
7-
#![cfg_attr(bootstrap, feature(strict_provenance))]
8-
#![cfg_attr(not(bootstrap), feature(strict_provenance_lints))]
7+
#![feature(strict_provenance_lints)]
98
#![feature(test)]
109
#![deny(fuzzy_provenance_casts)]
1110

library/alloc/src/alloc.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ use core::hint;
1010
#[cfg(not(test))]
1111
use core::ptr::{self, NonNull};
1212

13-
#[cfg(test)]
14-
mod tests;
15-
1613
extern "Rust" {
1714
// These are the magic symbols to call the global allocator. rustc generates
1815
// them to call `__rg_alloc` etc. if there is a `#[global_allocator]` attribute
@@ -342,7 +339,7 @@ unsafe impl Allocator for Global {
342339
}
343340
}
344341

345-
/// The allocator for unique pointers.
342+
/// The allocator for `Box`.
346343
#[cfg(all(not(no_global_oom_handling), not(test)))]
347344
#[lang = "exchange_malloc"]
348345
#[inline]

library/alloc/src/boxed.rs

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,7 @@ use core::error::{self, Error};
191191
use core::fmt;
192192
use core::future::Future;
193193
use core::hash::{Hash, Hasher};
194-
#[cfg(not(bootstrap))]
195-
use core::marker::PointerLike;
196-
use core::marker::{Tuple, Unsize};
194+
use core::marker::{PointerLike, Tuple, Unsize};
197195
use core::mem::{self, SizedTypeProperties};
198196
use core::ops::{
199197
AsyncFn, AsyncFnMut, AsyncFnOnce, CoerceUnsized, Coroutine, CoroutineState, Deref, DerefMut,
@@ -227,14 +225,35 @@ pub use thin::ThinBox;
227225
#[fundamental]
228226
#[stable(feature = "rust1", since = "1.0.0")]
229227
#[rustc_insignificant_dtor]
230-
#[cfg_attr(not(bootstrap), doc(search_unbox))]
228+
#[doc(search_unbox)]
231229
// The declaration of the `Box` struct must be kept in sync with the
232230
// compiler or ICEs will happen.
233231
pub struct Box<
234232
T: ?Sized,
235233
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
236234
>(Unique<T>, A);
237235

236+
/// Constructs a `Box<T>` by calling the `exchange_malloc` lang item and moving the argument into
237+
/// the newly allocated memory. This is an intrinsic to avoid unnecessary copies.
238+
///
239+
/// This is the surface syntax for `box <expr>` expressions.
240+
#[cfg(not(bootstrap))]
241+
#[rustc_intrinsic]
242+
#[rustc_intrinsic_must_be_overridden]
243+
#[unstable(feature = "liballoc_internals", issue = "none")]
244+
pub fn box_new<T>(_x: T) -> Box<T> {
245+
unreachable!()
246+
}
247+
248+
/// Transition function for the next bootstrap bump.
249+
#[cfg(bootstrap)]
250+
#[unstable(feature = "liballoc_internals", issue = "none")]
251+
#[inline(always)]
252+
pub fn box_new<T>(x: T) -> Box<T> {
253+
#[rustc_box]
254+
Box::new(x)
255+
}
256+
238257
impl<T> Box<T> {
239258
/// Allocates memory on the heap and then places `x` into it.
240259
///
@@ -252,8 +271,7 @@ impl<T> Box<T> {
252271
#[rustc_diagnostic_item = "box_new"]
253272
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
254273
pub fn new(x: T) -> Self {
255-
#[rustc_box]
256-
Box::new(x)
274+
return box_new(x);
257275
}
258276

259277
/// Constructs a new box with uninitialized contents.
@@ -763,6 +781,26 @@ impl<T> Box<[T]> {
763781
};
764782
unsafe { Ok(RawVec::from_raw_parts_in(ptr.as_ptr(), len, Global).into_box(len)) }
765783
}
784+
785+
/// Converts the boxed slice into a boxed array.
786+
///
787+
/// This operation does not reallocate; the underlying array of the slice is simply reinterpreted as an array type.
788+
///
789+
/// If `N` is not exactly equal to the length of `self`, then this method returns `None`.
790+
#[unstable(feature = "slice_as_array", issue = "133508")]
791+
#[inline]
792+
#[must_use]
793+
pub fn into_array<const N: usize>(self) -> Option<Box<[T; N]>> {
794+
if self.len() == N {
795+
let ptr = Self::into_raw(self) as *mut [T; N];
796+
797+
// 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.
798+
let me = unsafe { Box::from_raw(ptr) };
799+
Some(me)
800+
} else {
801+
None
802+
}
803+
}
766804
}
767805

768806
impl<T, A: Allocator> Box<[T], A> {
@@ -1027,6 +1065,8 @@ impl<T: ?Sized> Box<T> {
10271065
/// memory problems. For example, a double-free may occur if the
10281066
/// function is called twice on the same raw pointer.
10291067
///
1068+
/// The raw pointer must point to a block of memory allocated by the global allocator.
1069+
///
10301070
/// The safety conditions are described in the [memory layout] section.
10311071
///
10321072
/// # Examples
@@ -1130,6 +1170,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
11301170
/// memory problems. For example, a double-free may occur if the
11311171
/// function is called twice on the same raw pointer.
11321172
///
1173+
/// The raw pointer must point to a block of memory allocated by `alloc`
11331174
///
11341175
/// # Examples
11351176
///
@@ -1502,7 +1543,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
15021543
/// [`as_ptr`]: Self::as_ptr
15031544
#[unstable(feature = "box_as_ptr", issue = "129090")]
15041545
#[rustc_never_returns_null_ptr]
1505-
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
1546+
#[rustc_as_ptr]
15061547
#[inline]
15071548
pub fn as_mut_ptr(b: &mut Self) -> *mut T {
15081549
// This is a primitive deref, not going through `DerefMut`, and therefore not materializing
@@ -1551,7 +1592,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
15511592
/// [`as_ptr`]: Self::as_ptr
15521593
#[unstable(feature = "box_as_ptr", issue = "129090")]
15531594
#[rustc_never_returns_null_ptr]
1554-
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
1595+
#[rustc_as_ptr]
15551596
#[inline]
15561597
pub fn as_ptr(b: &Self) -> *const T {
15571598
// This is a primitive deref, not going through `DerefMut`, and therefore not materializing
@@ -1987,7 +2028,7 @@ impl<Args: Tuple, F: Fn<Args> + ?Sized, A: Allocator> Fn<Args> for Box<F, A> {
19872028
}
19882029
}
19892030

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

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

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

2137-
#[cfg(not(bootstrap))]
21382178
#[unstable(feature = "pointer_like_trait", issue = "none")]
21392179
impl<T> PointerLike for Box<T> {}

library/alloc/src/boxed/convert.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<T: Clone> From<&[T]> for Box<[T]> {
110110
}
111111

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

173173
#[cfg(not(no_global_oom_handling))]
174-
#[stable(feature = "box_from_mut_slice", since = "CURRENT_RUSTC_VERSION")]
174+
#[stable(feature = "box_from_mut_slice", since = "1.84.0")]
175175
impl From<&mut str> for Box<str> {
176176
/// Converts a `&mut str` into a `Box<str>`
177177
///

0 commit comments

Comments
 (0)