Skip to content

Commit 1184942

Browse files
github-actions[bot]gitbottautschnig
authored
Merge subtree update for toolchain nightly-2025-03-13 (#274)
This is an automated PR to merge library subtree updates from 2025-02-11 (6171d94) to 2025-03-13 (249cb84) (inclusive) into main. `git merge` resulted in conflicts, which require manual resolution. Files were commited with merge conflict markers. --------- Co-authored-by: gitbot <git@bot> Co-authored-by: Michael Tautschnig <[email protected]>
1 parent 9b27cfb commit 1184942

File tree

492 files changed

+10699
-9325
lines changed

Some content is hidden

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

492 files changed

+10699
-9325
lines changed

library/Cargo.lock

+79-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

library/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ members = [
44
"std",
55
"sysroot",
66
"coretests",
7+
"alloctests",
78
]
89

910
exclude = [

library/alloc/Cargo.toml

+8-24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
cargo-features = ["public-dependency"]
2+
13
[package]
24
name = "alloc"
35
version = "0.0.0"
@@ -8,33 +10,15 @@ autotests = false
810
autobenches = false
911
edition = "2021"
1012

13+
[lib]
14+
test = false
15+
bench = false
16+
1117
[dependencies]
12-
core = { path = "../core" }
13-
compiler_builtins = { version = "=0.1.145", features = ['rustc-dep-of-std'] }
18+
core = { path = "../core", public = true }
19+
compiler_builtins = { version = "=0.1.151", features = ['rustc-dep-of-std'] }
1420
safety = { path = "../contracts/safety" }
1521

16-
[dev-dependencies]
17-
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }
18-
rand_xorshift = "0.3.0"
19-
20-
[[test]]
21-
name = "alloctests"
22-
path = "tests/lib.rs"
23-
24-
[[test]]
25-
name = "vec_deque_alloc_error"
26-
path = "tests/vec_deque_alloc_error.rs"
27-
28-
[[bench]]
29-
name = "allocbenches"
30-
path = "benches/lib.rs"
31-
test = true
32-
33-
[[bench]]
34-
name = "vec_deque_append_bench"
35-
path = "benches/vec_deque_append.rs"
36-
harness = false
37-
3822
[features]
3923
compiler-builtins-mem = ['compiler_builtins/mem']
4024
compiler-builtins-c = ["compiler_builtins/c"]

library/alloc/src/alloc.rs

+14-20
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
#[stable(feature = "alloc_module", since = "1.28.0")]
66
#[doc(inline)]
77
pub use core::alloc::*;
8-
#[cfg(not(test))]
98
use core::hint;
10-
#[cfg(not(test))]
119
use core::ptr::{self, NonNull};
1210

13-
extern "Rust" {
11+
unsafe extern "Rust" {
1412
// These are the magic symbols to call the global allocator. rustc generates
1513
// them to call `__rg_alloc` etc. if there is a `#[global_allocator]` attribute
1614
// (the code expanding that attribute macro generates those functions), or to call
@@ -44,14 +42,10 @@ extern "Rust" {
4442
/// accessed through the [free functions in `alloc`](self#functions).
4543
#[unstable(feature = "allocator_api", issue = "32838")]
4644
#[derive(Copy, Clone, Default, Debug)]
47-
#[cfg(not(test))]
4845
// the compiler needs to know when a Box uses the global allocator vs a custom one
4946
#[lang = "global_alloc_ty"]
5047
pub struct Global;
5148

52-
#[cfg(test)]
53-
pub use std::alloc::Global;
54-
5549
/// Allocates memory with the global allocator.
5650
///
5751
/// This function forwards calls to the [`GlobalAlloc::alloc`] method
@@ -180,7 +174,6 @@ pub unsafe fn alloc_zeroed(layout: Layout) -> *mut u8 {
180174
}
181175
}
182176

183-
#[cfg(not(test))]
184177
impl Global {
185178
#[inline]
186179
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
@@ -246,7 +239,6 @@ impl Global {
246239
}
247240

248241
#[unstable(feature = "allocator_api", issue = "32838")]
249-
#[cfg(not(test))]
250242
unsafe impl Allocator for Global {
251243
#[inline]
252244
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
@@ -264,8 +256,14 @@ unsafe impl Allocator for Global {
264256
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
265257
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
266258
if layout.size() != 0 {
267-
// SAFETY: `layout` is non-zero in size,
268-
// other conditions must be upheld by the caller
259+
// SAFETY:
260+
// * We have checked that `layout` is non-zero in size.
261+
// * The caller is obligated to provide a layout that "fits", and in this case,
262+
// "fit" always means a layout that is equal to the original, because our
263+
// `allocate()`, `grow()`, and `shrink()` implementations never returns a larger
264+
// allocation than requested.
265+
// * Other conditions must be upheld by the caller, as per `Allocator::deallocate()`'s
266+
// safety documentation.
269267
unsafe { dealloc(ptr.as_ptr(), layout) }
270268
}
271269
}
@@ -340,7 +338,7 @@ unsafe impl Allocator for Global {
340338
}
341339

342340
/// The allocator for `Box`.
343-
#[cfg(all(not(no_global_oom_handling), not(test)))]
341+
#[cfg(not(no_global_oom_handling))]
344342
#[lang = "exchange_malloc"]
345343
#[inline]
346344
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
@@ -355,7 +353,7 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
355353
// # Allocation error handler
356354

357355
#[cfg(not(no_global_oom_handling))]
358-
extern "Rust" {
356+
unsafe extern "Rust" {
359357
// This is the magic symbol to call the global alloc error handler. rustc generates
360358
// it to call `__rg_oom` if there is a `#[alloc_error_handler]`, or to call the
361359
// default implementations below (`__rdl_oom`) otherwise.
@@ -389,7 +387,7 @@ extern "Rust" {
389387
/// [no_std]: https://doc.rust-lang.org/reference/names/preludes.html#the-no_std-attribute
390388
#[stable(feature = "global_alloc", since = "1.28.0")]
391389
#[rustc_const_unstable(feature = "const_alloc_error", issue = "92523")]
392-
#[cfg(all(not(no_global_oom_handling), not(test)))]
390+
#[cfg(not(no_global_oom_handling))]
393391
#[cold]
394392
#[optimize(size)]
395393
pub const fn handle_alloc_error(layout: Layout) -> ! {
@@ -413,11 +411,7 @@ pub const fn handle_alloc_error(layout: Layout) -> ! {
413411
ct_error(layout)
414412
}
415413

416-
// For alloc test `std::alloc::handle_alloc_error` can be used directly.
417-
#[cfg(all(not(no_global_oom_handling), test))]
418-
pub use std::alloc::handle_alloc_error;
419-
420-
#[cfg(all(not(no_global_oom_handling), not(test)))]
414+
#[cfg(not(no_global_oom_handling))]
421415
#[doc(hidden)]
422416
#[allow(unused_attributes)]
423417
#[unstable(feature = "alloc_internals", issue = "none")]
@@ -426,7 +420,7 @@ pub mod __alloc_error_handler {
426420
// `#[alloc_error_handler]`.
427421
#[rustc_std_internal_symbol]
428422
pub unsafe fn __rdl_oom(size: usize, _align: usize) -> ! {
429-
extern "Rust" {
423+
unsafe extern "Rust" {
430424
// This symbol is emitted by rustc next to __rust_alloc_error_handler.
431425
// Its value depends on the -Zoom={panic,abort} compiler option.
432426
static __rust_alloc_error_handler_should_panic: u8;

library/alloc/src/borrow.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ where
3232
/// implementing the `Clone` trait. But `Clone` works only for going from `&T`
3333
/// to `T`. The `ToOwned` trait generalizes `Clone` to construct owned data
3434
/// from any borrow of a given type.
35-
#[cfg_attr(not(test), rustc_diagnostic_item = "ToOwned")]
35+
#[rustc_diagnostic_item = "ToOwned"]
3636
#[stable(feature = "rust1", since = "1.0.0")]
3737
pub trait ToOwned {
3838
/// The resulting type after obtaining ownership.
@@ -54,7 +54,7 @@ pub trait ToOwned {
5454
/// ```
5555
#[stable(feature = "rust1", since = "1.0.0")]
5656
#[must_use = "cloning is often expensive and is not expected to have side effects"]
57-
#[cfg_attr(not(test), rustc_diagnostic_item = "to_owned_method")]
57+
#[rustc_diagnostic_item = "to_owned_method"]
5858
fn to_owned(&self) -> Self::Owned;
5959

6060
/// Uses borrowed data to replace owned data, usually by cloning.
@@ -175,7 +175,7 @@ where
175175
/// }
176176
/// ```
177177
#[stable(feature = "rust1", since = "1.0.0")]
178-
#[cfg_attr(not(test), rustc_diagnostic_item = "Cow")]
178+
#[rustc_diagnostic_item = "Cow"]
179179
pub enum Cow<'a, B: ?Sized + 'a>
180180
where
181181
B: ToOwned,
@@ -340,8 +340,18 @@ where
340340
}
341341
}
342342

343+
// `Cow<'_, T>` can only implement `DerefPure` if `<T::Owned as Borrow<T>>` (and `BorrowMut<T>`) is trusted.
344+
// For now, we restrict `DerefPure for Cow<T>` to `T: Sized` (`T as Borrow<T>` is trusted),
345+
// `str` (`String as Borrow<str>` is trusted) and `[T]` (`Vec<T> as Borrow<[T]>` is trusted).
346+
// In the future, a `BorrowPure<T>` trait analogous to `DerefPure` might generalize this.
343347
#[unstable(feature = "deref_pure_trait", issue = "87121")]
344-
unsafe impl<B: ?Sized + ToOwned> DerefPure for Cow<'_, B> where B::Owned: Borrow<B> {}
348+
unsafe impl<T: Clone> DerefPure for Cow<'_, T> {}
349+
#[cfg(not(no_global_oom_handling))]
350+
#[unstable(feature = "deref_pure_trait", issue = "87121")]
351+
unsafe impl DerefPure for Cow<'_, str> {}
352+
#[cfg(not(no_global_oom_handling))]
353+
#[unstable(feature = "deref_pure_trait", issue = "87121")]
354+
unsafe impl<T: Clone> DerefPure for Cow<'_, [T]> {}
345355

346356
#[stable(feature = "rust1", since = "1.0.0")]
347357
impl<B: ?Sized> Eq for Cow<'_, B> where B: Eq + ToOwned {}

0 commit comments

Comments
 (0)