Skip to content

Commit 7cb376a

Browse files
author
The Miri Cronjob Bot
committed
Merge ref '125ff8a788c5' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh. Upstream ref: 125ff8a Filtered ref: bcbe2eb9c674ba7e35befb4557f33a1956964256 This merge was created using https://github.com/rust-lang/josh-sync.
2 parents 78be8dc + 9bcee26 commit 7cb376a

File tree

17 files changed

+541
-134
lines changed

17 files changed

+541
-134
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,3 @@ rustflags = ["-Cpanic=abort"]
5959
rustc-std-workspace-core = { path = 'rustc-std-workspace-core' }
6060
rustc-std-workspace-alloc = { path = 'rustc-std-workspace-alloc' }
6161
rustc-std-workspace-std = { path = 'rustc-std-workspace-std' }
62-
compiler_builtins = { path = "compiler-builtins/compiler-builtins" }

alloc/src/alloc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ unsafe extern "Rust" {
1717
#[rustc_allocator]
1818
#[rustc_nounwind]
1919
#[rustc_std_internal_symbol]
20+
#[rustc_allocator_zeroed_variant = "__rust_alloc_zeroed"]
2021
fn __rust_alloc(size: usize, align: usize) -> *mut u8;
2122
#[rustc_deallocator]
2223
#[rustc_nounwind]

core/src/cmp.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,9 @@ pub fn min<T: Ord>(v1: T, v2: T) -> T {
15541554
///
15551555
/// Returns the first argument if the comparison determines them to be equal.
15561556
///
1557+
/// The parameter order is preserved when calling the `compare` function, i.e. `v1` is
1558+
/// always passed as the first argument and `v2` as the second.
1559+
///
15571560
/// # Examples
15581561
///
15591562
/// ```
@@ -1574,7 +1577,7 @@ pub fn min<T: Ord>(v1: T, v2: T) -> T {
15741577
#[must_use]
15751578
#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
15761579
pub fn min_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
1577-
if compare(&v2, &v1).is_lt() { v2 } else { v1 }
1580+
if compare(&v1, &v2).is_le() { v1 } else { v2 }
15781581
}
15791582

15801583
/// Returns the element that gives the minimum value from the specified function.
@@ -1646,6 +1649,9 @@ pub fn max<T: Ord>(v1: T, v2: T) -> T {
16461649
///
16471650
/// Returns the second argument if the comparison determines them to be equal.
16481651
///
1652+
/// The parameter order is preserved when calling the `compare` function, i.e. `v1` is
1653+
/// always passed as the first argument and `v2` as the second.
1654+
///
16491655
/// # Examples
16501656
///
16511657
/// ```
@@ -1666,7 +1672,7 @@ pub fn max<T: Ord>(v1: T, v2: T) -> T {
16661672
#[must_use]
16671673
#[stable(feature = "cmp_min_max_by", since = "1.53.0")]
16681674
pub fn max_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
1669-
if compare(&v2, &v1).is_lt() { v1 } else { v2 }
1675+
if compare(&v1, &v2).is_gt() { v1 } else { v2 }
16701676
}
16711677

16721678
/// Returns the element that gives the maximum value from the specified function.
@@ -1745,6 +1751,9 @@ where
17451751
///
17461752
/// Returns `[v1, v2]` if the comparison determines them to be equal.
17471753
///
1754+
/// The parameter order is preserved when calling the `compare` function, i.e. `v1` is
1755+
/// always passed as the first argument and `v2` as the second.
1756+
///
17481757
/// # Examples
17491758
///
17501759
/// ```
@@ -1769,7 +1778,7 @@ pub fn minmax_by<T, F>(v1: T, v2: T, compare: F) -> [T; 2]
17691778
where
17701779
F: FnOnce(&T, &T) -> Ordering,
17711780
{
1772-
if compare(&v2, &v1).is_lt() { [v2, v1] } else { [v1, v2] }
1781+
if compare(&v1, &v2).is_le() { [v1, v2] } else { [v2, v1] }
17731782
}
17741783

17751784
/// Returns minimum and maximum values with respect to the specified key function.

core/src/intrinsics/mod.rs

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -261,53 +261,72 @@ pub unsafe fn atomic_fence<const ORD: AtomicOrdering>();
261261
pub unsafe fn atomic_singlethreadfence<const ORD: AtomicOrdering>();
262262

263263
/// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
264-
/// if supported; otherwise, it is a no-op.
264+
/// for the given address if supported; otherwise, it is a no-op.
265265
/// Prefetches have no effect on the behavior of the program but can change its performance
266266
/// characteristics.
267267
///
268-
/// The `locality` argument must be a constant integer and is a temporal locality specifier
269-
/// ranging from (0) - no locality, to (3) - extremely local keep in cache.
268+
/// The `LOCALITY` argument is a temporal locality specifier ranging from (0) - no locality,
269+
/// to (3) - extremely local keep in cache.
270270
///
271271
/// This intrinsic does not have a stable counterpart.
272272
#[rustc_intrinsic]
273273
#[rustc_nounwind]
274-
pub unsafe fn prefetch_read_data<T>(data: *const T, locality: i32);
274+
#[miri::intrinsic_fallback_is_spec]
275+
pub const fn prefetch_read_data<T, const LOCALITY: i32>(data: *const T) {
276+
// This operation is a no-op, unless it is overridden by the backend.
277+
let _ = data;
278+
}
279+
275280
/// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
276-
/// if supported; otherwise, it is a no-op.
281+
/// for the given address if supported; otherwise, it is a no-op.
277282
/// Prefetches have no effect on the behavior of the program but can change its performance
278283
/// characteristics.
279284
///
280-
/// The `locality` argument must be a constant integer and is a temporal locality specifier
281-
/// ranging from (0) - no locality, to (3) - extremely local keep in cache.
285+
/// The `LOCALITY` argument is a temporal locality specifier ranging from (0) - no locality,
286+
/// to (3) - extremely local keep in cache.
282287
///
283288
/// This intrinsic does not have a stable counterpart.
284289
#[rustc_intrinsic]
285290
#[rustc_nounwind]
286-
pub unsafe fn prefetch_write_data<T>(data: *const T, locality: i32);
291+
#[miri::intrinsic_fallback_is_spec]
292+
pub const fn prefetch_write_data<T, const LOCALITY: i32>(data: *const T) {
293+
// This operation is a no-op, unless it is overridden by the backend.
294+
let _ = data;
295+
}
296+
287297
/// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
288-
/// if supported; otherwise, it is a no-op.
298+
/// for the given address if supported; otherwise, it is a no-op.
289299
/// Prefetches have no effect on the behavior of the program but can change its performance
290300
/// characteristics.
291301
///
292-
/// The `locality` argument must be a constant integer and is a temporal locality specifier
293-
/// ranging from (0) - no locality, to (3) - extremely local keep in cache.
302+
/// The `LOCALITY` argument is a temporal locality specifier ranging from (0) - no locality,
303+
/// to (3) - extremely local keep in cache.
294304
///
295305
/// This intrinsic does not have a stable counterpart.
296306
#[rustc_intrinsic]
297307
#[rustc_nounwind]
298-
pub unsafe fn prefetch_read_instruction<T>(data: *const T, locality: i32);
308+
#[miri::intrinsic_fallback_is_spec]
309+
pub const fn prefetch_read_instruction<T, const LOCALITY: i32>(data: *const T) {
310+
// This operation is a no-op, unless it is overridden by the backend.
311+
let _ = data;
312+
}
313+
299314
/// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
300-
/// if supported; otherwise, it is a no-op.
315+
/// for the given address if supported; otherwise, it is a no-op.
301316
/// Prefetches have no effect on the behavior of the program but can change its performance
302317
/// characteristics.
303318
///
304-
/// The `locality` argument must be a constant integer and is a temporal locality specifier
305-
/// ranging from (0) - no locality, to (3) - extremely local keep in cache.
319+
/// The `LOCALITY` argument is a temporal locality specifier ranging from (0) - no locality,
320+
/// to (3) - extremely local keep in cache.
306321
///
307322
/// This intrinsic does not have a stable counterpart.
308323
#[rustc_intrinsic]
309324
#[rustc_nounwind]
310-
pub unsafe fn prefetch_write_instruction<T>(data: *const T, locality: i32);
325+
#[miri::intrinsic_fallback_is_spec]
326+
pub const fn prefetch_write_instruction<T, const LOCALITY: i32>(data: *const T) {
327+
// This operation is a no-op, unless it is overridden by the backend.
328+
let _ = data;
329+
}
311330

312331
/// Executes a breakpoint trap, for inspection by a debugger.
313332
///

core/src/num/int_macros.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,48 @@ macro_rules! int_impl {
209209
self & self.wrapping_neg()
210210
}
211211

212+
/// Returns the index of the highest bit set to one in `self`, or `None`
213+
/// if `self` is `0`.
214+
///
215+
/// # Examples
216+
///
217+
/// ```
218+
/// #![feature(int_lowest_highest_one)]
219+
///
220+
#[doc = concat!("assert_eq!(0x0_", stringify!($SelfT), ".highest_one(), None);")]
221+
#[doc = concat!("assert_eq!(0x1_", stringify!($SelfT), ".highest_one(), Some(0));")]
222+
#[doc = concat!("assert_eq!(0x10_", stringify!($SelfT), ".highest_one(), Some(4));")]
223+
#[doc = concat!("assert_eq!(0x1f_", stringify!($SelfT), ".highest_one(), Some(4));")]
224+
/// ```
225+
#[unstable(feature = "int_lowest_highest_one", issue = "145203")]
226+
#[must_use = "this returns the result of the operation, \
227+
without modifying the original"]
228+
#[inline(always)]
229+
pub const fn highest_one(self) -> Option<u32> {
230+
(self as $UnsignedT).highest_one()
231+
}
232+
233+
/// Returns the index of the lowest bit set to one in `self`, or `None`
234+
/// if `self` is `0`.
235+
///
236+
/// # Examples
237+
///
238+
/// ```
239+
/// #![feature(int_lowest_highest_one)]
240+
///
241+
#[doc = concat!("assert_eq!(0x0_", stringify!($SelfT), ".lowest_one(), None);")]
242+
#[doc = concat!("assert_eq!(0x1_", stringify!($SelfT), ".lowest_one(), Some(0));")]
243+
#[doc = concat!("assert_eq!(0x10_", stringify!($SelfT), ".lowest_one(), Some(4));")]
244+
#[doc = concat!("assert_eq!(0x1f_", stringify!($SelfT), ".lowest_one(), Some(0));")]
245+
/// ```
246+
#[unstable(feature = "int_lowest_highest_one", issue = "145203")]
247+
#[must_use = "this returns the result of the operation, \
248+
without modifying the original"]
249+
#[inline(always)]
250+
pub const fn lowest_one(self) -> Option<u32> {
251+
(self as $UnsignedT).lowest_one()
252+
}
253+
212254
/// Returns the bit pattern of `self` reinterpreted as an unsigned integer of the same size.
213255
///
214256
/// This produces the same result as an `as` cast, but ensures that the bit-width remains

core/src/num/nonzero.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,54 @@ macro_rules! nonzero_integer {
681681
unsafe { NonZero::new_unchecked(n) }
682682
}
683683

684+
/// Returns the index of the highest bit set to one in `self`.
685+
///
686+
/// # Examples
687+
///
688+
/// ```
689+
/// #![feature(int_lowest_highest_one)]
690+
///
691+
/// # use core::num::NonZero;
692+
/// # fn main() { test().unwrap(); }
693+
/// # fn test() -> Option<()> {
694+
#[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0x1)?.highest_one(), 0);")]
695+
#[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0x10)?.highest_one(), 4);")]
696+
#[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0x1f)?.highest_one(), 4);")]
697+
/// # Some(())
698+
/// # }
699+
/// ```
700+
#[unstable(feature = "int_lowest_highest_one", issue = "145203")]
701+
#[must_use = "this returns the result of the operation, \
702+
without modifying the original"]
703+
#[inline(always)]
704+
pub const fn highest_one(self) -> u32 {
705+
Self::BITS - 1 - self.leading_zeros()
706+
}
707+
708+
/// Returns the index of the lowest bit set to one in `self`.
709+
///
710+
/// # Examples
711+
///
712+
/// ```
713+
/// #![feature(int_lowest_highest_one)]
714+
///
715+
/// # use core::num::NonZero;
716+
/// # fn main() { test().unwrap(); }
717+
/// # fn test() -> Option<()> {
718+
#[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0x1)?.lowest_one(), 0);")]
719+
#[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0x10)?.lowest_one(), 4);")]
720+
#[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0x1f)?.lowest_one(), 0);")]
721+
/// # Some(())
722+
/// # }
723+
/// ```
724+
#[unstable(feature = "int_lowest_highest_one", issue = "145203")]
725+
#[must_use = "this returns the result of the operation, \
726+
without modifying the original"]
727+
#[inline(always)]
728+
pub const fn lowest_one(self) -> u32 {
729+
self.trailing_zeros()
730+
}
731+
684732
/// Returns the number of ones in the binary representation of `self`.
685733
///
686734
/// # Examples

core/src/num/uint_macros.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,54 @@ macro_rules! uint_impl {
261261
self & self.wrapping_neg()
262262
}
263263

264+
/// Returns the index of the highest bit set to one in `self`, or `None`
265+
/// if `self` is `0`.
266+
///
267+
/// # Examples
268+
///
269+
/// ```
270+
/// #![feature(int_lowest_highest_one)]
271+
///
272+
#[doc = concat!("assert_eq!(0x0_", stringify!($SelfT), ".highest_one(), None);")]
273+
#[doc = concat!("assert_eq!(0x1_", stringify!($SelfT), ".highest_one(), Some(0));")]
274+
#[doc = concat!("assert_eq!(0x10_", stringify!($SelfT), ".highest_one(), Some(4));")]
275+
#[doc = concat!("assert_eq!(0x1f_", stringify!($SelfT), ".highest_one(), Some(4));")]
276+
/// ```
277+
#[unstable(feature = "int_lowest_highest_one", issue = "145203")]
278+
#[must_use = "this returns the result of the operation, \
279+
without modifying the original"]
280+
#[inline(always)]
281+
pub const fn highest_one(self) -> Option<u32> {
282+
match NonZero::new(self) {
283+
Some(v) => Some(v.highest_one()),
284+
None => None,
285+
}
286+
}
287+
288+
/// Returns the index of the lowest bit set to one in `self`, or `None`
289+
/// if `self` is `0`.
290+
///
291+
/// # Examples
292+
///
293+
/// ```
294+
/// #![feature(int_lowest_highest_one)]
295+
///
296+
#[doc = concat!("assert_eq!(0x0_", stringify!($SelfT), ".lowest_one(), None);")]
297+
#[doc = concat!("assert_eq!(0x1_", stringify!($SelfT), ".lowest_one(), Some(0));")]
298+
#[doc = concat!("assert_eq!(0x10_", stringify!($SelfT), ".lowest_one(), Some(4));")]
299+
#[doc = concat!("assert_eq!(0x1f_", stringify!($SelfT), ".lowest_one(), Some(0));")]
300+
/// ```
301+
#[unstable(feature = "int_lowest_highest_one", issue = "145203")]
302+
#[must_use = "this returns the result of the operation, \
303+
without modifying the original"]
304+
#[inline(always)]
305+
pub const fn lowest_one(self) -> Option<u32> {
306+
match NonZero::new(self) {
307+
Some(v) => Some(v.lowest_one()),
308+
None => None,
309+
}
310+
}
311+
264312
/// Returns the bit pattern of `self` reinterpreted as a signed integer of the same size.
265313
///
266314
/// This produces the same result as an `as` cast, but ensures that the bit-width remains

coretests/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#![feature(generic_assert_internals)]
5555
#![feature(hasher_prefixfree_extras)]
5656
#![feature(hashmap_internals)]
57+
#![feature(int_lowest_highest_one)]
5758
#![feature(int_roundings)]
5859
#![feature(ip)]
5960
#![feature(is_ascii_octdigit)]

0 commit comments

Comments
 (0)