Skip to content

Commit 54bf3e4

Browse files
author
The Miri Cronjob Bot
committed
Merge from rustc
2 parents 308c991 + bf96539 commit 54bf3e4

File tree

73 files changed

+950
-1117
lines changed

Some content is hidden

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

73 files changed

+950
-1117
lines changed

Cargo.lock

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

alloc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repository = "https://github.com/rust-lang/rust.git"
88
description = "The Rust core allocation and collections library"
99
autotests = false
1010
autobenches = false
11-
edition = "2021"
11+
edition = "2024"
1212

1313
[lib]
1414
test = false

alloc/src/boxed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ pub struct Box<
239239
/// This is the surface syntax for `box <expr>` expressions.
240240
#[rustc_intrinsic]
241241
#[unstable(feature = "liballoc_internals", issue = "none")]
242-
pub fn box_new<T>(_x: T) -> Box<T>;
242+
pub fn box_new<T>(x: T) -> Box<T>;
243243

244244
impl<T> Box<T> {
245245
/// Allocates memory on the heap and then places `x` into it.

alloc/src/collections/binary_heap/mod.rs

+78-4
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,74 @@ impl<T: Ord, A: Allocator> DerefMut for PeekMut<'_, T, A> {
361361
}
362362

363363
impl<'a, T: Ord, A: Allocator> PeekMut<'a, T, A> {
364+
/// Sifts the current element to its new position.
365+
///
366+
/// Afterwards refers to the new element. Returns if the element changed.
367+
///
368+
/// ## Examples
369+
///
370+
/// The condition can be used to upper bound all elements in the heap. When only few elements
371+
/// are affected, the heap's sort ensures this is faster than a reconstruction from the raw
372+
/// element list and requires no additional allocation.
373+
///
374+
/// ```
375+
/// #![feature(binary_heap_peek_mut_refresh)]
376+
/// use std::collections::BinaryHeap;
377+
///
378+
/// let mut heap: BinaryHeap<u32> = (0..128).collect();
379+
/// let mut peek = heap.peek_mut().unwrap();
380+
///
381+
/// loop {
382+
/// *peek = 99;
383+
///
384+
/// if !peek.refresh() {
385+
/// break;
386+
/// }
387+
/// }
388+
///
389+
/// // Post condition, this is now an upper bound.
390+
/// assert!(*peek < 100);
391+
/// ```
392+
///
393+
/// When the element remains the maximum after modification, the peek remains unchanged:
394+
///
395+
/// ```
396+
/// #![feature(binary_heap_peek_mut_refresh)]
397+
/// use std::collections::BinaryHeap;
398+
///
399+
/// let mut heap: BinaryHeap<u32> = [1, 2, 3].into();
400+
/// let mut peek = heap.peek_mut().unwrap();
401+
///
402+
/// assert_eq!(*peek, 3);
403+
/// *peek = 42;
404+
///
405+
/// // When we refresh, the peek is updated to the new maximum.
406+
/// assert!(!peek.refresh(), "42 is even larger than 3");
407+
/// assert_eq!(*peek, 42);
408+
/// ```
409+
#[unstable(feature = "binary_heap_peek_mut_refresh", issue = "138355")]
410+
#[must_use = "is equivalent to dropping and getting a new PeekMut except for return information"]
411+
pub fn refresh(&mut self) -> bool {
412+
// The length of the underlying heap is unchanged by sifting down. The value stored for leak
413+
// amplification thus remains accurate. We erase the leak amplification firstly because the
414+
// operation is then equivalent to constructing a new PeekMut and secondly this avoids any
415+
// future complication where original_len being non-empty would be interpreted as the heap
416+
// having been leak amplified instead of checking the heap itself.
417+
if let Some(original_len) = self.original_len.take() {
418+
// SAFETY: This is how many elements were in the Vec at the time of
419+
// the BinaryHeap::peek_mut call.
420+
unsafe { self.heap.data.set_len(original_len.get()) };
421+
422+
// The length of the heap did not change by sifting, upholding our own invariants.
423+
424+
// SAFETY: PeekMut is only instantiated for non-empty heaps.
425+
(unsafe { self.heap.sift_down(0) }) != 0
426+
} else {
427+
// The element was not modified.
428+
false
429+
}
430+
}
431+
364432
/// Removes the peeked value from the heap and returns it.
365433
#[stable(feature = "binary_heap_peek_mut_pop", since = "1.18.0")]
366434
pub fn pop(mut this: PeekMut<'a, T, A>) -> T {
@@ -672,6 +740,8 @@ impl<T: Ord, A: Allocator> BinaryHeap<T, A> {
672740
/// # Safety
673741
///
674742
/// The caller must guarantee that `pos < self.len()`.
743+
///
744+
/// Returns the new position of the element.
675745
unsafe fn sift_up(&mut self, start: usize, pos: usize) -> usize {
676746
// Take out the value at `pos` and create a hole.
677747
// SAFETY: The caller guarantees that pos < self.len()
@@ -698,10 +768,12 @@ impl<T: Ord, A: Allocator> BinaryHeap<T, A> {
698768
/// Take an element at `pos` and move it down the heap,
699769
/// while its children are larger.
700770
///
771+
/// Returns the new position of the element.
772+
///
701773
/// # Safety
702774
///
703775
/// The caller must guarantee that `pos < end <= self.len()`.
704-
unsafe fn sift_down_range(&mut self, pos: usize, end: usize) {
776+
unsafe fn sift_down_range(&mut self, pos: usize, end: usize) -> usize {
705777
// SAFETY: The caller guarantees that pos < end <= self.len().
706778
let mut hole = unsafe { Hole::new(&mut self.data, pos) };
707779
let mut child = 2 * hole.pos() + 1;
@@ -721,7 +793,7 @@ impl<T: Ord, A: Allocator> BinaryHeap<T, A> {
721793
// SAFETY: child is now either the old child or the old child+1
722794
// We already proven that both are < self.len() and != hole.pos()
723795
if hole.element() >= unsafe { hole.get(child) } {
724-
return;
796+
return hole.pos();
725797
}
726798

727799
// SAFETY: same as above.
@@ -736,16 +808,18 @@ impl<T: Ord, A: Allocator> BinaryHeap<T, A> {
736808
// child == 2 * hole.pos() + 1 != hole.pos().
737809
unsafe { hole.move_to(child) };
738810
}
811+
812+
hole.pos()
739813
}
740814

741815
/// # Safety
742816
///
743817
/// The caller must guarantee that `pos < self.len()`.
744-
unsafe fn sift_down(&mut self, pos: usize) {
818+
unsafe fn sift_down(&mut self, pos: usize) -> usize {
745819
let len = self.len();
746820
// SAFETY: pos < len is guaranteed by the caller and
747821
// obviously len = self.len() <= self.len().
748-
unsafe { self.sift_down_range(pos, len) };
822+
unsafe { self.sift_down_range(pos, len) }
749823
}
750824

751825
/// Take an element at `pos` and move it all the way down the heap,

core/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ autobenches = false
99
# If you update this, be sure to update it in a bunch of other places too!
1010
# As of 2024, it was src/tools/opt-dist, the core-no-fp-fmt-parse test and
1111
# the version of the prelude imported in core/lib.rs.
12-
edition = "2021"
12+
edition = "2024"
1313

1414
[lib]
1515
test = false

core/src/ffi/primitives.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ mod c_char_definition {
133133

134134
mod c_long_definition {
135135
cfg_if! {
136-
if #[cfg(all(target_pointer_width = "64", not(windows)))] {
136+
if #[cfg(any(
137+
all(target_pointer_width = "64", not(windows)),
138+
// wasm32 Linux ABI uses 64-bit long
139+
all(target_arch = "wasm32", target_os = "linux")))] {
137140
pub(super) type c_long = i64;
138141
pub(super) type c_ulong = u64;
139142
} else {

core/src/ffi/va_list.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,15 @@ impl<'f> Drop for VaListImpl<'f> {
306306
/// `va_copy`.
307307
#[rustc_intrinsic]
308308
#[rustc_nounwind]
309-
unsafe fn va_end(_ap: &mut VaListImpl<'_>);
309+
unsafe fn va_end(ap: &mut VaListImpl<'_>);
310310

311311
/// Copies the current location of arglist `src` to the arglist `dst`.
312312
#[rustc_intrinsic]
313313
#[rustc_nounwind]
314-
unsafe fn va_copy<'f>(_dest: *mut VaListImpl<'f>, _src: &VaListImpl<'f>);
314+
unsafe fn va_copy<'f>(dest: *mut VaListImpl<'f>, src: &VaListImpl<'f>);
315315

316316
/// Loads an argument of type `T` from the `va_list` `ap` and increment the
317317
/// argument `ap` points to.
318318
#[rustc_intrinsic]
319319
#[rustc_nounwind]
320-
unsafe fn va_arg<T: sealed_trait::VaArgSafe>(_ap: &mut VaListImpl<'_>) -> T;
320+
unsafe fn va_arg<T: sealed_trait::VaArgSafe>(ap: &mut VaListImpl<'_>) -> T;

core/src/fmt/float.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn float_to_decimal_common_exact<T>(
2929
fmt: &mut Formatter<'_>,
3030
num: &T,
3131
sign: flt2dec::Sign,
32-
precision: usize,
32+
precision: u16,
3333
) -> Result
3434
where
3535
T: flt2dec::DecodableFloat,
@@ -40,7 +40,7 @@ where
4040
flt2dec::strategy::grisu::format_exact,
4141
*num,
4242
sign,
43-
precision,
43+
precision.into(),
4444
&mut buf,
4545
&mut parts,
4646
);
@@ -55,7 +55,7 @@ fn float_to_decimal_common_shortest<T>(
5555
fmt: &mut Formatter<'_>,
5656
num: &T,
5757
sign: flt2dec::Sign,
58-
precision: usize,
58+
precision: u16,
5959
) -> Result
6060
where
6161
T: flt2dec::DecodableFloat,
@@ -68,7 +68,7 @@ where
6868
flt2dec::strategy::grisu::format_shortest,
6969
*num,
7070
sign,
71-
precision,
71+
precision.into(),
7272
&mut buf,
7373
&mut parts,
7474
);
@@ -101,7 +101,7 @@ fn float_to_exponential_common_exact<T>(
101101
fmt: &mut Formatter<'_>,
102102
num: &T,
103103
sign: flt2dec::Sign,
104-
precision: usize,
104+
precision: u16,
105105
upper: bool,
106106
) -> Result
107107
where
@@ -113,7 +113,7 @@ where
113113
flt2dec::strategy::grisu::format_exact,
114114
*num,
115115
sign,
116-
precision,
116+
precision.into(),
117117
upper,
118118
&mut buf,
119119
&mut parts,

0 commit comments

Comments
 (0)