Skip to content

Commit 32f57ef

Browse files
author
The Miri Cronjob Bot
committed
Merge from rustc
2 parents 6e0b09b + f20c139 commit 32f57ef

26 files changed

+197
-113
lines changed

core/src/alloc/layout.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ impl Layout {
126126
#[rustc_const_stable(feature = "const_alloc_layout_unchecked", since = "1.36.0")]
127127
#[must_use]
128128
#[inline]
129+
#[track_caller]
129130
pub const unsafe fn from_size_align_unchecked(size: usize, align: usize) -> Self {
130131
assert_unsafe_precondition!(
131132
check_library_ub,

core/src/ascii/ascii_char.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ impl AsciiChar {
503503
/// something useful. It might be tightened before stabilization.)
504504
#[unstable(feature = "ascii_char", issue = "110998")]
505505
#[inline]
506+
#[track_caller]
506507
pub const unsafe fn digit_unchecked(d: u8) -> Self {
507508
assert_unsafe_precondition!(
508509
check_language_ub,

core/src/char/convert.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub(super) const fn from_u32(i: u32) -> Option<char> {
2222
#[inline]
2323
#[must_use]
2424
#[allow(unnecessary_transmutes)]
25+
#[track_caller]
2526
pub(super) const unsafe fn from_u32_unchecked(i: u32) -> char {
2627
// SAFETY: the caller must guarantee that `i` is a valid char value.
2728
unsafe {

core/src/hint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ use crate::{intrinsics, ub_checks};
9898
#[inline]
9999
#[stable(feature = "unreachable", since = "1.27.0")]
100100
#[rustc_const_stable(feature = "const_unreachable_unchecked", since = "1.57.0")]
101-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
101+
#[track_caller]
102102
pub const unsafe fn unreachable_unchecked() -> ! {
103103
ub_checks::assert_unsafe_precondition!(
104104
check_language_ub,

core/src/intrinsics/mod.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
//! Compiler intrinsics.
22
//!
3-
//! The corresponding definitions are in <https://github.com/rust-lang/rust/blob/master/compiler/rustc_codegen_llvm/src/intrinsic.rs>.
4-
//! The corresponding const implementations are in <https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs>.
3+
//! These are the imports making intrinsics available to Rust code. The actual implementations live in the compiler.
4+
//! Some of these intrinsics are lowered to MIR in <https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_transform/src/lower_intrinsics.rs>.
5+
//! The remaining intrinsics are implemented for the LLVM backend in <https://github.com/rust-lang/rust/blob/master/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs>
6+
//! and <https://github.com/rust-lang/rust/blob/master/compiler/rustc_codegen_llvm/src/intrinsic.rs>,
7+
//! and for const evaluation in <https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs>.
58
//!
69
//! # Const intrinsics
710
//!
@@ -20,28 +23,14 @@
2023
//!
2124
//! The volatile intrinsics provide operations intended to act on I/O
2225
//! memory, which are guaranteed to not be reordered by the compiler
23-
//! across other volatile intrinsics. See the LLVM documentation on
24-
//! [[volatile]].
25-
//!
26-
//! [volatile]: https://llvm.org/docs/LangRef.html#volatile-memory-accesses
26+
//! across other volatile intrinsics. See [`read_volatile`][ptr::read_volatile]
27+
//! and [`write_volatile`][ptr::write_volatile].
2728
//!
2829
//! # Atomics
2930
//!
3031
//! The atomic intrinsics provide common atomic operations on machine
31-
//! words, with multiple possible memory orderings. They obey the same
32-
//! semantics as C++11. See the LLVM documentation on [[atomics]].
33-
//!
34-
//! [atomics]: https://llvm.org/docs/Atomics.html
35-
//!
36-
//! A quick refresher on memory ordering:
37-
//!
38-
//! * Acquire - a barrier for acquiring a lock. Subsequent reads and writes
39-
//! take place after the barrier.
40-
//! * Release - a barrier for releasing a lock. Preceding reads and writes
41-
//! take place before the barrier.
42-
//! * Sequentially consistent - sequentially consistent operations are
43-
//! guaranteed to happen in order. This is the standard mode for working
44-
//! with atomic types and is equivalent to Java's `volatile`.
32+
//! words, with multiple possible memory orderings. See the
33+
//! [atomic types][crate::sync::atomic] docs for details.
4534
//!
4635
//! # Unwinding
4736
//!
@@ -2622,7 +2611,7 @@ pub const fn three_way_compare<T: Copy>(lhs: T, rhss: T) -> crate::cmp::Ordering
26222611
#[rustc_const_unstable(feature = "disjoint_bitor", issue = "135758")]
26232612
#[rustc_nounwind]
26242613
#[rustc_intrinsic]
2625-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
2614+
#[track_caller]
26262615
#[miri::intrinsic_fallback_is_spec] // the fallbacks all `assume` to tell Miri
26272616
pub const unsafe fn disjoint_bitor<T: ~const fallback::DisjointBitOr>(a: T, b: T) -> T {
26282617
// SAFETY: same preconditions as this function.

core/src/num/int_macros.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ macro_rules! int_impl {
555555
#[must_use = "this returns the result of the operation, \
556556
without modifying the original"]
557557
#[inline(always)]
558-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
558+
#[track_caller]
559559
pub const unsafe fn unchecked_add(self, rhs: Self) -> Self {
560560
assert_unsafe_precondition!(
561561
check_language_ub,
@@ -705,7 +705,7 @@ macro_rules! int_impl {
705705
#[must_use = "this returns the result of the operation, \
706706
without modifying the original"]
707707
#[inline(always)]
708-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
708+
#[track_caller]
709709
pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self {
710710
assert_unsafe_precondition!(
711711
check_language_ub,
@@ -855,7 +855,7 @@ macro_rules! int_impl {
855855
#[must_use = "this returns the result of the operation, \
856856
without modifying the original"]
857857
#[inline(always)]
858-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
858+
#[track_caller]
859859
pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self {
860860
assert_unsafe_precondition!(
861861
check_language_ub,
@@ -1199,7 +1199,7 @@ macro_rules! int_impl {
11991199
#[must_use = "this returns the result of the operation, \
12001200
without modifying the original"]
12011201
#[inline(always)]
1202-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1202+
#[track_caller]
12031203
pub const unsafe fn unchecked_neg(self) -> Self {
12041204
assert_unsafe_precondition!(
12051205
check_language_ub,
@@ -1327,7 +1327,7 @@ macro_rules! int_impl {
13271327
#[must_use = "this returns the result of the operation, \
13281328
without modifying the original"]
13291329
#[inline(always)]
1330-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1330+
#[track_caller]
13311331
pub const unsafe fn unchecked_shl(self, rhs: u32) -> Self {
13321332
assert_unsafe_precondition!(
13331333
check_language_ub,
@@ -1448,7 +1448,7 @@ macro_rules! int_impl {
14481448
#[must_use = "this returns the result of the operation, \
14491449
without modifying the original"]
14501450
#[inline(always)]
1451-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1451+
#[track_caller]
14521452
pub const unsafe fn unchecked_shr(self, rhs: u32) -> Self {
14531453
assert_unsafe_precondition!(
14541454
check_language_ub,

core/src/num/nonzero.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ where
388388
#[rustc_const_stable(feature = "nonzero", since = "1.28.0")]
389389
#[must_use]
390390
#[inline]
391+
#[track_caller]
391392
pub const unsafe fn new_unchecked(n: T) -> Self {
392393
match Self::new(n) {
393394
Some(n) => n,
@@ -428,6 +429,7 @@ where
428429
#[unstable(feature = "nonzero_from_mut", issue = "106290")]
429430
#[must_use]
430431
#[inline]
432+
#[track_caller]
431433
pub unsafe fn from_mut_unchecked(n: &mut T) -> &mut Self {
432434
match Self::from_mut(n) {
433435
Some(n) => n,

core/src/num/uint_macros.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ macro_rules! uint_impl {
601601
#[must_use = "this returns the result of the operation, \
602602
without modifying the original"]
603603
#[inline(always)]
604-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
604+
#[track_caller]
605605
pub const unsafe fn unchecked_add(self, rhs: Self) -> Self {
606606
assert_unsafe_precondition!(
607607
check_language_ub,
@@ -791,7 +791,7 @@ macro_rules! uint_impl {
791791
#[must_use = "this returns the result of the operation, \
792792
without modifying the original"]
793793
#[inline(always)]
794-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
794+
#[track_caller]
795795
pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self {
796796
assert_unsafe_precondition!(
797797
check_language_ub,
@@ -974,7 +974,7 @@ macro_rules! uint_impl {
974974
#[must_use = "this returns the result of the operation, \
975975
without modifying the original"]
976976
#[inline(always)]
977-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
977+
#[track_caller]
978978
pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self {
979979
assert_unsafe_precondition!(
980980
check_language_ub,
@@ -1588,7 +1588,7 @@ macro_rules! uint_impl {
15881588
#[must_use = "this returns the result of the operation, \
15891589
without modifying the original"]
15901590
#[inline(always)]
1591-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1591+
#[track_caller]
15921592
pub const unsafe fn unchecked_shl(self, rhs: u32) -> Self {
15931593
assert_unsafe_precondition!(
15941594
check_language_ub,
@@ -1709,7 +1709,7 @@ macro_rules! uint_impl {
17091709
#[must_use = "this returns the result of the operation, \
17101710
without modifying the original"]
17111711
#[inline(always)]
1712-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1712+
#[track_caller]
17131713
pub const unsafe fn unchecked_shr(self, rhs: u32) -> Self {
17141714
assert_unsafe_precondition!(
17151715
check_language_ub,

core/src/ops/index_range.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ impl IndexRange {
1919
/// # Safety
2020
/// - `start <= end`
2121
#[inline]
22+
#[track_caller]
2223
pub(crate) const unsafe fn new_unchecked(start: usize, end: usize) -> Self {
2324
ub_checks::assert_unsafe_precondition!(
2425
check_library_ub,

core/src/option.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,36 @@ impl<T> Option<T> {
12531253
}
12541254
}
12551255

1256+
/// Maps an `Option<T>` to a `U` by applying function `f` to the contained
1257+
/// value if the option is [`Some`], otherwise if [`None`], returns the
1258+
/// [default value] for the type `U`.
1259+
///
1260+
/// # Examples
1261+
///
1262+
/// ```
1263+
/// #![feature(result_option_map_or_default)]
1264+
///
1265+
/// let x: Option<&str> = Some("hi");
1266+
/// let y: Option<&str> = None;
1267+
///
1268+
/// assert_eq!(x.map_or_default(|x| x.len()), 2);
1269+
/// assert_eq!(y.map_or_default(|y| y.len()), 0);
1270+
/// ```
1271+
///
1272+
/// [default value]: Default::default
1273+
#[inline]
1274+
#[unstable(feature = "result_option_map_or_default", issue = "138099")]
1275+
pub fn map_or_default<U, F>(self, f: F) -> U
1276+
where
1277+
U: Default,
1278+
F: FnOnce(T) -> U,
1279+
{
1280+
match self {
1281+
Some(t) => f(t),
1282+
None => U::default(),
1283+
}
1284+
}
1285+
12561286
/// Transforms the `Option<T>` into a [`Result<T, E>`], mapping [`Some(v)`] to
12571287
/// [`Ok(v)`] and [`None`] to [`Err(err)`].
12581288
///

core/src/ptr/alignment.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ impl Alignment {
7373
/// It must *not* be zero.
7474
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
7575
#[inline]
76+
#[track_caller]
7677
pub const unsafe fn new_unchecked(align: usize) -> Self {
7778
assert_unsafe_precondition!(
7879
check_language_ub,

core/src/ptr/const_ptr.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ impl<T: ?Sized> *const T {
442442
#[must_use = "returns a new pointer rather than modifying its argument"]
443443
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
444444
#[inline(always)]
445-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
445+
#[track_caller]
446446
pub const unsafe fn offset(self, count: isize) -> *const T
447447
where
448448
T: Sized,
@@ -495,7 +495,7 @@ impl<T: ?Sized> *const T {
495495
#[inline(always)]
496496
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
497497
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
498-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
498+
#[track_caller]
499499
pub const unsafe fn byte_offset(self, count: isize) -> Self {
500500
// SAFETY: the caller must uphold the safety contract for `offset`.
501501
unsafe { self.cast::<u8>().offset(count).with_metadata_of(self) }
@@ -794,7 +794,7 @@ impl<T: ?Sized> *const T {
794794
#[stable(feature = "ptr_sub_ptr", since = "1.87.0")]
795795
#[rustc_const_stable(feature = "const_ptr_sub_ptr", since = "1.87.0")]
796796
#[inline]
797-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
797+
#[track_caller]
798798
pub const unsafe fn offset_from_unsigned(self, origin: *const T) -> usize
799799
where
800800
T: Sized,
@@ -839,7 +839,7 @@ impl<T: ?Sized> *const T {
839839
#[stable(feature = "ptr_sub_ptr", since = "1.87.0")]
840840
#[rustc_const_stable(feature = "const_ptr_sub_ptr", since = "1.87.0")]
841841
#[inline]
842-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
842+
#[track_caller]
843843
pub const unsafe fn byte_offset_from_unsigned<U: ?Sized>(self, origin: *const U) -> usize {
844844
// SAFETY: the caller must uphold the safety contract for `offset_from_unsigned`.
845845
unsafe { self.cast::<u8>().offset_from_unsigned(origin.cast::<u8>()) }
@@ -953,7 +953,7 @@ impl<T: ?Sized> *const T {
953953
#[must_use = "returns a new pointer rather than modifying its argument"]
954954
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
955955
#[inline(always)]
956-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
956+
#[track_caller]
957957
pub const unsafe fn add(self, count: usize) -> Self
958958
where
959959
T: Sized,
@@ -1005,7 +1005,7 @@ impl<T: ?Sized> *const T {
10051005
#[inline(always)]
10061006
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
10071007
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
1008-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1008+
#[track_caller]
10091009
pub const unsafe fn byte_add(self, count: usize) -> Self {
10101010
// SAFETY: the caller must uphold the safety contract for `add`.
10111011
unsafe { self.cast::<u8>().add(count).with_metadata_of(self) }
@@ -1059,7 +1059,7 @@ impl<T: ?Sized> *const T {
10591059
#[must_use = "returns a new pointer rather than modifying its argument"]
10601060
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
10611061
#[inline(always)]
1062-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1062+
#[track_caller]
10631063
pub const unsafe fn sub(self, count: usize) -> Self
10641064
where
10651065
T: Sized,
@@ -1117,7 +1117,7 @@ impl<T: ?Sized> *const T {
11171117
#[inline(always)]
11181118
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
11191119
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
1120-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1120+
#[track_caller]
11211121
pub const unsafe fn byte_sub(self, count: usize) -> Self {
11221122
// SAFETY: the caller must uphold the safety contract for `sub`.
11231123
unsafe { self.cast::<u8>().sub(count).with_metadata_of(self) }
@@ -1290,7 +1290,7 @@ impl<T: ?Sized> *const T {
12901290
#[stable(feature = "pointer_methods", since = "1.26.0")]
12911291
#[rustc_const_stable(feature = "const_ptr_read", since = "1.71.0")]
12921292
#[inline]
1293-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1293+
#[track_caller]
12941294
pub const unsafe fn read(self) -> T
12951295
where
12961296
T: Sized,
@@ -1311,7 +1311,7 @@ impl<T: ?Sized> *const T {
13111311
/// [`ptr::read_volatile`]: crate::ptr::read_volatile()
13121312
#[stable(feature = "pointer_methods", since = "1.26.0")]
13131313
#[inline]
1314-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1314+
#[track_caller]
13151315
pub unsafe fn read_volatile(self) -> T
13161316
where
13171317
T: Sized,
@@ -1331,7 +1331,7 @@ impl<T: ?Sized> *const T {
13311331
#[stable(feature = "pointer_methods", since = "1.26.0")]
13321332
#[rustc_const_stable(feature = "const_ptr_read", since = "1.71.0")]
13331333
#[inline]
1334-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1334+
#[track_caller]
13351335
pub const unsafe fn read_unaligned(self) -> T
13361336
where
13371337
T: Sized,
@@ -1351,7 +1351,7 @@ impl<T: ?Sized> *const T {
13511351
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.83.0")]
13521352
#[stable(feature = "pointer_methods", since = "1.26.0")]
13531353
#[inline]
1354-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1354+
#[track_caller]
13551355
pub const unsafe fn copy_to(self, dest: *mut T, count: usize)
13561356
where
13571357
T: Sized,
@@ -1371,7 +1371,7 @@ impl<T: ?Sized> *const T {
13711371
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.83.0")]
13721372
#[stable(feature = "pointer_methods", since = "1.26.0")]
13731373
#[inline]
1374-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1374+
#[track_caller]
13751375
pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize)
13761376
where
13771377
T: Sized,

0 commit comments

Comments
 (0)