Skip to content

Commit 649567e

Browse files
github-actions[bot]matthiaskrgrborsNobodyXubjorn3
authored
Merge subtree update for toolchain nightly-2025-04-07 (model-checking#329)
This is an automated PR to merge library subtree updates from 2025-04-06 (rust-lang/rust@5e17a2a) to 2025-04-07 (rust-lang/rust@2fa8b11), inclusive. This is a clean merge, no conflicts were detected. **Do not remove or edit the following annotations:** git-subtree-dir: library git-subtree-split: 0b8a1cd --------- Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> Signed-off-by: Ayush Singh <ayush@beagleboard.org> Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn> Co-authored-by: Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> Co-authored-by: bors <bors@rust-lang.org> Co-authored-by: Jiahao XU <Jiahao_XU@outlook.com> Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com> Co-authored-by: Michael Goulet <michael@errs.io> Co-authored-by: The Miri Cronjob Bot <miri@cron.bot> Co-authored-by: Jacob Pratt <jacob@jhpratt.dev> Co-authored-by: Tobias Bucher <tobiasbucher5991@gmail.com> Co-authored-by: León Orell Valerian Liehr <me@fmease.dev> Co-authored-by: Yotam Ofek <yotam.ofek@gmail.com> Co-authored-by: okaneco <47607823+okaneco@users.noreply.github.com> Co-authored-by: 许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com> Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com> Co-authored-by: Ayush Singh <ayush@beagleboard.org> Co-authored-by: Noratrieb <48135649+Noratrieb@users.noreply.github.com> Co-authored-by: Ralf Jung <post@ralfj.de> Co-authored-by: Thalia Archibald <thalia@archibald.dev> Co-authored-by: Marijn Schouten <hkBst@users.noreply.github.com> Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca> Co-authored-by: Berrysoft <Strawberry_Str@hotmail.com> Co-authored-by: Chris Denton <chris@chrisdenton.dev> Co-authored-by: Taiki Endo <te316e89@gmail.com> Co-authored-by: Andrei Damian <andreidaamian@gmail.com> Co-authored-by: bendn <bend.n@outlook.com> Co-authored-by: Caleb Zulawski <caleb.zulawski@gmail.com> Co-authored-by: Mara Bos <m-ou.se@m-ou.se> Co-authored-by: Scott McMurray <scottmcm@users.noreply.github.com> Co-authored-by: Jana Dönszelmann <jana@donsz.nl> Co-authored-by: syvb <me@iter.ca> Co-authored-by: Sebastian Urban <surban@surban.net> Co-authored-by: Bardi Harborow <bardi@bardiharborow.com> Co-authored-by: lcnr <rust@lcnr.de> Co-authored-by: Trevor Gross <tmgross@umich.edu> Co-authored-by: moxian <moxian@users.noreply.github.com> Co-authored-by: Frank King <frankking1729@gmail.com> Co-authored-by: joboet <jonasboettiger@icloud.com> Co-authored-by: Takayuki Maeda <takoyaki0316@gmail.com> Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Co-authored-by: Mads Marquart <mads@marquart.dk> Co-authored-by: Christopher Durham <cad97@cad97.com> Co-authored-by: Rafael Bachmann <rafael.bachmann.93@gmail.com> Co-authored-by: xizheyin <xizheyin@smail.nju.edu.cn> Co-authored-by: Benoît du Garreau <benoit@dugarreau.fr> Co-authored-by: Nikolai Kuklin <nickkuklin@gmail.com> Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com> Co-authored-by: mejrs <59372212+mejrs@users.noreply.github.com> Co-authored-by: clubby789 <jamie@hill-daniel.co.uk> Co-authored-by: Daniel Bloom <daniel@wormholelabs.xyz> Co-authored-by: Jake Wharton <jw@squareup.com> Co-authored-by: Kornel <kornel@geekhood.net> Co-authored-by: Calder Coalson <caldercoalson@gmail.com> Co-authored-by: Stuart Cook <Zalathar@users.noreply.github.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: gitbot <git@bot> Co-authored-by: Michael Tautschnig <tautschn@amazon.com>
1 parent 3b80a4c commit 649567e

File tree

13 files changed

+281
-93
lines changed

13 files changed

+281
-93
lines changed

library/Cargo.lock

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

library/core/src/fmt/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3017,6 +3017,6 @@ impl<T: ?Sized> Debug for SyncUnsafeCell<T> {
30173017
}
30183018
}
30193019

3020-
// If you expected tests to be here, look instead at the core/tests/fmt.rs file,
3020+
// If you expected tests to be here, look instead at coretests/tests/fmt/;
30213021
// it's a lot easier than creating all of the rt::Piece structures here.
3022-
// There are also tests in the alloc crate, for those that need allocations.
3022+
// There are also tests in alloctests/tests/fmt.rs, for those that need allocations.

library/core/src/slice/iter.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,14 +1432,16 @@ impl<'a, T> Iterator for Windows<'a, T> {
14321432

14331433
#[inline]
14341434
fn nth(&mut self, n: usize) -> Option<Self::Item> {
1435-
let (end, overflow) = self.size.get().overflowing_add(n);
1436-
if end > self.v.len() || overflow {
1437-
self.v = &[];
1438-
None
1439-
} else {
1440-
let nth = &self.v[n..end];
1441-
self.v = &self.v[n + 1..];
1435+
let size = self.size.get();
1436+
if let Some(rest) = self.v.get(n..)
1437+
&& let Some(nth) = rest.get(..size)
1438+
{
1439+
self.v = &rest[1..];
14421440
Some(nth)
1441+
} else {
1442+
// setting length to 0 is cheaper than overwriting the pointer when assigning &[]
1443+
self.v = &self.v[..0]; // cheaper than &[]
1444+
None
14431445
}
14441446
}
14451447

@@ -1479,7 +1481,7 @@ impl<'a, T> DoubleEndedIterator for Windows<'a, T> {
14791481
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
14801482
let (end, overflow) = self.v.len().overflowing_sub(n);
14811483
if end < self.size.get() || overflow {
1482-
self.v = &[];
1484+
self.v = &self.v[..0]; // cheaper than &[]
14831485
None
14841486
} else {
14851487
let ret = &self.v[end - self.size.get()..end];
@@ -1588,17 +1590,15 @@ impl<'a, T> Iterator for Chunks<'a, T> {
15881590
#[inline]
15891591
fn nth(&mut self, n: usize) -> Option<Self::Item> {
15901592
let (start, overflow) = n.overflowing_mul(self.chunk_size);
1591-
if start >= self.v.len() || overflow {
1592-
self.v = &[];
1593-
None
1594-
} else {
1595-
let end = match start.checked_add(self.chunk_size) {
1596-
Some(sum) => cmp::min(self.v.len(), sum),
1597-
None => self.v.len(),
1598-
};
1599-
let nth = &self.v[start..end];
1600-
self.v = &self.v[end..];
1593+
// min(len) makes a wrong start harmless, but enables optimizing this to brachless code
1594+
let chunk_start = &self.v[start.min(self.v.len())..];
1595+
let (nth, remainder) = chunk_start.split_at(self.chunk_size.min(chunk_start.len()));
1596+
if !overflow && start < self.v.len() {
1597+
self.v = remainder;
16011598
Some(nth)
1599+
} else {
1600+
self.v = &self.v[..0]; // cheaper than &[]
1601+
None
16021602
}
16031603
}
16041604

@@ -1661,7 +1661,7 @@ impl<'a, T> DoubleEndedIterator for Chunks<'a, T> {
16611661
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
16621662
let len = self.len();
16631663
if n >= len {
1664-
self.v = &[];
1664+
self.v = &self.v[..0]; // cheaper than &[]
16651665
None
16661666
} else {
16671667
let start = (len - 1 - n) * self.chunk_size;
@@ -1985,7 +1985,7 @@ impl<'a, T> Iterator for ChunksExact<'a, T> {
19851985
fn nth(&mut self, n: usize) -> Option<Self::Item> {
19861986
let (start, overflow) = n.overflowing_mul(self.chunk_size);
19871987
if start >= self.v.len() || overflow {
1988-
self.v = &[];
1988+
self.v = &self.v[..0]; // cheaper than &[]
19891989
None
19901990
} else {
19911991
let (_, snd) = self.v.split_at(start);
@@ -2023,7 +2023,7 @@ impl<'a, T> DoubleEndedIterator for ChunksExact<'a, T> {
20232023
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
20242024
let len = self.len();
20252025
if n >= len {
2026-
self.v = &[];
2026+
self.v = &self.v[..0]; // cheaper than &[]
20272027
None
20282028
} else {
20292029
let start = (len - 1 - n) * self.chunk_size;
@@ -2690,7 +2690,7 @@ impl<'a, T> Iterator for RChunks<'a, T> {
26902690
fn nth(&mut self, n: usize) -> Option<Self::Item> {
26912691
let (end, overflow) = n.overflowing_mul(self.chunk_size);
26922692
if end >= self.v.len() || overflow {
2693-
self.v = &[];
2693+
self.v = &self.v[..0]; // cheaper than &[]
26942694
None
26952695
} else {
26962696
// Can't underflow because of the check above
@@ -2747,7 +2747,7 @@ impl<'a, T> DoubleEndedIterator for RChunks<'a, T> {
27472747
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
27482748
let len = self.len();
27492749
if n >= len {
2750-
self.v = &[];
2750+
self.v = &self.v[..0]; // cheaper than &[]
27512751
None
27522752
} else {
27532753
// can't underflow because `n < len`
@@ -3075,7 +3075,7 @@ impl<'a, T> Iterator for RChunksExact<'a, T> {
30753075
fn nth(&mut self, n: usize) -> Option<Self::Item> {
30763076
let (end, overflow) = n.overflowing_mul(self.chunk_size);
30773077
if end >= self.v.len() || overflow {
3078-
self.v = &[];
3078+
self.v = &self.v[..0]; // cheaper than &[]
30793079
None
30803080
} else {
30813081
let (fst, _) = self.v.split_at(self.v.len() - end);
@@ -3114,7 +3114,7 @@ impl<'a, T> DoubleEndedIterator for RChunksExact<'a, T> {
31143114
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
31153115
let len = self.len();
31163116
if n >= len {
3117-
self.v = &[];
3117+
self.v = &self.v[..0]; // cheaper than &[]
31183118
None
31193119
} else {
31203120
// now that we know that `n` corresponds to a chunk,

library/core/src/slice/mod.rs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
use crate::cmp::Ordering::{self, Equal, Greater, Less};
1010
use crate::intrinsics::{exact_div, unchecked_sub};
11-
use crate::mem::{self, SizedTypeProperties};
11+
use crate::mem::{self, MaybeUninit, SizedTypeProperties};
1212
use crate::num::NonZero;
1313
use crate::ops::{OneSidedRange, OneSidedRangeBound, Range, RangeBounds, RangeInclusive};
1414
use crate::panic::const_panic;
@@ -4579,7 +4579,7 @@ impl<T> [T] {
45794579
// or generate worse code otherwise. This is also why we need to go
45804580
// through a raw pointer here.
45814581
let slice: *mut [T] = self;
4582-
let mut arr: mem::MaybeUninit<[&mut I::Output; N]> = mem::MaybeUninit::uninit();
4582+
let mut arr: MaybeUninit<[&mut I::Output; N]> = MaybeUninit::uninit();
45834583
let arr_ptr = arr.as_mut_ptr();
45844584

45854585
// SAFETY: We expect `indices` to contain disjunct values that are
@@ -4764,6 +4764,55 @@ impl<T> [T] {
47644764
}
47654765
}
47664766

4767+
impl<T> [MaybeUninit<T>] {
4768+
/// Transmutes the mutable uninitialized slice to a mutable uninitialized slice of
4769+
/// another type, ensuring alignment of the types is maintained.
4770+
///
4771+
/// This is a safe wrapper around [`slice::align_to_mut`], so inherits the same
4772+
/// guarantees as that method.
4773+
///
4774+
/// # Examples
4775+
///
4776+
/// ```
4777+
/// #![feature(align_to_uninit_mut)]
4778+
/// use std::mem::MaybeUninit;
4779+
///
4780+
/// pub struct BumpAllocator<'scope> {
4781+
/// memory: &'scope mut [MaybeUninit<u8>],
4782+
/// }
4783+
///
4784+
/// impl<'scope> BumpAllocator<'scope> {
4785+
/// pub fn new(memory: &'scope mut [MaybeUninit<u8>]) -> Self {
4786+
/// Self { memory }
4787+
/// }
4788+
/// pub fn try_alloc_uninit<T>(&mut self) -> Option<&'scope mut MaybeUninit<T>> {
4789+
/// let first_end = self.memory.as_ptr().align_offset(align_of::<T>()) + size_of::<T>();
4790+
/// let prefix = self.memory.split_off_mut(..first_end)?;
4791+
/// Some(&mut prefix.align_to_uninit_mut::<T>().1[0])
4792+
/// }
4793+
/// pub fn try_alloc_u32(&mut self, value: u32) -> Option<&'scope mut u32> {
4794+
/// let uninit = self.try_alloc_uninit()?;
4795+
/// Some(uninit.write(value))
4796+
/// }
4797+
/// }
4798+
///
4799+
/// let mut memory = [MaybeUninit::<u8>::uninit(); 10];
4800+
/// let mut allocator = BumpAllocator::new(&mut memory);
4801+
/// let v = allocator.try_alloc_u32(42);
4802+
/// assert_eq!(v, Some(&mut 42));
4803+
/// ```
4804+
#[unstable(feature = "align_to_uninit_mut", issue = "139062")]
4805+
#[inline]
4806+
#[must_use]
4807+
pub fn align_to_uninit_mut<U>(&mut self) -> (&mut Self, &mut [MaybeUninit<U>], &mut Self) {
4808+
// SAFETY: `MaybeUninit` is transparent. Correct size and alignment are guaranteed by
4809+
// `align_to_mut` itself. Therefore the only thing that we have to ensure for a safe
4810+
// `transmute` is that the values are valid for the types involved. But for `MaybeUninit`
4811+
// any values are valid, so this operation is safe.
4812+
unsafe { self.align_to_mut() }
4813+
}
4814+
}
4815+
47674816
impl<T, const N: usize> [[T; N]] {
47684817
/// Takes a `&[[T; N]]`, and flattens it to a `&[T]`.
47694818
///

library/core/src/str/lossy.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -310,25 +310,27 @@ impl fmt::Debug for Utf8Chunks<'_> {
310310
pub mod verify {
311311
use super::*;
312312

313-
#[kani::proof]
314-
pub fn check_next() {
315-
if kani::any() {
316-
// TODO: ARR_SIZE can be `std::usize::MAX` with cbmc argument
317-
// `--arrays-uf-always`
318-
const ARR_SIZE: usize = 1000;
319-
let mut x: [u8; ARR_SIZE] = kani::any();
320-
let mut xs = kani::slice::any_slice_of_array_mut(&mut x);
321-
let mut chunks = xs.utf8_chunks();
322-
unsafe {
323-
chunks.next();
324-
}
325-
} else {
326-
let ptr = kani::any_where::<usize, _>(|val| *val != 0) as *const u8;
327-
kani::assume(ptr.is_aligned());
328-
unsafe {
329-
let mut chunks = crate::slice::from_raw_parts(ptr, 0).utf8_chunks();
330-
chunks.next();
331-
}
332-
}
333-
}
313+
// TODO: This proof became too slow with the toolchain update to 2025-04-07 for reasons yet to
314+
// be understood
315+
// #[kani::proof]
316+
// pub fn check_next() {
317+
// if kani::any() {
318+
// // TODO: ARR_SIZE can be `std::usize::MAX` with cbmc argument
319+
// // `--arrays-uf-always`
320+
// const ARR_SIZE: usize = 1000;
321+
// let mut x: [u8; ARR_SIZE] = kani::any();
322+
// let mut xs = kani::slice::any_slice_of_array_mut(&mut x);
323+
// let mut chunks = xs.utf8_chunks();
324+
// unsafe {
325+
// chunks.next();
326+
// }
327+
// } else {
328+
// let ptr = kani::any_where::<usize, _>(|val| *val != 0) as *const u8;
329+
// kani::assume(ptr.is_aligned());
330+
// unsafe {
331+
// let mut chunks = crate::slice::from_raw_parts(ptr, 0).utf8_chunks();
332+
// chunks.next();
333+
// }
334+
// }
335+
// }
334336
}

library/coretests/tests/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// All `str` tests live in library/alloc/tests/str.rs
1+
// All `str` tests live in library/alloctests/tests/str.rs

library/proc_macro/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ std = { path = "../std" }
99
# `core` when resolving doc links. Without this line a different `core` will be
1010
# loaded from sysroot causing duplicate lang items and other similar errors.
1111
core = { path = "../core" }
12+
rustc-literal-escaper = { version = "0.0.2", features = ["rustc-dep-of-std"] }

0 commit comments

Comments
 (0)