Skip to content

Commit 85fb4c2

Browse files
author
The Miri Cronjob Bot
committed
Merge ref '828e45ad11ce' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh. Upstream ref: 828e45a Filtered ref: 10ab51e1b1b8eadb430163bd78ef39c0721cfbf8 This merge was created using https://github.com/rust-lang/josh-sync.
2 parents a9f5f2c + 6db6210 commit 85fb4c2

File tree

30 files changed

+1090
-367
lines changed

30 files changed

+1090
-367
lines changed

alloc/src/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@
354354
//! sign := '+' | '-'
355355
//! width := count
356356
//! precision := count | '*'
357-
//! type := '?' | 'x?' | 'X?' | identifier
357+
//! type := '?' | 'x?' | 'X?' | 'o' | 'x' | 'X' | 'p' | 'b' | 'e' | 'E'
358358
//! count := parameter | integer
359359
//! parameter := argument '$'
360360
//! ```

compiler-builtins/etc/thumbv7em-none-eabi-renamed.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
},
2020
"panic-strategy": "abort",
2121
"relocation-model": "static",
22-
"target-pointer-width": "32"
22+
"target-pointer-width": 32
2323
}

core/src/array/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,14 @@ pub use iter::IntoIter;
4141
///
4242
/// Creating multiple copies of a `String`:
4343
/// ```rust
44-
/// #![feature(array_repeat)]
45-
///
4644
/// use std::array;
4745
///
4846
/// let string = "Hello there!".to_string();
4947
/// let strings = array::repeat(string);
5048
/// assert_eq!(strings, ["Hello there!", "Hello there!"]);
5149
/// ```
5250
#[inline]
53-
#[unstable(feature = "array_repeat", issue = "126695")]
51+
#[stable(feature = "array_repeat", since = "CURRENT_RUSTC_VERSION")]
5452
pub fn repeat<T: Clone, const N: usize>(val: T) -> [T; N] {
5553
from_trusted_iterator(repeat_n(val, N))
5654
}

core/src/char/methods.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,11 @@ impl char {
950950
#[stable(feature = "rust1", since = "1.0.0")]
951951
#[inline]
952952
pub fn is_control(self) -> bool {
953-
unicode::Cc(self)
953+
// According to
954+
// https://www.unicode.org/policies/stability_policy.html#Property_Value,
955+
// the set of codepoints in `Cc` will never change.
956+
// So we can just hard-code the patterns to match against instead of using a table.
957+
matches!(self, '\0'..='\x1f' | '\x7f'..='\u{9f}')
954958
}
955959

956960
/// Returns `true` if this `char` has the `Grapheme_Extend` property.

core/src/hint.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,12 +776,45 @@ pub fn select_unpredictable<T>(condition: bool, true_val: T, false_val: T) -> T
776776
// Change this to use ManuallyDrop instead.
777777
let mut true_val = MaybeUninit::new(true_val);
778778
let mut false_val = MaybeUninit::new(false_val);
779+
780+
struct DropOnPanic<T> {
781+
// Invariant: valid pointer and points to an initialized value that is not further used,
782+
// i.e. it can be dropped by this guard.
783+
inner: *mut T,
784+
}
785+
786+
impl<T> Drop for DropOnPanic<T> {
787+
fn drop(&mut self) {
788+
// SAFETY: Must be guaranteed on construction of local type `DropOnPanic`.
789+
unsafe { self.inner.drop_in_place() }
790+
}
791+
}
792+
793+
let true_ptr = true_val.as_mut_ptr();
794+
let false_ptr = false_val.as_mut_ptr();
795+
779796
// SAFETY: The value that is not selected is dropped, and the selected one
780797
// is returned. This is necessary because the intrinsic doesn't drop the
781798
// value that is not selected.
782799
unsafe {
783-
crate::intrinsics::select_unpredictable(!condition, &mut true_val, &mut false_val)
784-
.assume_init_drop();
800+
// Extract the selected value first, ensure it is dropped as well if dropping the unselected
801+
// value panics. We construct a temporary by-pointer guard around the selected value while
802+
// dropping the unselected value. Arguments overlap here, so we can not use mutable
803+
// reference for these arguments.
804+
let guard = crate::intrinsics::select_unpredictable(condition, true_ptr, false_ptr);
805+
let drop = crate::intrinsics::select_unpredictable(condition, false_ptr, true_ptr);
806+
807+
// SAFETY: both pointers are well-aligned and point to initialized values inside a
808+
// `MaybeUninit` each. In both possible values for `condition` the pointer `guard` and
809+
// `drop` do not alias (even though the two argument pairs we have selected from did alias
810+
// each other).
811+
let guard = DropOnPanic { inner: guard };
812+
drop.drop_in_place();
813+
crate::mem::forget(guard);
814+
815+
// Note that it is important to use the values here. Reading from the pointer we got makes
816+
// LLVM forget the !unpredictable annotation sometimes (in tests, integer sized values in
817+
// particular seemed to confuse it, also observed in llvm/llvm-project #82340).
785818
crate::intrinsics::select_unpredictable(condition, true_val, false_val).assume_init()
786819
}
787820
}

core/src/num/uint_macros.rs

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,20 @@ macro_rules! uint_impl {
14911491
without modifying the original"]
14921492
#[inline]
14931493
pub const fn checked_ilog(self, base: Self) -> Option<u32> {
1494+
// Inform compiler of optimizations when the base is known at
1495+
// compile time and there's a cheaper method available.
1496+
//
1497+
// Note: Like all optimizations, this is not guaranteed to be
1498+
// applied by the compiler. If you want those specific bases,
1499+
// use `.checked_ilog2()` or `.checked_ilog10()` directly.
1500+
if core::intrinsics::is_val_statically_known(base) {
1501+
if base == 2 {
1502+
return self.checked_ilog2();
1503+
} else if base == 10 {
1504+
return self.checked_ilog10();
1505+
}
1506+
}
1507+
14941508
if self <= 0 || base <= 1 {
14951509
None
14961510
} else if self < base {
@@ -2447,7 +2461,7 @@ macro_rules! uint_impl {
24472461
}
24482462

24492463
/// Calculates `self` + `rhs` + `carry` and returns a tuple containing
2450-
/// the sum and the output carry.
2464+
/// the sum and the output carry (in that order).
24512465
///
24522466
/// Performs "ternary addition" of two integer operands and a carry-in
24532467
/// bit, and returns an output integer and a carry-out bit. This allows
@@ -2465,8 +2479,6 @@ macro_rules! uint_impl {
24652479
/// # Examples
24662480
///
24672481
/// ```
2468-
/// #![feature(bigint_helper_methods)]
2469-
///
24702482
#[doc = concat!("// 3 MAX (a = 3 × 2^", stringify!($BITS), " + 2^", stringify!($BITS), " - 1)")]
24712483
#[doc = concat!("// + 5 7 (b = 5 × 2^", stringify!($BITS), " + 7)")]
24722484
/// // ---------
@@ -2483,7 +2495,7 @@ macro_rules! uint_impl {
24832495
///
24842496
/// assert_eq!((sum1, sum0), (9, 6));
24852497
/// ```
2486-
#[unstable(feature = "bigint_helper_methods", issue = "85532")]
2498+
#[stable(feature = "unsigned_bigint_helpers", since = "CURRENT_RUSTC_VERSION")]
24872499
#[rustc_const_unstable(feature = "bigint_helper_methods", issue = "85532")]
24882500
#[must_use = "this returns the result of the operation, \
24892501
without modifying the original"]
@@ -2559,8 +2571,6 @@ macro_rules! uint_impl {
25592571
/// # Examples
25602572
///
25612573
/// ```
2562-
/// #![feature(bigint_helper_methods)]
2563-
///
25642574
#[doc = concat!("// 9 6 (a = 9 × 2^", stringify!($BITS), " + 6)")]
25652575
#[doc = concat!("// - 5 7 (b = 5 × 2^", stringify!($BITS), " + 7)")]
25662576
/// // ---------
@@ -2577,7 +2587,7 @@ macro_rules! uint_impl {
25772587
///
25782588
#[doc = concat!("assert_eq!((diff1, diff0), (3, ", stringify!($SelfT), "::MAX));")]
25792589
/// ```
2580-
#[unstable(feature = "bigint_helper_methods", issue = "85532")]
2590+
#[stable(feature = "unsigned_bigint_helpers", since = "CURRENT_RUSTC_VERSION")]
25812591
#[rustc_const_unstable(feature = "bigint_helper_methods", issue = "85532")]
25822592
#[must_use = "this returns the result of the operation, \
25832593
without modifying the original"]
@@ -2651,10 +2661,12 @@ macro_rules! uint_impl {
26512661
/// indicating whether an arithmetic overflow would occur. If an
26522662
/// overflow would have occurred then the wrapped value is returned.
26532663
///
2664+
/// If you want the *value* of the overflow, rather than just *whether*
2665+
/// an overflow occurred, see [`Self::carrying_mul`].
2666+
///
26542667
/// # Examples
26552668
///
2656-
/// Please note that this example is shared among integer types, which is why why `u32`
2657-
/// is used.
2669+
/// Please note that this example is shared among integer types, which is why `u32` is used.
26582670
///
26592671
/// ```
26602672
/// assert_eq!(5u32.overflowing_mul(2), (10, false));
@@ -2670,16 +2682,38 @@ macro_rules! uint_impl {
26702682
(a as Self, b)
26712683
}
26722684

2673-
/// Calculates the complete product `self * rhs` without the possibility to overflow.
2685+
/// Calculates the complete double-width product `self * rhs`.
26742686
///
26752687
/// This returns the low-order (wrapping) bits and the high-order (overflow) bits
2676-
/// of the result as two separate values, in that order.
2688+
/// of the result as two separate values, in that order. As such,
2689+
/// `a.widening_mul(b).0` produces the same result as `a.wrapping_mul(b)`.
2690+
///
2691+
/// If you also need to add a value and carry to the wide result, then you want
2692+
/// [`Self::carrying_mul_add`] instead.
26772693
///
26782694
/// If you also need to add a carry to the wide result, then you want
26792695
/// [`Self::carrying_mul`] instead.
26802696
///
2697+
/// If you just want to know *whether* the multiplication overflowed, then you
2698+
/// want [`Self::overflowing_mul`] instead.
2699+
///
26812700
/// # Examples
26822701
///
2702+
/// ```
2703+
/// #![feature(bigint_helper_methods)]
2704+
#[doc = concat!("assert_eq!(5_", stringify!($SelfT), ".widening_mul(7), (35, 0));")]
2705+
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.widening_mul(", stringify!($SelfT), "::MAX), (1, ", stringify!($SelfT), "::MAX - 1));")]
2706+
/// ```
2707+
///
2708+
/// Compared to other `*_mul` methods:
2709+
/// ```
2710+
/// #![feature(bigint_helper_methods)]
2711+
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::widening_mul(1 << ", stringify!($BITS_MINUS_ONE), ", 6), (0, 3));")]
2712+
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::overflowing_mul(1 << ", stringify!($BITS_MINUS_ONE), ", 6), (0, true));")]
2713+
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::wrapping_mul(1 << ", stringify!($BITS_MINUS_ONE), ", 6), 0);")]
2714+
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::checked_mul(1 << ", stringify!($BITS_MINUS_ONE), ", 6), None);")]
2715+
/// ```
2716+
///
26832717
/// Please note that this example is shared among integer types, which is why `u32` is used.
26842718
///
26852719
/// ```
@@ -2706,14 +2740,13 @@ macro_rules! uint_impl {
27062740
/// additional amount of overflow. This allows for chaining together multiple
27072741
/// multiplications to create "big integers" which represent larger values.
27082742
///
2709-
/// If you don't need the `carry`, then you can use [`Self::widening_mul`] instead.
2743+
/// If you also need to add a value, then use [`Self::carrying_mul_add`].
27102744
///
27112745
/// # Examples
27122746
///
27132747
/// Please note that this example is shared among integer types, which is why `u32` is used.
27142748
///
27152749
/// ```
2716-
/// #![feature(bigint_helper_methods)]
27172750
/// assert_eq!(5u32.carrying_mul(2, 0), (10, 0));
27182751
/// assert_eq!(5u32.carrying_mul(2, 10), (20, 0));
27192752
/// assert_eq!(1_000_000_000u32.carrying_mul(10, 0), (1410065408, 2));
@@ -2771,7 +2804,7 @@ macro_rules! uint_impl {
27712804
/// 789_u16.wrapping_mul(456).wrapping_add(123),
27722805
/// );
27732806
/// ```
2774-
#[unstable(feature = "bigint_helper_methods", issue = "85532")]
2807+
#[stable(feature = "unsigned_bigint_helpers", since = "CURRENT_RUSTC_VERSION")]
27752808
#[rustc_const_unstable(feature = "bigint_helper_methods", issue = "85532")]
27762809
#[must_use = "this returns the result of the operation, \
27772810
without modifying the original"]
@@ -2780,26 +2813,27 @@ macro_rules! uint_impl {
27802813
Self::carrying_mul_add(self, rhs, carry, 0)
27812814
}
27822815

2783-
/// Calculates the "full multiplication" `self * rhs + carry1 + carry2`
2784-
/// without the possibility to overflow.
2816+
/// Calculates the "full multiplication" `self * rhs + carry1 + carry2`.
27852817
///
27862818
/// This returns the low-order (wrapping) bits and the high-order (overflow) bits
27872819
/// of the result as two separate values, in that order.
27882820
///
2821+
/// This cannot overflow, as the double-width result has exactly enough
2822+
/// space for the largest possible result. This is equivalent to how, in
2823+
/// decimal, 9 × 9 + 9 + 9 = 81 + 18 = 99 = 9×10⁰ + 9×10¹ = 10² - 1.
2824+
///
27892825
/// Performs "long multiplication" which takes in an extra amount to add, and may return an
27902826
/// additional amount of overflow. This allows for chaining together multiple
27912827
/// multiplications to create "big integers" which represent larger values.
27922828
///
2793-
/// If you don't need either `carry`, then you can use [`Self::widening_mul`] instead,
2794-
/// and if you only need one `carry`, then you can use [`Self::carrying_mul`] instead.
2829+
/// If you don't need the `add` part, then you can use [`Self::carrying_mul`] instead.
27952830
///
27962831
/// # Examples
27972832
///
27982833
/// Please note that this example is shared between integer types,
27992834
/// which explains why `u32` is used here.
28002835
///
28012836
/// ```
2802-
/// #![feature(bigint_helper_methods)]
28032837
/// assert_eq!(5u32.carrying_mul_add(2, 0, 0), (10, 0));
28042838
/// assert_eq!(5u32.carrying_mul_add(2, 10, 10), (30, 0));
28052839
/// assert_eq!(1_000_000_000u32.carrying_mul_add(10, 0, 0), (1410065408, 2));
@@ -2816,8 +2850,6 @@ macro_rules! uint_impl {
28162850
/// using `u8` for simplicity of the demonstration.
28172851
///
28182852
/// ```
2819-
/// #![feature(bigint_helper_methods)]
2820-
///
28212853
/// fn quadratic_mul<const N: usize>(a: [u8; N], b: [u8; N]) -> [u8; N] {
28222854
/// let mut out = [0; N];
28232855
/// for j in 0..N {
@@ -2832,13 +2864,13 @@ macro_rules! uint_impl {
28322864
/// // -1 * -1 == 1
28332865
/// assert_eq!(quadratic_mul([0xFF; 3], [0xFF; 3]), [1, 0, 0]);
28342866
///
2835-
/// assert_eq!(u32::wrapping_mul(0x9e3779b9, 0x7f4a7c15), 0xCFFC982D);
2867+
/// assert_eq!(u32::wrapping_mul(0x9e3779b9, 0x7f4a7c15), 0xcffc982d);
28362868
/// assert_eq!(
28372869
/// quadratic_mul(u32::to_le_bytes(0x9e3779b9), u32::to_le_bytes(0x7f4a7c15)),
2838-
/// u32::to_le_bytes(0xCFFC982D)
2870+
/// u32::to_le_bytes(0xcffc982d)
28392871
/// );
28402872
/// ```
2841-
#[unstable(feature = "bigint_helper_methods", issue = "85532")]
2873+
#[stable(feature = "unsigned_bigint_helpers", since = "CURRENT_RUSTC_VERSION")]
28422874
#[rustc_const_unstable(feature = "bigint_helper_methods", issue = "85532")]
28432875
#[must_use = "this returns the result of the operation, \
28442876
without modifying the original"]

core/src/ptr/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,10 +2166,9 @@ pub unsafe fn write_volatile<T>(dst: *mut T, src: T) {
21662166
}
21672167
}
21682168

2169-
/// Align pointer `p`.
2169+
/// Calculate an element-offset that increases a pointer's alignment.
21702170
///
2171-
/// Calculate offset (in terms of elements of `size_of::<T>()` stride) that has to be applied
2172-
/// to pointer `p` so that pointer `p` would get aligned to `a`.
2171+
/// Calculate an element-offset (not byte-offset) that when added to a given pointer `p`, increases `p`'s alignment to at least the given alignment `a`.
21732172
///
21742173
/// # Safety
21752174
/// `a` must be a power of two.

core/src/time.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,42 @@ impl Duration {
308308
Duration { secs, nanos: subsec_nanos }
309309
}
310310

311+
/// Creates a new `Duration` from the specified number of nanoseconds.
312+
///
313+
/// # Panics
314+
///
315+
/// Panics if the given number of nanoseconds is greater than [`Duration::MAX`].
316+
///
317+
/// # Examples
318+
///
319+
/// ```
320+
/// #![feature(duration_from_nanos_u128)]
321+
/// use std::time::Duration;
322+
///
323+
/// let nanos = 10_u128.pow(24) + 321;
324+
/// let duration = Duration::from_nanos_u128(nanos);
325+
///
326+
/// assert_eq!(10_u64.pow(15), duration.as_secs());
327+
/// assert_eq!(321, duration.subsec_nanos());
328+
/// ```
329+
#[unstable(feature = "duration_from_nanos_u128", issue = "139201")]
330+
// This is necessary because of const `try_from`, but can be removed if a trait-free impl is used instead
331+
#[rustc_const_unstable(feature = "duration_from_nanos_u128", issue = "139201")]
332+
#[must_use]
333+
#[inline]
334+
#[track_caller]
335+
pub const fn from_nanos_u128(nanos: u128) -> Duration {
336+
const NANOS_PER_SEC: u128 = self::NANOS_PER_SEC as u128;
337+
let Ok(secs) = u64::try_from(nanos / NANOS_PER_SEC) else {
338+
panic!("overflow in `Duration::from_nanos_u128`");
339+
};
340+
let subsec_nanos = (nanos % NANOS_PER_SEC) as u32;
341+
// SAFETY: x % 1_000_000_000 < 1_000_000_000 also, subsec_nanos >= 0 since u128 >=0 and u32 >=0
342+
let subsec_nanos = unsafe { Nanoseconds::new_unchecked(subsec_nanos) };
343+
344+
Duration { secs: secs as u64, nanos: subsec_nanos }
345+
}
346+
311347
/// Creates a new `Duration` from the specified number of weeks.
312348
///
313349
/// # Panics

core/src/unicode/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pub use unicode_data::conversions;
1010

1111
#[rustfmt::skip]
1212
pub(crate) use unicode_data::alphabetic::lookup as Alphabetic;
13-
pub(crate) use unicode_data::cc::lookup as Cc;
1413
pub(crate) use unicode_data::grapheme_extend::lookup as Grapheme_Extend;
1514
pub(crate) use unicode_data::lowercase::lookup as Lowercase;
1615
pub(crate) use unicode_data::n::lookup as N;

core/src/unicode/unicode_data.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -358,31 +358,6 @@ pub mod cased {
358358
}
359359
}
360360

361-
#[rustfmt::skip]
362-
pub mod cc {
363-
use super::ShortOffsetRunHeader;
364-
365-
static SHORT_OFFSET_RUNS: [ShortOffsetRunHeader; 1] = [
366-
ShortOffsetRunHeader::new(0, 1114272),
367-
];
368-
static OFFSETS: [u8; 5] = [
369-
0, 32, 95, 33, 0,
370-
];
371-
pub fn lookup(c: char) -> bool {
372-
const {
373-
assert!(SHORT_OFFSET_RUNS.last().unwrap().0 > char::MAX as u32);
374-
let mut i = 0;
375-
while i < SHORT_OFFSET_RUNS.len() {
376-
assert!(SHORT_OFFSET_RUNS[i].start_index() < OFFSETS.len());
377-
i += 1;
378-
}
379-
}
380-
// SAFETY: We just ensured the last element of `SHORT_OFFSET_RUNS` is greater than `std::char::MAX`
381-
// and the start indices of all elements in `SHORT_OFFSET_RUNS` are smaller than `OFFSETS.len()`.
382-
unsafe { super::skip_search(c, &SHORT_OFFSET_RUNS, &OFFSETS) }
383-
}
384-
}
385-
386361
#[rustfmt::skip]
387362
pub mod grapheme_extend {
388363
use super::ShortOffsetRunHeader;

0 commit comments

Comments
 (0)