Skip to content

Commit c176f19

Browse files
thanhnguyen-awsGuillaumeGomezKobzoldavidtwconealsid
authored
Update for toolchain nightly-2025-07-10 + Fix loop-invariant (#417)
This PR replaces the failed PR #413 by fixing the loop invariant for `small_slice_eq`. Automated PR (413) description: This is an automated PR to merge library subtree updates from 2025-07-02 (rust-lang@71e4c00) to 2025-07-10 (rust-lang@e43d139) (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: d836404 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses. --------- Signed-off-by: Ayush Singh <ayush@beagleboard.org> Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn> Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com> Co-authored-by: Jakub Beránek <berykubik@gmail.com> Co-authored-by: David Wood <david.wood2@arm.com> Co-authored-by: Neal <nealsid@users.noreply.github.com> Co-authored-by: Tomoaki Kobayashi <tomoaki.kobayashi.t3@alumni.tohoku.ac.jp> Co-authored-by: Daniel Paoliello <danpao@microsoft.com> Co-authored-by: Marijn Schouten <hkBst@users.noreply.github.com> Co-authored-by: Marijn Schouten <mhkbst@gmail.com> Co-authored-by: Jubilee <workingjubilee@gmail.com> Co-authored-by: Benoît du Garreau <benoit@dugarreau.fr> Co-authored-by: bors <bors@rust-lang.org> Co-authored-by: Trevor Gross <tmgross@umich.edu> Co-authored-by: Aniket Mishra <143333884+satiscugcat@users.noreply.github.com> Co-authored-by: satiscugcat <23110026@iitgn.ac.in> Co-authored-by: Jacob Pratt <jacob@jhpratt.dev> Co-authored-by: Jeremy Smart <jeremy3141592@gmail.com> Co-authored-by: Mara Bos <m-ou.se@m-ou.se> Co-authored-by: Urgau <3616612+Urgau@users.noreply.github.com> Co-authored-by: Zachary S <zasample18+github@gmail.com> Co-authored-by: Trevor Gross <t.gross35@gmail.com> Co-authored-by: Tim (Theemathas) Chirananthavat <theemathas@gmail.com> Co-authored-by: Alice Ryhl <aliceryhl@google.com> Co-authored-by: Folkert de Vries <folkert@folkertdev.nl> Co-authored-by: Kornel <kornel@geekhood.net> Co-authored-by: LimpSquid <git@limpsquid.nl> Co-authored-by: Daniel Bloom <7810950-Daniel.Aaron.Bloom@users.noreply.gitlab.com> Co-authored-by: Ed Page <eopage@gmail.com> Co-authored-by: The Miri Cronjob Bot <miri@cron.bot> Co-authored-by: Chai T. Rex <ChaiTRex@users.noreply.github.com> Co-authored-by: Valdemar Erk <valdemar@erk.dev> Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com> Co-authored-by: Samuel Tardieu <sam@rfc1149.net> Co-authored-by: binarycat <binarycat@envs.net> Co-authored-by: Tshepang Mbambo <hopsi@tuta.io> Co-authored-by: Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> Co-authored-by: mejrs <59372212+mejrs@users.noreply.github.com> Co-authored-by: Laine Taffin Altman <alexanderaltman@me.com> Co-authored-by: Oli Scherer <github333195615777966@oli-obk.de> Co-authored-by: MetaNova <adam.magnum@gmail.com> Co-authored-by: Kurt Heiritz (pseudo) <saarthkarkera@gmail.com> Co-authored-by: krikera <prafulrai522@gmail.com> Co-authored-by: Pavel Grigorenko <GrigorenkoPV@ya.ru> Co-authored-by: Michael Goulet <michael@errs.io> Co-authored-by: Bastian Kersting <bkersting@google.com> Co-authored-by: Deadbeef <ent3rm4n@gmail.com> Co-authored-by: Cheng Xu <git@xuc.me> Co-authored-by: Chris Denton <chris@chrisdenton.dev> Co-authored-by: наб <nabijaczleweli@nabijaczleweli.xyz> Co-authored-by: kilavvy <140459108+kilavvy@users.noreply.github.com> Co-authored-by: Ralf Jung <post@ralfj.de> Co-authored-by: zachs18 <8355914+zachs18@users.noreply.github.com> Co-authored-by: dianqk <dianqk@dianqk.net> Co-authored-by: Nurzhan Sakén <nurzhan.sakenov@gmail.com> Co-authored-by: Benjamin Schulz <benjamin.schulz@sap.com> Co-authored-by: Amanieu d'Antras <amanieu@gmail.com> Co-authored-by: Josh Stone <jistone@redhat.com> Co-authored-by: klensy <klensy@users.noreply.github.com> Co-authored-by: clubby789 <jamie@hill-daniel.co.uk> Co-authored-by: Jana Dönszelmann <jonathan@donsz.nl> Co-authored-by: Urgau <urgau@numericable.fr> Co-authored-by: Ayush Singh <ayush@beagleboard.org> Co-authored-by: Ben Kimock <kimockb@gmail.com> Co-authored-by: Joshua Gentry <pixel@deathbysoftware.com> Co-authored-by: dvdsk <noreply@davidsk.dev> Co-authored-by: Yotam Ofek <yotam.ofek@gmail.com> Co-authored-by: Simonas Kazlauskas <git@kazlauskas.me> Co-authored-by: xizheyin <xizheyin@smail.nju.edu.cn> Co-authored-by: 许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com> Co-authored-by: Md. Yeasin Arafat <yeasinarafat4389@gmail.com> Co-authored-by: Esteban Küber <esteban@kuber.com.ar> Co-authored-by: gitbot <git@bot> Co-authored-by: Michael Tautschnig <tautschn@amazon.com>
1 parent e4bedab commit c176f19

File tree

115 files changed

+1421
-992
lines changed

Some content is hidden

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

115 files changed

+1421
-992
lines changed

library/alloc/src/alloc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,10 @@ pub mod __alloc_error_handler {
429429
// This symbol is emitted by rustc next to __rust_alloc_error_handler.
430430
// Its value depends on the -Zoom={panic,abort} compiler option.
431431
#[rustc_std_internal_symbol]
432-
static __rust_alloc_error_handler_should_panic: u8;
432+
fn __rust_alloc_error_handler_should_panic_v2() -> u8;
433433
}
434434

435-
if unsafe { __rust_alloc_error_handler_should_panic != 0 } {
435+
if unsafe { __rust_alloc_error_handler_should_panic_v2() != 0 } {
436436
panic!("memory allocation of {size} bytes failed")
437437
} else {
438438
core::panicking::panic_nounwind_fmt(

library/alloc/src/boxed.rs

Lines changed: 118 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ use core::error::{self, Error};
191191
use core::fmt;
192192
use core::future::Future;
193193
use core::hash::{Hash, Hasher};
194-
use core::marker::{PointerLike, Tuple, Unsize};
194+
use core::marker::{Tuple, Unsize};
195195
use core::mem::{self, SizedTypeProperties};
196196
use core::ops::{
197197
AsyncFn, AsyncFnMut, AsyncFnOnce, CoerceUnsized, Coroutine, CoroutineState, Deref, DerefMut,
@@ -1098,115 +1098,6 @@ impl<T: ?Sized> Box<T> {
10981098
pub unsafe fn from_non_null(ptr: NonNull<T>) -> Self {
10991099
unsafe { Self::from_raw(ptr.as_ptr()) }
11001100
}
1101-
}
1102-
1103-
impl<T: ?Sized, A: Allocator> Box<T, A> {
1104-
/// Constructs a box from a raw pointer in the given allocator.
1105-
///
1106-
/// After calling this function, the raw pointer is owned by the
1107-
/// resulting `Box`. Specifically, the `Box` destructor will call
1108-
/// the destructor of `T` and free the allocated memory. For this
1109-
/// to be safe, the memory must have been allocated in accordance
1110-
/// with the [memory layout] used by `Box` .
1111-
///
1112-
/// # Safety
1113-
///
1114-
/// This function is unsafe because improper use may lead to
1115-
/// memory problems. For example, a double-free may occur if the
1116-
/// function is called twice on the same raw pointer.
1117-
///
1118-
/// The raw pointer must point to a block of memory allocated by `alloc`.
1119-
///
1120-
/// # Examples
1121-
///
1122-
/// Recreate a `Box` which was previously converted to a raw pointer
1123-
/// using [`Box::into_raw_with_allocator`]:
1124-
/// ```
1125-
/// #![feature(allocator_api)]
1126-
///
1127-
/// use std::alloc::System;
1128-
///
1129-
/// let x = Box::new_in(5, System);
1130-
/// let (ptr, alloc) = Box::into_raw_with_allocator(x);
1131-
/// let x = unsafe { Box::from_raw_in(ptr, alloc) };
1132-
/// ```
1133-
/// Manually create a `Box` from scratch by using the system allocator:
1134-
/// ```
1135-
/// #![feature(allocator_api, slice_ptr_get)]
1136-
///
1137-
/// use std::alloc::{Allocator, Layout, System};
1138-
///
1139-
/// unsafe {
1140-
/// let ptr = System.allocate(Layout::new::<i32>())?.as_mut_ptr() as *mut i32;
1141-
/// // In general .write is required to avoid attempting to destruct
1142-
/// // the (uninitialized) previous contents of `ptr`, though for this
1143-
/// // simple example `*ptr = 5` would have worked as well.
1144-
/// ptr.write(5);
1145-
/// let x = Box::from_raw_in(ptr, System);
1146-
/// }
1147-
/// # Ok::<(), std::alloc::AllocError>(())
1148-
/// ```
1149-
///
1150-
/// [memory layout]: self#memory-layout
1151-
#[unstable(feature = "allocator_api", issue = "32838")]
1152-
#[inline]
1153-
pub unsafe fn from_raw_in(raw: *mut T, alloc: A) -> Self {
1154-
Box(unsafe { Unique::new_unchecked(raw) }, alloc)
1155-
}
1156-
1157-
/// Constructs a box from a `NonNull` pointer in the given allocator.
1158-
///
1159-
/// After calling this function, the `NonNull` pointer is owned by
1160-
/// the resulting `Box`. Specifically, the `Box` destructor will call
1161-
/// the destructor of `T` and free the allocated memory. For this
1162-
/// to be safe, the memory must have been allocated in accordance
1163-
/// with the [memory layout] used by `Box` .
1164-
///
1165-
/// # Safety
1166-
///
1167-
/// This function is unsafe because improper use may lead to
1168-
/// memory problems. For example, a double-free may occur if the
1169-
/// function is called twice on the same raw pointer.
1170-
///
1171-
/// The non-null pointer must point to a block of memory allocated by `alloc`.
1172-
///
1173-
/// # Examples
1174-
///
1175-
/// Recreate a `Box` which was previously converted to a `NonNull` pointer
1176-
/// using [`Box::into_non_null_with_allocator`]:
1177-
/// ```
1178-
/// #![feature(allocator_api, box_vec_non_null)]
1179-
///
1180-
/// use std::alloc::System;
1181-
///
1182-
/// let x = Box::new_in(5, System);
1183-
/// let (non_null, alloc) = Box::into_non_null_with_allocator(x);
1184-
/// let x = unsafe { Box::from_non_null_in(non_null, alloc) };
1185-
/// ```
1186-
/// Manually create a `Box` from scratch by using the system allocator:
1187-
/// ```
1188-
/// #![feature(allocator_api, box_vec_non_null, slice_ptr_get)]
1189-
///
1190-
/// use std::alloc::{Allocator, Layout, System};
1191-
///
1192-
/// unsafe {
1193-
/// let non_null = System.allocate(Layout::new::<i32>())?.cast::<i32>();
1194-
/// // In general .write is required to avoid attempting to destruct
1195-
/// // the (uninitialized) previous contents of `non_null`.
1196-
/// non_null.write(5);
1197-
/// let x = Box::from_non_null_in(non_null, System);
1198-
/// }
1199-
/// # Ok::<(), std::alloc::AllocError>(())
1200-
/// ```
1201-
///
1202-
/// [memory layout]: self#memory-layout
1203-
#[unstable(feature = "allocator_api", issue = "32838")]
1204-
// #[unstable(feature = "box_vec_non_null", reason = "new API", issue = "130364")]
1205-
#[inline]
1206-
pub unsafe fn from_non_null_in(raw: NonNull<T>, alloc: A) -> Self {
1207-
// SAFETY: guaranteed by the caller.
1208-
unsafe { Box::from_raw_in(raw.as_ptr(), alloc) }
1209-
}
12101101

12111102
/// Consumes the `Box`, returning a wrapped raw pointer.
12121103
///
@@ -1259,8 +1150,11 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
12591150
#[stable(feature = "box_raw", since = "1.4.0")]
12601151
#[inline]
12611152
pub fn into_raw(b: Self) -> *mut T {
1262-
// Make sure Miri realizes that we transition from a noalias pointer to a raw pointer here.
1263-
unsafe { &raw mut *&mut *Self::into_raw_with_allocator(b).0 }
1153+
// Avoid `into_raw_with_allocator` as that interacts poorly with Miri's Stacked Borrows.
1154+
let mut b = mem::ManuallyDrop::new(b);
1155+
// We go through the built-in deref for `Box`, which is crucial for Miri to recognize this
1156+
// operation for it's alias tracking.
1157+
&raw mut **b
12641158
}
12651159

12661160
/// Consumes the `Box`, returning a wrapped `NonNull` pointer.
@@ -1322,6 +1216,115 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
13221216
// SAFETY: `Box` is guaranteed to be non-null.
13231217
unsafe { NonNull::new_unchecked(Self::into_raw(b)) }
13241218
}
1219+
}
1220+
1221+
impl<T: ?Sized, A: Allocator> Box<T, A> {
1222+
/// Constructs a box from a raw pointer in the given allocator.
1223+
///
1224+
/// After calling this function, the raw pointer is owned by the
1225+
/// resulting `Box`. Specifically, the `Box` destructor will call
1226+
/// the destructor of `T` and free the allocated memory. For this
1227+
/// to be safe, the memory must have been allocated in accordance
1228+
/// with the [memory layout] used by `Box` .
1229+
///
1230+
/// # Safety
1231+
///
1232+
/// This function is unsafe because improper use may lead to
1233+
/// memory problems. For example, a double-free may occur if the
1234+
/// function is called twice on the same raw pointer.
1235+
///
1236+
/// The raw pointer must point to a block of memory allocated by `alloc`.
1237+
///
1238+
/// # Examples
1239+
///
1240+
/// Recreate a `Box` which was previously converted to a raw pointer
1241+
/// using [`Box::into_raw_with_allocator`]:
1242+
/// ```
1243+
/// #![feature(allocator_api)]
1244+
///
1245+
/// use std::alloc::System;
1246+
///
1247+
/// let x = Box::new_in(5, System);
1248+
/// let (ptr, alloc) = Box::into_raw_with_allocator(x);
1249+
/// let x = unsafe { Box::from_raw_in(ptr, alloc) };
1250+
/// ```
1251+
/// Manually create a `Box` from scratch by using the system allocator:
1252+
/// ```
1253+
/// #![feature(allocator_api, slice_ptr_get)]
1254+
///
1255+
/// use std::alloc::{Allocator, Layout, System};
1256+
///
1257+
/// unsafe {
1258+
/// let ptr = System.allocate(Layout::new::<i32>())?.as_mut_ptr() as *mut i32;
1259+
/// // In general .write is required to avoid attempting to destruct
1260+
/// // the (uninitialized) previous contents of `ptr`, though for this
1261+
/// // simple example `*ptr = 5` would have worked as well.
1262+
/// ptr.write(5);
1263+
/// let x = Box::from_raw_in(ptr, System);
1264+
/// }
1265+
/// # Ok::<(), std::alloc::AllocError>(())
1266+
/// ```
1267+
///
1268+
/// [memory layout]: self#memory-layout
1269+
#[unstable(feature = "allocator_api", issue = "32838")]
1270+
#[inline]
1271+
pub unsafe fn from_raw_in(raw: *mut T, alloc: A) -> Self {
1272+
Box(unsafe { Unique::new_unchecked(raw) }, alloc)
1273+
}
1274+
1275+
/// Constructs a box from a `NonNull` pointer in the given allocator.
1276+
///
1277+
/// After calling this function, the `NonNull` pointer is owned by
1278+
/// the resulting `Box`. Specifically, the `Box` destructor will call
1279+
/// the destructor of `T` and free the allocated memory. For this
1280+
/// to be safe, the memory must have been allocated in accordance
1281+
/// with the [memory layout] used by `Box` .
1282+
///
1283+
/// # Safety
1284+
///
1285+
/// This function is unsafe because improper use may lead to
1286+
/// memory problems. For example, a double-free may occur if the
1287+
/// function is called twice on the same raw pointer.
1288+
///
1289+
/// The non-null pointer must point to a block of memory allocated by `alloc`.
1290+
///
1291+
/// # Examples
1292+
///
1293+
/// Recreate a `Box` which was previously converted to a `NonNull` pointer
1294+
/// using [`Box::into_non_null_with_allocator`]:
1295+
/// ```
1296+
/// #![feature(allocator_api, box_vec_non_null)]
1297+
///
1298+
/// use std::alloc::System;
1299+
///
1300+
/// let x = Box::new_in(5, System);
1301+
/// let (non_null, alloc) = Box::into_non_null_with_allocator(x);
1302+
/// let x = unsafe { Box::from_non_null_in(non_null, alloc) };
1303+
/// ```
1304+
/// Manually create a `Box` from scratch by using the system allocator:
1305+
/// ```
1306+
/// #![feature(allocator_api, box_vec_non_null, slice_ptr_get)]
1307+
///
1308+
/// use std::alloc::{Allocator, Layout, System};
1309+
///
1310+
/// unsafe {
1311+
/// let non_null = System.allocate(Layout::new::<i32>())?.cast::<i32>();
1312+
/// // In general .write is required to avoid attempting to destruct
1313+
/// // the (uninitialized) previous contents of `non_null`.
1314+
/// non_null.write(5);
1315+
/// let x = Box::from_non_null_in(non_null, System);
1316+
/// }
1317+
/// # Ok::<(), std::alloc::AllocError>(())
1318+
/// ```
1319+
///
1320+
/// [memory layout]: self#memory-layout
1321+
#[unstable(feature = "allocator_api", issue = "32838")]
1322+
// #[unstable(feature = "box_vec_non_null", reason = "new API", issue = "130364")]
1323+
#[inline]
1324+
pub unsafe fn from_non_null_in(raw: NonNull<T>, alloc: A) -> Self {
1325+
// SAFETY: guaranteed by the caller.
1326+
unsafe { Box::from_raw_in(raw.as_ptr(), alloc) }
1327+
}
13251328

13261329
/// Consumes the `Box`, returning a wrapped raw pointer and the allocator.
13271330
///
@@ -1602,7 +1605,9 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
16021605
where
16031606
A: 'a,
16041607
{
1605-
unsafe { &mut *Box::into_raw(b) }
1608+
let (ptr, alloc) = Box::into_raw_with_allocator(b);
1609+
mem::forget(alloc);
1610+
unsafe { &mut *ptr }
16061611
}
16071612

16081613
/// Converts a `Box<T>` into a `Pin<Box<T>>`. If `T` does not implement [`Unpin`], then
@@ -2127,6 +2132,3 @@ impl<E: Error> Error for Box<E> {
21272132
Error::provide(&**self, request);
21282133
}
21292134
}
2130-
2131-
#[unstable(feature = "pointer_like_trait", issue = "none")]
2132-
impl<T> PointerLike for Box<T> {}

library/alloc/src/collections/linked_list.rs

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ impl<T, A: Allocator> LinkedList<T, A> {
10311031

10321032
/// Retains only the elements specified by the predicate.
10331033
///
1034-
/// In other words, remove all elements `e` for which `f(&e)` returns false.
1034+
/// In other words, remove all elements `e` for which `f(&mut e)` returns false.
10351035
/// This method operates in place, visiting each element exactly once in the
10361036
/// original order, and preserves the order of the retained elements.
10371037
///
@@ -1047,7 +1047,7 @@ impl<T, A: Allocator> LinkedList<T, A> {
10471047
/// d.push_front(2);
10481048
/// d.push_front(3);
10491049
///
1050-
/// d.retain(|&x| x % 2 == 0);
1050+
/// d.retain(|&mut x| x % 2 == 0);
10511051
///
10521052
/// assert_eq!(d.pop_front(), Some(2));
10531053
/// assert_eq!(d.pop_front(), None);
@@ -1074,41 +1074,6 @@ impl<T, A: Allocator> LinkedList<T, A> {
10741074
/// ```
10751075
#[unstable(feature = "linked_list_retain", issue = "114135")]
10761076
pub fn retain<F>(&mut self, mut f: F)
1077-
where
1078-
F: FnMut(&T) -> bool,
1079-
{
1080-
self.retain_mut(|elem| f(elem));
1081-
}
1082-
1083-
/// Retains only the elements specified by the predicate.
1084-
///
1085-
/// In other words, remove all elements `e` for which `f(&mut e)` returns false.
1086-
/// This method operates in place, visiting each element exactly once in the
1087-
/// original order, and preserves the order of the retained elements.
1088-
///
1089-
/// # Examples
1090-
///
1091-
/// ```
1092-
/// #![feature(linked_list_retain)]
1093-
/// use std::collections::LinkedList;
1094-
///
1095-
/// let mut d = LinkedList::new();
1096-
///
1097-
/// d.push_front(1);
1098-
/// d.push_front(2);
1099-
/// d.push_front(3);
1100-
///
1101-
/// d.retain_mut(|x| if *x % 2 == 0 {
1102-
/// *x += 1;
1103-
/// true
1104-
/// } else {
1105-
/// false
1106-
/// });
1107-
/// assert_eq!(d.pop_front(), Some(3));
1108-
/// assert_eq!(d.pop_front(), None);
1109-
/// ```
1110-
#[unstable(feature = "linked_list_retain", issue = "114135")]
1111-
pub fn retain_mut<F>(&mut self, mut f: F)
11121077
where
11131078
F: FnMut(&mut T) -> bool,
11141079
{

library/alloc/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@
108108
#![feature(char_max_len)]
109109
#![feature(clone_to_uninit)]
110110
#![feature(coerce_unsized)]
111+
#![feature(const_default)]
111112
#![feature(const_eval_select)]
112113
#![feature(const_heap)]
114+
#![feature(const_trait_impl)]
113115
#![feature(core_intrinsics)]
114116
#![feature(deprecated_suggestion)]
115117
#![feature(deref_pure_trait)]
@@ -135,7 +137,6 @@
135137
#![feature(panic_internals)]
136138
#![feature(pattern)]
137139
#![feature(pin_coerce_unsized_trait)]
138-
#![feature(pointer_like_trait)]
139140
#![feature(ptr_alignment_type)]
140141
#![feature(ptr_internals)]
141142
#![feature(ptr_metadata)]

0 commit comments

Comments
 (0)