Skip to content

Commit 30d156b

Browse files
github-actions[bot]ChrisDentonno1wudiborsAyush1325
authored
Merge subtree update for toolchain nightly-2025-05-06 (#354)
This is an automated PR to merge library subtree updates from 2025-04-24 (rust-lang/rust@df35ff6) to 2025-05-06 (rust-lang/rust@2e6882a) (inclusive) into main. `git merge` resulted in conflicts, which require manual resolution. Files were commited with merge conflict markers. **Do not remove or edit the following annotations:** git-subtree-dir: library git-subtree-split: 794e274 --------- Signed-off-by: Huang Qi <[email protected]> Signed-off-by: Ayush Singh <[email protected]> Signed-off-by: xizheyin <[email protected]> Signed-off-by: Alice Ryhl <[email protected]> Signed-off-by: Jiahao XU <[email protected]> Signed-off-by: Sean Cross <[email protected]> Co-authored-by: Chris Denton <[email protected]> Co-authored-by: Huang Qi <[email protected]> Co-authored-by: bors <[email protected]> Co-authored-by: Ayush Singh <[email protected]> Co-authored-by: Thalia Archibald <[email protected]> Co-authored-by: Jacob Pratt <[email protected]> Co-authored-by: xizheyin <[email protected]> Co-authored-by: Diego Ongaro <[email protected]> Co-authored-by: Jethro Beekman <[email protected]> Co-authored-by: Ralf Jung <[email protected]> Co-authored-by: Janggun Lee <[email protected]> Co-authored-by: 0x79de <[email protected]> Co-authored-by: Matthias Krüger <[email protected]> Co-authored-by: binarycat <[email protected]> Co-authored-by: Glyn Normington <[email protected]> Co-authored-by: Stuart Cook <[email protected]> Co-authored-by: Tamir Duberstein <[email protected]> Co-authored-by: Alice Ryhl <[email protected]> Co-authored-by: Mara Bos <[email protected]> Co-authored-by: Josh Triplett <[email protected]> Co-authored-by: Bastian Kersting <[email protected]> Co-authored-by: Guillaume Gomez <[email protected]> Co-authored-by: Lyndon Brown <[email protected]> Co-authored-by: Kent Ross <[email protected]> Co-authored-by: Amanieu d'Antras <[email protected]> Co-authored-by: Noa <[email protected]> Co-authored-by: Ed Page <[email protected]> Co-authored-by: Trevor Gross <[email protected]> Co-authored-by: The Miri Cronjob Bot <[email protected]> Co-authored-by: Lieselotte <[email protected]> Co-authored-by: Patrick Mooney <[email protected]> Co-authored-by: Scott McMurray <[email protected]> Co-authored-by: Jonathan Gruner <[email protected]> Co-authored-by: Chris Denton <[email protected]> Co-authored-by: Onè <[email protected]> Co-authored-by: Folkert de Vries <[email protected]> Co-authored-by: Urgau <[email protected]> Co-authored-by: 王宇逸 <[email protected]> Co-authored-by: Jonas Böttiger <[email protected]> Co-authored-by: Hegui Dai <[email protected]> Co-authored-by: Gabriel Bjørnager Jensen <[email protected]> Co-authored-by: Artur Roos <[email protected]> Co-authored-by: Jiahao XU <[email protected]> Co-authored-by: Nicholas Nethercote <[email protected]> Co-authored-by: bendn <[email protected]> Co-authored-by: ismailarilik <[email protected]> Co-authored-by: Tobias <[email protected]> Co-authored-by: Ethan Wu <[email protected]> Co-authored-by: Jake Goulding <[email protected]> Co-authored-by: Michael Howell <[email protected]> Co-authored-by: Christopher Durham <[email protected]> Co-authored-by: Pavel Grigorenko <[email protected]> Co-authored-by: LemonJ <[email protected]> Co-authored-by: SabrinaJewson <[email protected]> Co-authored-by: Andrew Zhogin <[email protected]> Co-authored-by: DaniPopes <[email protected]> Co-authored-by: Sean Cross <[email protected]> Co-authored-by: Trevor Gross <[email protected]> Co-authored-by: Zachary S <[email protected]> Co-authored-by: sayantn <[email protected]> Co-authored-by: Eyal Kalderon <[email protected]> Co-authored-by: Lynnesbian <[email protected]> Co-authored-by: Christopher Berner <[email protected]> Co-authored-by: gitbot <git@bot> Co-authored-by: Michael Tautschnig <[email protected]> Co-authored-by: Carolyn Zech <[email protected]>
1 parent 571c8ac commit 30d156b

File tree

212 files changed

+3356
-2564
lines changed

Some content is hidden

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

212 files changed

+3356
-2564
lines changed

.github/workflows/kani.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jobs:
122122
--exclude-pattern time::Duration::from_secs_f \
123123
--include-pattern unicode::unicode_data::conversions::to_ \
124124
--exclude-pattern ::precondition_check \
125-
--harness-timeout 5m \
125+
--harness-timeout 10m \
126126
--default-unwind 1000 \
127127
--jobs=3 --output-format=terse
128128

library/Cargo.lock

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

library/alloc/src/collections/btree/set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub struct Iter<'a, T: 'a> {
139139
#[stable(feature = "collection_debug", since = "1.17.0")]
140140
impl<T: fmt::Debug> fmt::Debug for Iter<'_, T> {
141141
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
142-
f.debug_tuple("Iter").field(&self.iter.clone()).finish()
142+
f.debug_tuple("Iter").field(&self.iter).finish()
143143
}
144144
}
145145

library/alloc/src/ffi/c_str.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,14 @@ impl CString {
351351
/// # Safety
352352
///
353353
/// This should only ever be called with a pointer that was earlier
354-
/// obtained by calling [`CString::into_raw`]. Other usage (e.g., trying to take
355-
/// ownership of a string that was allocated by foreign code) is likely to lead
356-
/// to undefined behavior or allocator corruption.
354+
/// obtained by calling [`CString::into_raw`], and the memory it points to must not be accessed
355+
/// through any other pointer during the lifetime of reconstructed `CString`.
356+
/// Other usage (e.g., trying to take ownership of a string that was allocated by foreign code)
357+
/// is likely to lead to undefined behavior or allocator corruption.
358+
///
359+
/// This function does not validate ownership of the raw pointer's memory.
360+
/// A double-free may occur if the function is called twice on the same raw pointer.
361+
/// Additionally, the caller must ensure the pointer is not dangling.
357362
///
358363
/// It should be noted that the length isn't just "recomputed," but that
359364
/// the recomputed length must match the original length from the
@@ -818,6 +823,7 @@ impl From<Vec<NonZero<u8>>> for CString {
818823
}
819824
}
820825

826+
#[stable(feature = "c_string_from_str", since = "1.85.0")]
821827
impl FromStr for CString {
822828
type Err = NulError;
823829

@@ -830,6 +836,7 @@ impl FromStr for CString {
830836
}
831837
}
832838

839+
#[stable(feature = "c_string_from_str", since = "1.85.0")]
833840
impl TryFrom<CString> for String {
834841
type Error = IntoStringError;
835842

library/alloc/src/ffi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ pub use self::c_str::CString;
8787
#[stable(feature = "alloc_c_string", since = "1.64.0")]
8888
pub use self::c_str::{FromVecWithNulError, IntoStringError, NulError};
8989

90-
#[unstable(feature = "c_str_module", issue = "112134")]
90+
#[stable(feature = "c_str_module", since = "CURRENT_RUSTC_VERSION")]
9191
pub mod c_str;

library/alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
#![feature(fmt_internals)]
124124
#![feature(fn_traits)]
125125
#![feature(formatting_options)]
126+
#![feature(generic_atomic)]
126127
#![feature(hasher_prefixfree_extras)]
127128
#![feature(inplace_iteration)]
128129
#![feature(iter_advance_by)]

library/alloc/src/macros.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ macro_rules! vec {
105105
macro_rules! format {
106106
($($arg:tt)*) => {
107107
$crate::__export::must_use({
108-
let res = $crate::fmt::format($crate::__export::format_args!($($arg)*));
109-
res
108+
$crate::fmt::format($crate::__export::format_args!($($arg)*))
110109
})
111110
}
112111
}

library/alloc/src/str.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,10 @@ impl str {
603603
/// Converts a boxed slice of bytes to a boxed string slice without checking
604604
/// that the string contains valid UTF-8.
605605
///
606+
/// # Safety
607+
///
608+
/// * The provided bytes must contain a valid UTF-8 sequence.
609+
///
606610
/// # Examples
607611
///
608612
/// ```

library/alloc/src/string.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,7 @@ impl String {
18321832
#[stable(feature = "rust1", since = "1.0.0")]
18331833
#[rustc_const_stable(feature = "const_vec_string_slice", since = "1.87.0")]
18341834
#[rustc_confusables("length", "size")]
1835+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
18351836
pub const fn len(&self) -> usize {
18361837
self.vec.len()
18371838
}
@@ -1851,6 +1852,7 @@ impl String {
18511852
#[must_use]
18521853
#[stable(feature = "rust1", since = "1.0.0")]
18531854
#[rustc_const_stable(feature = "const_vec_string_slice", since = "1.87.0")]
1855+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
18541856
pub const fn is_empty(&self) -> bool {
18551857
self.len() == 0
18561858
}

library/alloc/src/sync.rs

Lines changed: 66 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ use core::pin::{Pin, PinCoerceUnsized};
2626
use core::ptr::{self, NonNull};
2727
#[cfg(not(no_global_oom_handling))]
2828
use core::slice::from_raw_parts_mut;
29-
use core::sync::atomic;
3029
use core::sync::atomic::Ordering::{Acquire, Relaxed, Release};
30+
use core::sync::atomic::{self, Atomic};
3131
use core::{borrow, fmt, hint};
3232

3333
#[cfg(not(no_global_oom_handling))]
@@ -369,12 +369,12 @@ impl<T: ?Sized, A: Allocator> fmt::Debug for Weak<T, A> {
369369
// inner types.
370370
#[repr(C)]
371371
struct ArcInner<T: ?Sized> {
372-
strong: atomic::AtomicUsize,
372+
strong: Atomic<usize>,
373373

374374
// the value usize::MAX acts as a sentinel for temporarily "locking" the
375375
// ability to upgrade weak pointers or downgrade strong ones; this is used
376376
// to avoid races in `make_mut` and `get_mut`.
377-
weak: atomic::AtomicUsize,
377+
weak: Atomic<usize>,
378378

379379
data: T,
380380
}
@@ -2446,7 +2446,7 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
24462446
#[inline]
24472447
#[stable(feature = "arc_unique", since = "1.4.0")]
24482448
pub fn get_mut(this: &mut Self) -> Option<&mut T> {
2449-
if this.is_unique() {
2449+
if Self::is_unique(this) {
24502450
// This unsafety is ok because we're guaranteed that the pointer
24512451
// returned is the *only* pointer that will ever be returned to T. Our
24522452
// reference count is guaranteed to be 1 at this point, and we required
@@ -2526,28 +2526,81 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
25262526
unsafe { &mut (*this.ptr.as_ptr()).data }
25272527
}
25282528

2529-
/// Determine whether this is the unique reference (including weak refs) to
2530-
/// the underlying data.
2529+
/// Determine whether this is the unique reference to the underlying data.
25312530
///
2532-
/// Note that this requires locking the weak ref count.
2533-
fn is_unique(&mut self) -> bool {
2531+
/// Returns `true` if there are no other `Arc` or [`Weak`] pointers to the same allocation;
2532+
/// returns `false` otherwise.
2533+
///
2534+
/// If this function returns `true`, then is guaranteed to be safe to call [`get_mut_unchecked`]
2535+
/// on this `Arc`, so long as no clones occur in between.
2536+
///
2537+
/// # Examples
2538+
///
2539+
/// ```
2540+
/// #![feature(arc_is_unique)]
2541+
///
2542+
/// use std::sync::Arc;
2543+
///
2544+
/// let x = Arc::new(3);
2545+
/// assert!(Arc::is_unique(&x));
2546+
///
2547+
/// let y = Arc::clone(&x);
2548+
/// assert!(!Arc::is_unique(&x));
2549+
/// drop(y);
2550+
///
2551+
/// // Weak references also count, because they could be upgraded at any time.
2552+
/// let z = Arc::downgrade(&x);
2553+
/// assert!(!Arc::is_unique(&x));
2554+
/// ```
2555+
///
2556+
/// # Pointer invalidation
2557+
///
2558+
/// This function will always return the same value as `Arc::get_mut(arc).is_some()`. However,
2559+
/// unlike that operation it does not produce any mutable references to the underlying data,
2560+
/// meaning no pointers to the data inside the `Arc` are invalidated by the call. Thus, the
2561+
/// following code is valid, even though it would be UB if it used `Arc::get_mut`:
2562+
///
2563+
/// ```
2564+
/// #![feature(arc_is_unique)]
2565+
///
2566+
/// use std::sync::Arc;
2567+
///
2568+
/// let arc = Arc::new(5);
2569+
/// let pointer: *const i32 = &*arc;
2570+
/// assert!(Arc::is_unique(&arc));
2571+
/// assert_eq!(unsafe { *pointer }, 5);
2572+
/// ```
2573+
///
2574+
/// # Atomic orderings
2575+
///
2576+
/// Concurrent drops to other `Arc` pointers to the same allocation will synchronize with this
2577+
/// call - that is, this call performs an `Acquire` operation on the underlying strong and weak
2578+
/// ref counts. This ensures that calling `get_mut_unchecked` is safe.
2579+
///
2580+
/// Note that this operation requires locking the weak ref count, so concurrent calls to
2581+
/// `downgrade` may spin-loop for a short period of time.
2582+
///
2583+
/// [`get_mut_unchecked`]: Self::get_mut_unchecked
2584+
#[inline]
2585+
#[unstable(feature = "arc_is_unique", issue = "138938")]
2586+
pub fn is_unique(this: &Self) -> bool {
25342587
// lock the weak pointer count if we appear to be the sole weak pointer
25352588
// holder.
25362589
//
25372590
// The acquire label here ensures a happens-before relationship with any
25382591
// writes to `strong` (in particular in `Weak::upgrade`) prior to decrements
25392592
// of the `weak` count (via `Weak::drop`, which uses release). If the upgraded
25402593
// weak ref was never dropped, the CAS here will fail so we do not care to synchronize.
2541-
if self.inner().weak.compare_exchange(1, usize::MAX, Acquire, Relaxed).is_ok() {
2594+
if this.inner().weak.compare_exchange(1, usize::MAX, Acquire, Relaxed).is_ok() {
25422595
// This needs to be an `Acquire` to synchronize with the decrement of the `strong`
25432596
// counter in `drop` -- the only access that happens when any but the last reference
25442597
// is being dropped.
2545-
let unique = self.inner().strong.load(Acquire) == 1;
2598+
let unique = this.inner().strong.load(Acquire) == 1;
25462599

25472600
// The release write here synchronizes with a read in `downgrade`,
25482601
// effectively preventing the above read of `strong` from happening
25492602
// after the write.
2550-
self.inner().weak.store(1, Release); // release the lock
2603+
this.inner().weak.store(1, Release); // release the lock
25512604
unique
25522605
} else {
25532606
false
@@ -2760,8 +2813,8 @@ impl<T, A: Allocator> Weak<T, A> {
27602813
/// Helper type to allow accessing the reference counts without
27612814
/// making any assertions about the data field.
27622815
struct WeakInner<'a> {
2763-
weak: &'a atomic::AtomicUsize,
2764-
strong: &'a atomic::AtomicUsize,
2816+
weak: &'a Atomic<usize>,
2817+
strong: &'a Atomic<usize>,
27652818
}
27662819

27672820
impl<T: ?Sized> Weak<T> {

library/alloc/src/vec/into_iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl<T, A: Allocator> IntoIter<T, A> {
168168

169169
// SAFETY: This allocation originally came from a `Vec`, so it passes
170170
// all those checks. We have `this.buf` ≤ `this.ptr` ≤ `this.end`,
171-
// so the `sub_ptr`s below cannot wrap, and will produce a well-formed
171+
// so the `offset_from_unsigned`s below cannot wrap, and will produce a well-formed
172172
// range. `end` ≤ `buf + cap`, so the range will be in-bounds.
173173
// Taking `alloc` is ok because nothing else is going to look at it,
174174
// since our `Drop` impl isn't going to run so there's no more code.

library/alloc/src/vec/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2588,7 +2588,7 @@ impl<T, A: Allocator> Vec<T, A> {
25882588
#[inline]
25892589
#[track_caller]
25902590
unsafe fn append_elements(&mut self, other: *const [T]) {
2591-
let count = unsafe { (*other).len() };
2591+
let count = other.len();
25922592
self.reserve(count);
25932593
let len = self.len();
25942594
unsafe { ptr::copy_nonoverlapping(other as *const T, self.as_mut_ptr().add(len), count) };

library/alloc/src/vec/splice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<I: Iterator, A: Allocator> Drop for Splice<'_, I, A> {
5959
// and moving things into the final place.
6060
// Which means we can replace the slice::Iter with pointers that won't point to deallocated
6161
// memory, so that Drain::drop is still allowed to call iter.len(), otherwise it would break
62-
// the ptr.sub_ptr contract.
62+
// the ptr.offset_from_unsigned contract.
6363
self.drain.iter = (&[]).iter();
6464

6565
unsafe {

library/alloctests/tests/fmt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![deny(warnings)]
22
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
33
#![allow(static_mut_refs)]
4+
#![cfg_attr(not(bootstrap), allow(unnecessary_transmutes))]
45

56
use std::cell::RefCell;
67
use std::fmt::{self, Write};

library/core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ level = "warn"
3434
check-cfg = [
3535
'cfg(bootstrap)',
3636
'cfg(no_fp_fmt_parse)',
37-
'cfg(stdarch_intel_sde)',
3837
# core use #[path] imports to portable-simd `core_simd` crate
3938
# and to stdarch `core_arch` crate which messes-up with Cargo list
4039
# of declared features, we therefor expect any feature cfg

library/core/src/alloc/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl fmt::Display for AllocError {
9090
/// # Safety
9191
///
9292
/// Memory blocks that are [*currently allocated*] by an allocator,
93-
/// must point to valid memory, and retain their validity while until either:
93+
/// must point to valid memory, and retain their validity until either:
9494
/// - the memory block is deallocated, or
9595
/// - the allocator is dropped.
9696
///
@@ -112,7 +112,9 @@ pub unsafe trait Allocator {
112112
///
113113
/// The returned block of memory remains valid as long as it is [*currently allocated*] and the shorter of:
114114
/// - the borrow-checker lifetime of the allocator type itself.
115-
/// - as long as at the allocator and all its clones has not been dropped.
115+
/// - as long as the allocator and all its clones have not been dropped.
116+
///
117+
/// [*currently allocated*]: #currently-allocated-memory
116118
///
117119
/// # Errors
118120
///

library/core/src/cell.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,16 +549,14 @@ impl<T: Copy> Cell<T> {
549549
/// # Examples
550550
///
551551
/// ```
552-
/// #![feature(cell_update)]
553-
///
554552
/// use std::cell::Cell;
555553
///
556554
/// let c = Cell::new(5);
557555
/// c.update(|x| x + 1);
558556
/// assert_eq!(c.get(), 6);
559557
/// ```
560558
#[inline]
561-
#[unstable(feature = "cell_update", issue = "50186")]
559+
#[stable(feature = "cell_update", since = "CURRENT_RUSTC_VERSION")]
562560
pub fn update(&self, f: impl FnOnce(T) -> T) {
563561
let old = self.get();
564562
self.set(f(old));

library/core/src/char/convert.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub(super) const fn from_u32(i: u32) -> Option<char> {
2525
/// Converts a `u32` to a `char`, ignoring validity. See [`char::from_u32_unchecked`].
2626
#[inline]
2727
#[must_use]
28+
#[cfg_attr(not(bootstrap), allow(unnecessary_transmutes))]
2829
#[requires(char_try_from_u32(i).is_ok())]
2930
#[ensures(|result| *result as u32 == i)]
3031
pub(super) const unsafe fn from_u32_unchecked(i: u32) -> char {
@@ -227,6 +228,7 @@ impl FromStr for char {
227228
}
228229

229230
#[inline]
231+
#[cfg_attr(not(bootstrap), allow(unnecessary_transmutes))]
230232
const fn char_try_from_u32(i: u32) -> Result<char, CharTryFromError> {
231233
// This is an optimized version of the check
232234
// (i > MAX as u32) || (i >= 0xD800 && i <= 0xDFFF),

library/core/src/ffi/c_str.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ use crate::{fmt, ops, slice, str};
8686
///
8787
/// fn my_string_safe() -> String {
8888
/// let cstr = unsafe { CStr::from_ptr(my_string()) };
89-
/// // Get copy-on-write Cow<'_, str>, then guarantee a freshly-owned String allocation
90-
/// String::from_utf8_lossy(cstr.to_bytes()).to_string()
89+
/// // Get a copy-on-write Cow<'_, str>, then extract the
90+
/// // allocated String (or allocate a fresh one if needed).
91+
/// cstr.to_string_lossy().into_owned()
9192
/// }
9293
///
9394
/// println!("string: {}", my_string_safe());

library/core/src/ffi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub use self::c_str::FromBytesUntilNulError;
2020
pub use self::c_str::FromBytesWithNulError;
2121
use crate::fmt;
2222

23-
#[unstable(feature = "c_str_module", issue = "112134")]
23+
#[stable(feature = "c_str_module", since = "CURRENT_RUSTC_VERSION")]
2424
pub mod c_str;
2525

2626
#[unstable(

0 commit comments

Comments
 (0)