Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c18718c

Browse files
committedJan 16, 2025·
Less unsafe in dangling/without_provenance
1 parent 5cd16b7 commit c18718c

18 files changed

+272
-457
lines changed
 

‎library/core/src/ptr/alignment.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ impl Alignment {
4242
/// but in an `Alignment` instead of a `usize`.
4343
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
4444
#[inline]
45+
#[must_use]
4546
pub const fn of<T>() -> Self {
46-
// SAFETY: rustc ensures that type alignment is always a power of two.
47-
unsafe { Alignment::new_unchecked(mem::align_of::<T>()) }
47+
// This can't actually panic since type alignment is always a power of two.
48+
const { Alignment::new(mem::align_of::<T>()).unwrap() }
4849
}
4950

5051
/// Creates an `Alignment` from a `usize`, or returns `None` if it's
@@ -95,8 +96,13 @@ impl Alignment {
9596
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
9697
#[inline]
9798
pub const fn as_nonzero(self) -> NonZero<usize> {
99+
// This transmutes directly to avoid the UbCheck in `NonZero::new_unchecked`
100+
// since there's no way for the user to trip that check anyway -- the
101+
// validity invariant of the type would have to have been broken earlier --
102+
// and emitting it in an otherwise simple method is bad for compile time.
103+
98104
// SAFETY: All the discriminants are non-zero.
99-
unsafe { NonZero::new_unchecked(self.as_usize()) }
105+
unsafe { mem::transmute::<Alignment, NonZero<usize>>(self) }
100106
}
101107

102108
/// Returns the base-2 logarithm of the alignment.

‎library/core/src/ptr/mod.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,7 @@ pub const fn null_mut<T: ?Sized + Thin>() -> *mut T {
596596
#[stable(feature = "strict_provenance", since = "1.84.0")]
597597
#[rustc_const_stable(feature = "strict_provenance", since = "1.84.0")]
598598
pub const fn without_provenance<T>(addr: usize) -> *const T {
599-
// An int-to-pointer transmute currently has exactly the intended semantics: it creates a
600-
// pointer without provenance. Note that this is *not* a stable guarantee about transmute
601-
// semantics, it relies on sysroot crates having special status.
602-
// SAFETY: every valid integer is also a valid pointer (as long as you don't dereference that
603-
// pointer).
604-
unsafe { mem::transmute(addr) }
599+
without_provenance_mut(addr)
605600
}
606601

607602
/// Creates a new pointer that is dangling, but non-null and well-aligned.
@@ -618,7 +613,7 @@ pub const fn without_provenance<T>(addr: usize) -> *const T {
618613
#[stable(feature = "strict_provenance", since = "1.84.0")]
619614
#[rustc_const_stable(feature = "strict_provenance", since = "1.84.0")]
620615
pub const fn dangling<T>() -> *const T {
621-
without_provenance(mem::align_of::<T>())
616+
dangling_mut()
622617
}
623618

624619
/// Creates a pointer with the given address and no [provenance][crate::ptr#provenance].
@@ -661,7 +656,7 @@ pub const fn without_provenance_mut<T>(addr: usize) -> *mut T {
661656
#[stable(feature = "strict_provenance", since = "1.84.0")]
662657
#[rustc_const_stable(feature = "strict_provenance", since = "1.84.0")]
663658
pub const fn dangling_mut<T>() -> *mut T {
664-
without_provenance_mut(mem::align_of::<T>())
659+
NonNull::dangling().as_ptr()
665660
}
666661

667662
/// Converts an address back to a pointer, picking up some previously 'exposed'

‎library/core/src/ptr/non_null.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ impl<T: Sized> NonNull<T> {
9191
///
9292
/// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
9393
#[unstable(feature = "nonnull_provenance", issue = "135243")]
94+
#[must_use]
95+
#[inline]
9496
pub const fn without_provenance(addr: NonZero<usize>) -> Self {
97+
let pointer = crate::ptr::without_provenance(addr.get());
9598
// SAFETY: we know `addr` is non-zero.
96-
unsafe {
97-
let ptr = crate::ptr::without_provenance_mut(addr.get());
98-
NonNull::new_unchecked(ptr)
99-
}
99+
unsafe { NonNull { pointer } }
100100
}
101101

102102
/// Creates a new `NonNull` that is dangling, but well-aligned.
@@ -123,11 +123,8 @@ impl<T: Sized> NonNull<T> {
123123
#[must_use]
124124
#[inline]
125125
pub const fn dangling() -> Self {
126-
// SAFETY: ptr::dangling_mut() returns a non-null well-aligned pointer.
127-
unsafe {
128-
let ptr = crate::ptr::dangling_mut::<T>();
129-
NonNull::new_unchecked(ptr)
130-
}
126+
let align = crate::ptr::Alignment::of::<T>();
127+
NonNull::without_provenance(align.as_nonzero())
131128
}
132129

133130
/// Converts an address back to a mutable pointer, picking up some previously 'exposed'
@@ -137,6 +134,7 @@ impl<T: Sized> NonNull<T> {
137134
///
138135
/// This is an [Exposed Provenance][crate::ptr#exposed-provenance] API.
139136
#[unstable(feature = "nonnull_provenance", issue = "135243")]
137+
#[inline]
140138
pub fn with_exposed_provenance(addr: NonZero<usize>) -> Self {
141139
// SAFETY: we know `addr` is non-zero.
142140
unsafe {

‎tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,23 @@
1616
scope 4 (inlined Unique::<[bool; 0]>::dangling) {
1717
let mut _5: std::ptr::NonNull<[bool; 0]>;
1818
scope 5 (inlined NonNull::<[bool; 0]>::dangling) {
19-
let _6: *mut [bool; 0];
19+
let mut _6: std::num::NonZero<usize>;
2020
scope 6 {
21-
scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) {
22-
let mut _8: bool;
23-
let _9: ();
24-
let mut _10: *mut ();
25-
let mut _11: *const [bool; 0];
26-
scope 11 (inlined core::ub_checks::check_language_ub) {
27-
scope 12 (inlined core::ub_checks::check_language_ub::runtime) {
21+
scope 8 (inlined std::ptr::Alignment::as_nonzero) {
22+
}
23+
scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) {
24+
let _7: *const [bool; 0];
25+
scope 10 {
26+
}
27+
scope 11 (inlined NonZero::<usize>::get) {
28+
}
29+
scope 12 (inlined without_provenance::<[bool; 0]>) {
30+
scope 13 (inlined without_provenance_mut::<[bool; 0]>) {
2831
}
2932
}
3033
}
3134
}
32-
scope 7 (inlined dangling_mut::<[bool; 0]>) {
33-
let mut _7: usize;
34-
scope 8 (inlined align_of::<[bool; 0]>) {
35-
}
36-
scope 9 (inlined without_provenance_mut::<[bool; 0]>) {
37-
}
35+
scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) {
3836
}
3937
}
4038
}
@@ -44,54 +42,31 @@
4442
StorageLive(_1);
4543
StorageLive(_2);
4644
StorageLive(_3);
47-
StorageLive(_9);
4845
StorageLive(_4);
4946
StorageLive(_5);
5047
StorageLive(_6);
48+
_6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize));
5149
StorageLive(_7);
52-
_7 = const 1_usize;
53-
_6 = const {0x1 as *mut [bool; 0]};
54-
StorageLive(_11);
55-
StorageLive(_8);
56-
_8 = UbChecks();
57-
switchInt(move _8) -> [0: bb4, otherwise: bb2];
58-
}
59-
60-
bb1: {
61-
StorageDead(_1);
62-
return;
63-
}
64-
65-
bb2: {
66-
StorageLive(_10);
67-
_10 = const {0x1 as *mut ()};
68-
_9 = NonNull::<T>::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb3, unwind unreachable];
69-
}
70-
71-
bb3: {
72-
StorageDead(_10);
73-
goto -> bb4;
74-
}
75-
76-
bb4: {
77-
StorageDead(_8);
78-
_11 = const {0x1 as *const [bool; 0]};
50+
_7 = const {0x1 as *const [bool; 0]};
7951
_5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
80-
StorageDead(_11);
8152
StorageDead(_7);
8253
StorageDead(_6);
8354
_4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }};
8455
StorageDead(_5);
8556
_3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }};
8657
StorageDead(_4);
8758
_2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global);
88-
StorageDead(_9);
8959
StorageDead(_3);
9060
_1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }};
9161
StorageDead(_2);
9262
_0 = const ();
9363
drop(_1) -> [return: bb1, unwind unreachable];
9464
}
65+
66+
bb1: {
67+
StorageDead(_1);
68+
return;
69+
}
9570
}
9671

9772
ALLOC2 (size: 8, align: 4) { .. }

‎tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,23 @@
1616
scope 4 (inlined Unique::<[bool; 0]>::dangling) {
1717
let mut _5: std::ptr::NonNull<[bool; 0]>;
1818
scope 5 (inlined NonNull::<[bool; 0]>::dangling) {
19-
let _6: *mut [bool; 0];
19+
let mut _6: std::num::NonZero<usize>;
2020
scope 6 {
21-
scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) {
22-
let mut _8: bool;
23-
let _9: ();
24-
let mut _10: *mut ();
25-
let mut _11: *const [bool; 0];
26-
scope 11 (inlined core::ub_checks::check_language_ub) {
27-
scope 12 (inlined core::ub_checks::check_language_ub::runtime) {
21+
scope 8 (inlined std::ptr::Alignment::as_nonzero) {
22+
}
23+
scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) {
24+
let _7: *const [bool; 0];
25+
scope 10 {
26+
}
27+
scope 11 (inlined NonZero::<usize>::get) {
28+
}
29+
scope 12 (inlined without_provenance::<[bool; 0]>) {
30+
scope 13 (inlined without_provenance_mut::<[bool; 0]>) {
2831
}
2932
}
3033
}
3134
}
32-
scope 7 (inlined dangling_mut::<[bool; 0]>) {
33-
let mut _7: usize;
34-
scope 8 (inlined align_of::<[bool; 0]>) {
35-
}
36-
scope 9 (inlined without_provenance_mut::<[bool; 0]>) {
37-
}
35+
scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) {
3836
}
3937
}
4038
}
@@ -44,58 +42,35 @@
4442
StorageLive(_1);
4543
StorageLive(_2);
4644
StorageLive(_3);
47-
StorageLive(_9);
4845
StorageLive(_4);
4946
StorageLive(_5);
5047
StorageLive(_6);
48+
_6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize));
5149
StorageLive(_7);
52-
_7 = const 1_usize;
53-
_6 = const {0x1 as *mut [bool; 0]};
54-
StorageLive(_11);
55-
StorageLive(_8);
56-
_8 = UbChecks();
57-
switchInt(move _8) -> [0: bb5, otherwise: bb3];
58-
}
59-
60-
bb1: {
61-
StorageDead(_1);
62-
return;
63-
}
64-
65-
bb2 (cleanup): {
66-
resume;
67-
}
68-
69-
bb3: {
70-
StorageLive(_10);
71-
_10 = const {0x1 as *mut ()};
72-
_9 = NonNull::<T>::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb4, unwind unreachable];
73-
}
74-
75-
bb4: {
76-
StorageDead(_10);
77-
goto -> bb5;
78-
}
79-
80-
bb5: {
81-
StorageDead(_8);
82-
_11 = const {0x1 as *const [bool; 0]};
50+
_7 = const {0x1 as *const [bool; 0]};
8351
_5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
84-
StorageDead(_11);
8552
StorageDead(_7);
8653
StorageDead(_6);
8754
_4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }};
8855
StorageDead(_5);
8956
_3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }};
9057
StorageDead(_4);
9158
_2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global);
92-
StorageDead(_9);
9359
StorageDead(_3);
9460
_1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }};
9561
StorageDead(_2);
9662
_0 = const ();
9763
drop(_1) -> [return: bb1, unwind: bb2];
9864
}
65+
66+
bb1: {
67+
StorageDead(_1);
68+
return;
69+
}
70+
71+
bb2 (cleanup): {
72+
resume;
73+
}
9974
}
10075

10176
ALLOC2 (size: 8, align: 4) { .. }

‎tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,23 @@
1616
scope 4 (inlined Unique::<[bool; 0]>::dangling) {
1717
let mut _5: std::ptr::NonNull<[bool; 0]>;
1818
scope 5 (inlined NonNull::<[bool; 0]>::dangling) {
19-
let _6: *mut [bool; 0];
19+
let mut _6: std::num::NonZero<usize>;
2020
scope 6 {
21-
scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) {
22-
let mut _8: bool;
23-
let _9: ();
24-
let mut _10: *mut ();
25-
let mut _11: *const [bool; 0];
26-
scope 11 (inlined core::ub_checks::check_language_ub) {
27-
scope 12 (inlined core::ub_checks::check_language_ub::runtime) {
21+
scope 8 (inlined std::ptr::Alignment::as_nonzero) {
22+
}
23+
scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) {
24+
let _7: *const [bool; 0];
25+
scope 10 {
26+
}
27+
scope 11 (inlined NonZero::<usize>::get) {
28+
}
29+
scope 12 (inlined without_provenance::<[bool; 0]>) {
30+
scope 13 (inlined without_provenance_mut::<[bool; 0]>) {
2831
}
2932
}
3033
}
3134
}
32-
scope 7 (inlined dangling_mut::<[bool; 0]>) {
33-
let mut _7: usize;
34-
scope 8 (inlined align_of::<[bool; 0]>) {
35-
}
36-
scope 9 (inlined without_provenance_mut::<[bool; 0]>) {
37-
}
35+
scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) {
3836
}
3937
}
4038
}
@@ -44,54 +42,31 @@
4442
StorageLive(_1);
4543
StorageLive(_2);
4644
StorageLive(_3);
47-
StorageLive(_9);
4845
StorageLive(_4);
4946
StorageLive(_5);
5047
StorageLive(_6);
48+
_6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize));
5149
StorageLive(_7);
52-
_7 = const 1_usize;
53-
_6 = const {0x1 as *mut [bool; 0]};
54-
StorageLive(_11);
55-
StorageLive(_8);
56-
_8 = UbChecks();
57-
switchInt(move _8) -> [0: bb4, otherwise: bb2];
58-
}
59-
60-
bb1: {
61-
StorageDead(_1);
62-
return;
63-
}
64-
65-
bb2: {
66-
StorageLive(_10);
67-
_10 = const {0x1 as *mut ()};
68-
_9 = NonNull::<T>::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb3, unwind unreachable];
69-
}
70-
71-
bb3: {
72-
StorageDead(_10);
73-
goto -> bb4;
74-
}
75-
76-
bb4: {
77-
StorageDead(_8);
78-
_11 = const {0x1 as *const [bool; 0]};
50+
_7 = const {0x1 as *const [bool; 0]};
7951
_5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
80-
StorageDead(_11);
8152
StorageDead(_7);
8253
StorageDead(_6);
8354
_4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }};
8455
StorageDead(_5);
8556
_3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }};
8657
StorageDead(_4);
8758
_2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global);
88-
StorageDead(_9);
8959
StorageDead(_3);
9060
_1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }};
9161
StorageDead(_2);
9262
_0 = const ();
9363
drop(_1) -> [return: bb1, unwind unreachable];
9464
}
65+
66+
bb1: {
67+
StorageDead(_1);
68+
return;
69+
}
9570
}
9671

9772
ALLOC2 (size: 16, align: 8) { .. }

‎tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,23 @@
1616
scope 4 (inlined Unique::<[bool; 0]>::dangling) {
1717
let mut _5: std::ptr::NonNull<[bool; 0]>;
1818
scope 5 (inlined NonNull::<[bool; 0]>::dangling) {
19-
let _6: *mut [bool; 0];
19+
let mut _6: std::num::NonZero<usize>;
2020
scope 6 {
21-
scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) {
22-
let mut _8: bool;
23-
let _9: ();
24-
let mut _10: *mut ();
25-
let mut _11: *const [bool; 0];
26-
scope 11 (inlined core::ub_checks::check_language_ub) {
27-
scope 12 (inlined core::ub_checks::check_language_ub::runtime) {
21+
scope 8 (inlined std::ptr::Alignment::as_nonzero) {
22+
}
23+
scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) {
24+
let _7: *const [bool; 0];
25+
scope 10 {
26+
}
27+
scope 11 (inlined NonZero::<usize>::get) {
28+
}
29+
scope 12 (inlined without_provenance::<[bool; 0]>) {
30+
scope 13 (inlined without_provenance_mut::<[bool; 0]>) {
2831
}
2932
}
3033
}
3134
}
32-
scope 7 (inlined dangling_mut::<[bool; 0]>) {
33-
let mut _7: usize;
34-
scope 8 (inlined align_of::<[bool; 0]>) {
35-
}
36-
scope 9 (inlined without_provenance_mut::<[bool; 0]>) {
37-
}
35+
scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) {
3836
}
3937
}
4038
}
@@ -44,58 +42,35 @@
4442
StorageLive(_1);
4543
StorageLive(_2);
4644
StorageLive(_3);
47-
StorageLive(_9);
4845
StorageLive(_4);
4946
StorageLive(_5);
5047
StorageLive(_6);
48+
_6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize));
5149
StorageLive(_7);
52-
_7 = const 1_usize;
53-
_6 = const {0x1 as *mut [bool; 0]};
54-
StorageLive(_11);
55-
StorageLive(_8);
56-
_8 = UbChecks();
57-
switchInt(move _8) -> [0: bb5, otherwise: bb3];
58-
}
59-
60-
bb1: {
61-
StorageDead(_1);
62-
return;
63-
}
64-
65-
bb2 (cleanup): {
66-
resume;
67-
}
68-
69-
bb3: {
70-
StorageLive(_10);
71-
_10 = const {0x1 as *mut ()};
72-
_9 = NonNull::<T>::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb4, unwind unreachable];
73-
}
74-
75-
bb4: {
76-
StorageDead(_10);
77-
goto -> bb5;
78-
}
79-
80-
bb5: {
81-
StorageDead(_8);
82-
_11 = const {0x1 as *const [bool; 0]};
50+
_7 = const {0x1 as *const [bool; 0]};
8351
_5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
84-
StorageDead(_11);
8552
StorageDead(_7);
8653
StorageDead(_6);
8754
_4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }};
8855
StorageDead(_5);
8956
_3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }};
9057
StorageDead(_4);
9158
_2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global);
92-
StorageDead(_9);
9359
StorageDead(_3);
9460
_1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }};
9561
StorageDead(_2);
9662
_0 = const ();
9763
drop(_1) -> [return: bb1, unwind: bb2];
9864
}
65+
66+
bb1: {
67+
StorageDead(_1);
68+
return;
69+
}
70+
71+
bb2 (cleanup): {
72+
resume;
73+
}
9974
}
10075

10176
ALLOC2 (size: 16, align: 8) { .. }

‎tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff

Lines changed: 22 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,23 @@
1616
scope 4 (inlined Unique::<[bool; 0]>::dangling) {
1717
let mut _5: std::ptr::NonNull<[bool; 0]>;
1818
scope 5 (inlined NonNull::<[bool; 0]>::dangling) {
19-
let _6: *mut [bool; 0];
19+
let mut _6: std::num::NonZero<usize>;
2020
scope 6 {
21-
scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) {
22-
let mut _8: bool;
23-
let _9: ();
24-
let mut _10: *mut ();
25-
let mut _11: *const [bool; 0];
26-
scope 11 (inlined core::ub_checks::check_language_ub) {
27-
scope 12 (inlined core::ub_checks::check_language_ub::runtime) {
21+
scope 8 (inlined std::ptr::Alignment::as_nonzero) {
22+
}
23+
scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) {
24+
let _7: *const [bool; 0];
25+
scope 10 {
26+
}
27+
scope 11 (inlined NonZero::<usize>::get) {
28+
}
29+
scope 12 (inlined without_provenance::<[bool; 0]>) {
30+
scope 13 (inlined without_provenance_mut::<[bool; 0]>) {
2831
}
2932
}
3033
}
3134
}
32-
scope 7 (inlined dangling_mut::<[bool; 0]>) {
33-
let mut _7: usize;
34-
scope 8 (inlined align_of::<[bool; 0]>) {
35-
}
36-
scope 9 (inlined without_provenance_mut::<[bool; 0]>) {
37-
}
35+
scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) {
3836
}
3937
}
4038
}
@@ -44,46 +42,16 @@
4442
StorageLive(_1);
4543
StorageLive(_2);
4644
StorageLive(_3);
47-
StorageLive(_9);
4845
StorageLive(_4);
4946
StorageLive(_5);
5047
StorageLive(_6);
48+
- _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as std::num::NonZero<usize> (Transmute);
49+
+ _6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize));
5150
StorageLive(_7);
52-
- _7 = AlignOf([bool; 0]);
53-
- _6 = copy _7 as *mut [bool; 0] (Transmute);
54-
+ _7 = const 1_usize;
55-
+ _6 = const {0x1 as *mut [bool; 0]};
56-
StorageLive(_11);
57-
StorageLive(_8);
58-
_8 = UbChecks();
59-
switchInt(move _8) -> [0: bb4, otherwise: bb2];
60-
}
61-
62-
bb1: {
63-
StorageDead(_1);
64-
return;
65-
}
66-
67-
bb2: {
68-
StorageLive(_10);
69-
- _10 = copy _7 as *mut () (Transmute);
70-
- _9 = NonNull::<T>::new_unchecked::precondition_check(move _10) -> [return: bb3, unwind unreachable];
71-
+ _10 = const {0x1 as *mut ()};
72-
+ _9 = NonNull::<T>::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb3, unwind unreachable];
73-
}
74-
75-
bb3: {
76-
StorageDead(_10);
77-
goto -> bb4;
78-
}
79-
80-
bb4: {
81-
StorageDead(_8);
82-
- _11 = copy _7 as *const [bool; 0] (Transmute);
83-
- _5 = NonNull::<[bool; 0]> { pointer: copy _11 };
84-
+ _11 = const {0x1 as *const [bool; 0]};
51+
- _7 = copy _6 as *const [bool; 0] (Transmute);
52+
- _5 = NonNull::<[bool; 0]> { pointer: copy _7 };
53+
+ _7 = const {0x1 as *const [bool; 0]};
8554
+ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
86-
StorageDead(_11);
8755
StorageDead(_7);
8856
StorageDead(_6);
8957
- _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> };
@@ -94,14 +62,18 @@
9462
StorageDead(_4);
9563
- _2 = Box::<[bool]>(copy _3, const std::alloc::Global);
9664
+ _2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global);
97-
StorageDead(_9);
9865
StorageDead(_3);
9966
- _1 = A { foo: move _2 };
10067
+ _1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }};
10168
StorageDead(_2);
10269
_0 = const ();
10370
drop(_1) -> [return: bb1, unwind unreachable];
10471
}
72+
73+
bb1: {
74+
StorageDead(_1);
75+
return;
76+
}
10577
}
10678
+
10779
+ ALLOC2 (size: 8, align: 4) { .. }

‎tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff

Lines changed: 26 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,23 @@
1616
scope 4 (inlined Unique::<[bool; 0]>::dangling) {
1717
let mut _5: std::ptr::NonNull<[bool; 0]>;
1818
scope 5 (inlined NonNull::<[bool; 0]>::dangling) {
19-
let _6: *mut [bool; 0];
19+
let mut _6: std::num::NonZero<usize>;
2020
scope 6 {
21-
scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) {
22-
let mut _8: bool;
23-
let _9: ();
24-
let mut _10: *mut ();
25-
let mut _11: *const [bool; 0];
26-
scope 11 (inlined core::ub_checks::check_language_ub) {
27-
scope 12 (inlined core::ub_checks::check_language_ub::runtime) {
21+
scope 8 (inlined std::ptr::Alignment::as_nonzero) {
22+
}
23+
scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) {
24+
let _7: *const [bool; 0];
25+
scope 10 {
26+
}
27+
scope 11 (inlined NonZero::<usize>::get) {
28+
}
29+
scope 12 (inlined without_provenance::<[bool; 0]>) {
30+
scope 13 (inlined without_provenance_mut::<[bool; 0]>) {
2831
}
2932
}
3033
}
3134
}
32-
scope 7 (inlined dangling_mut::<[bool; 0]>) {
33-
let mut _7: usize;
34-
scope 8 (inlined align_of::<[bool; 0]>) {
35-
}
36-
scope 9 (inlined without_provenance_mut::<[bool; 0]>) {
37-
}
35+
scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) {
3836
}
3937
}
4038
}
@@ -44,50 +42,16 @@
4442
StorageLive(_1);
4543
StorageLive(_2);
4644
StorageLive(_3);
47-
StorageLive(_9);
4845
StorageLive(_4);
4946
StorageLive(_5);
5047
StorageLive(_6);
48+
- _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as std::num::NonZero<usize> (Transmute);
49+
+ _6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize));
5150
StorageLive(_7);
52-
- _7 = AlignOf([bool; 0]);
53-
- _6 = copy _7 as *mut [bool; 0] (Transmute);
54-
+ _7 = const 1_usize;
55-
+ _6 = const {0x1 as *mut [bool; 0]};
56-
StorageLive(_11);
57-
StorageLive(_8);
58-
_8 = UbChecks();
59-
switchInt(move _8) -> [0: bb5, otherwise: bb3];
60-
}
61-
62-
bb1: {
63-
StorageDead(_1);
64-
return;
65-
}
66-
67-
bb2 (cleanup): {
68-
resume;
69-
}
70-
71-
bb3: {
72-
StorageLive(_10);
73-
- _10 = copy _7 as *mut () (Transmute);
74-
- _9 = NonNull::<T>::new_unchecked::precondition_check(move _10) -> [return: bb4, unwind unreachable];
75-
+ _10 = const {0x1 as *mut ()};
76-
+ _9 = NonNull::<T>::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb4, unwind unreachable];
77-
}
78-
79-
bb4: {
80-
StorageDead(_10);
81-
goto -> bb5;
82-
}
83-
84-
bb5: {
85-
StorageDead(_8);
86-
- _11 = copy _7 as *const [bool; 0] (Transmute);
87-
- _5 = NonNull::<[bool; 0]> { pointer: copy _11 };
88-
+ _11 = const {0x1 as *const [bool; 0]};
51+
- _7 = copy _6 as *const [bool; 0] (Transmute);
52+
- _5 = NonNull::<[bool; 0]> { pointer: copy _7 };
53+
+ _7 = const {0x1 as *const [bool; 0]};
8954
+ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
90-
StorageDead(_11);
9155
StorageDead(_7);
9256
StorageDead(_6);
9357
- _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> };
@@ -98,14 +62,22 @@
9862
StorageDead(_4);
9963
- _2 = Box::<[bool]>(copy _3, const std::alloc::Global);
10064
+ _2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global);
101-
StorageDead(_9);
10265
StorageDead(_3);
10366
- _1 = A { foo: move _2 };
10467
+ _1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }};
10568
StorageDead(_2);
10669
_0 = const ();
10770
drop(_1) -> [return: bb1, unwind: bb2];
10871
}
72+
73+
bb1: {
74+
StorageDead(_1);
75+
return;
76+
}
77+
78+
bb2 (cleanup): {
79+
resume;
80+
}
10981
}
11082
+
11183
+ ALLOC2 (size: 8, align: 4) { .. }

‎tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff

Lines changed: 22 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,23 @@
1616
scope 4 (inlined Unique::<[bool; 0]>::dangling) {
1717
let mut _5: std::ptr::NonNull<[bool; 0]>;
1818
scope 5 (inlined NonNull::<[bool; 0]>::dangling) {
19-
let _6: *mut [bool; 0];
19+
let mut _6: std::num::NonZero<usize>;
2020
scope 6 {
21-
scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) {
22-
let mut _8: bool;
23-
let _9: ();
24-
let mut _10: *mut ();
25-
let mut _11: *const [bool; 0];
26-
scope 11 (inlined core::ub_checks::check_language_ub) {
27-
scope 12 (inlined core::ub_checks::check_language_ub::runtime) {
21+
scope 8 (inlined std::ptr::Alignment::as_nonzero) {
22+
}
23+
scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) {
24+
let _7: *const [bool; 0];
25+
scope 10 {
26+
}
27+
scope 11 (inlined NonZero::<usize>::get) {
28+
}
29+
scope 12 (inlined without_provenance::<[bool; 0]>) {
30+
scope 13 (inlined without_provenance_mut::<[bool; 0]>) {
2831
}
2932
}
3033
}
3134
}
32-
scope 7 (inlined dangling_mut::<[bool; 0]>) {
33-
let mut _7: usize;
34-
scope 8 (inlined align_of::<[bool; 0]>) {
35-
}
36-
scope 9 (inlined without_provenance_mut::<[bool; 0]>) {
37-
}
35+
scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) {
3836
}
3937
}
4038
}
@@ -44,46 +42,16 @@
4442
StorageLive(_1);
4543
StorageLive(_2);
4644
StorageLive(_3);
47-
StorageLive(_9);
4845
StorageLive(_4);
4946
StorageLive(_5);
5047
StorageLive(_6);
48+
- _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as std::num::NonZero<usize> (Transmute);
49+
+ _6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize));
5150
StorageLive(_7);
52-
- _7 = AlignOf([bool; 0]);
53-
- _6 = copy _7 as *mut [bool; 0] (Transmute);
54-
+ _7 = const 1_usize;
55-
+ _6 = const {0x1 as *mut [bool; 0]};
56-
StorageLive(_11);
57-
StorageLive(_8);
58-
_8 = UbChecks();
59-
switchInt(move _8) -> [0: bb4, otherwise: bb2];
60-
}
61-
62-
bb1: {
63-
StorageDead(_1);
64-
return;
65-
}
66-
67-
bb2: {
68-
StorageLive(_10);
69-
- _10 = copy _7 as *mut () (Transmute);
70-
- _9 = NonNull::<T>::new_unchecked::precondition_check(move _10) -> [return: bb3, unwind unreachable];
71-
+ _10 = const {0x1 as *mut ()};
72-
+ _9 = NonNull::<T>::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb3, unwind unreachable];
73-
}
74-
75-
bb3: {
76-
StorageDead(_10);
77-
goto -> bb4;
78-
}
79-
80-
bb4: {
81-
StorageDead(_8);
82-
- _11 = copy _7 as *const [bool; 0] (Transmute);
83-
- _5 = NonNull::<[bool; 0]> { pointer: copy _11 };
84-
+ _11 = const {0x1 as *const [bool; 0]};
51+
- _7 = copy _6 as *const [bool; 0] (Transmute);
52+
- _5 = NonNull::<[bool; 0]> { pointer: copy _7 };
53+
+ _7 = const {0x1 as *const [bool; 0]};
8554
+ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
86-
StorageDead(_11);
8755
StorageDead(_7);
8856
StorageDead(_6);
8957
- _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> };
@@ -94,14 +62,18 @@
9462
StorageDead(_4);
9563
- _2 = Box::<[bool]>(copy _3, const std::alloc::Global);
9664
+ _2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global);
97-
StorageDead(_9);
9865
StorageDead(_3);
9966
- _1 = A { foo: move _2 };
10067
+ _1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }};
10168
StorageDead(_2);
10269
_0 = const ();
10370
drop(_1) -> [return: bb1, unwind unreachable];
10471
}
72+
73+
bb1: {
74+
StorageDead(_1);
75+
return;
76+
}
10577
}
10678
+
10779
+ ALLOC2 (size: 16, align: 8) { .. }

‎tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff

Lines changed: 26 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,23 @@
1616
scope 4 (inlined Unique::<[bool; 0]>::dangling) {
1717
let mut _5: std::ptr::NonNull<[bool; 0]>;
1818
scope 5 (inlined NonNull::<[bool; 0]>::dangling) {
19-
let _6: *mut [bool; 0];
19+
let mut _6: std::num::NonZero<usize>;
2020
scope 6 {
21-
scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) {
22-
let mut _8: bool;
23-
let _9: ();
24-
let mut _10: *mut ();
25-
let mut _11: *const [bool; 0];
26-
scope 11 (inlined core::ub_checks::check_language_ub) {
27-
scope 12 (inlined core::ub_checks::check_language_ub::runtime) {
21+
scope 8 (inlined std::ptr::Alignment::as_nonzero) {
22+
}
23+
scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) {
24+
let _7: *const [bool; 0];
25+
scope 10 {
26+
}
27+
scope 11 (inlined NonZero::<usize>::get) {
28+
}
29+
scope 12 (inlined without_provenance::<[bool; 0]>) {
30+
scope 13 (inlined without_provenance_mut::<[bool; 0]>) {
2831
}
2932
}
3033
}
3134
}
32-
scope 7 (inlined dangling_mut::<[bool; 0]>) {
33-
let mut _7: usize;
34-
scope 8 (inlined align_of::<[bool; 0]>) {
35-
}
36-
scope 9 (inlined without_provenance_mut::<[bool; 0]>) {
37-
}
35+
scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) {
3836
}
3937
}
4038
}
@@ -44,50 +42,16 @@
4442
StorageLive(_1);
4543
StorageLive(_2);
4644
StorageLive(_3);
47-
StorageLive(_9);
4845
StorageLive(_4);
4946
StorageLive(_5);
5047
StorageLive(_6);
48+
- _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as std::num::NonZero<usize> (Transmute);
49+
+ _6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize));
5150
StorageLive(_7);
52-
- _7 = AlignOf([bool; 0]);
53-
- _6 = copy _7 as *mut [bool; 0] (Transmute);
54-
+ _7 = const 1_usize;
55-
+ _6 = const {0x1 as *mut [bool; 0]};
56-
StorageLive(_11);
57-
StorageLive(_8);
58-
_8 = UbChecks();
59-
switchInt(move _8) -> [0: bb5, otherwise: bb3];
60-
}
61-
62-
bb1: {
63-
StorageDead(_1);
64-
return;
65-
}
66-
67-
bb2 (cleanup): {
68-
resume;
69-
}
70-
71-
bb3: {
72-
StorageLive(_10);
73-
- _10 = copy _7 as *mut () (Transmute);
74-
- _9 = NonNull::<T>::new_unchecked::precondition_check(move _10) -> [return: bb4, unwind unreachable];
75-
+ _10 = const {0x1 as *mut ()};
76-
+ _9 = NonNull::<T>::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb4, unwind unreachable];
77-
}
78-
79-
bb4: {
80-
StorageDead(_10);
81-
goto -> bb5;
82-
}
83-
84-
bb5: {
85-
StorageDead(_8);
86-
- _11 = copy _7 as *const [bool; 0] (Transmute);
87-
- _5 = NonNull::<[bool; 0]> { pointer: copy _11 };
88-
+ _11 = const {0x1 as *const [bool; 0]};
51+
- _7 = copy _6 as *const [bool; 0] (Transmute);
52+
- _5 = NonNull::<[bool; 0]> { pointer: copy _7 };
53+
+ _7 = const {0x1 as *const [bool; 0]};
8954
+ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
90-
StorageDead(_11);
9155
StorageDead(_7);
9256
StorageDead(_6);
9357
- _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> };
@@ -98,14 +62,22 @@
9862
StorageDead(_4);
9963
- _2 = Box::<[bool]>(copy _3, const std::alloc::Global);
10064
+ _2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global);
101-
StorageDead(_9);
10265
StorageDead(_3);
10366
- _1 = A { foo: move _2 };
10467
+ _1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }};
10568
StorageDead(_2);
10669
_0 = const ();
10770
drop(_1) -> [return: bb1, unwind: bb2];
10871
}
72+
73+
bb1: {
74+
StorageDead(_1);
75+
return;
76+
}
77+
78+
bb2 (cleanup): {
79+
resume;
80+
}
10981
}
11082
+
11183
+ ALLOC2 (size: 16, align: 8) { .. }

‎tests/mir-opt/gvn_ptr_eq_with_constant.main.GVN.diff

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,43 @@
66
let _1: bool;
77
let mut _2: *mut u8;
88
scope 1 (inlined dangling_mut::<u8>) {
9-
let mut _3: usize;
10-
scope 2 (inlined align_of::<u8>) {
9+
scope 2 (inlined NonNull::<u8>::dangling) {
10+
let mut _3: std::num::NonZero<usize>;
11+
scope 3 {
12+
scope 5 (inlined std::ptr::Alignment::as_nonzero) {
13+
}
14+
scope 6 (inlined NonNull::<u8>::without_provenance) {
15+
scope 7 {
16+
}
17+
scope 8 (inlined NonZero::<usize>::get) {
18+
}
19+
scope 9 (inlined without_provenance::<u8>) {
20+
scope 10 (inlined without_provenance_mut::<u8>) {
21+
}
22+
}
23+
}
24+
}
25+
scope 4 (inlined std::ptr::Alignment::of::<u8>) {
26+
}
1127
}
12-
scope 3 (inlined without_provenance_mut::<u8>) {
28+
scope 11 (inlined NonNull::<u8>::as_ptr) {
1329
}
1430
}
15-
scope 4 (inlined Foo::<u8>::cmp_ptr) {
31+
scope 12 (inlined Foo::<u8>::cmp_ptr) {
1632
let mut _4: *const u8;
1733
let mut _5: *mut u8;
1834
let mut _6: *const u8;
19-
scope 5 (inlined std::ptr::eq::<u8>) {
35+
scope 13 (inlined std::ptr::eq::<u8>) {
2036
}
2137
}
2238

2339
bb0: {
2440
StorageLive(_1);
2541
StorageLive(_2);
2642
StorageLive(_3);
27-
- _3 = AlignOf(u8);
43+
- _3 = const std::ptr::Alignment::of::<u8>::{constant#0} as std::num::NonZero<usize> (Transmute);
2844
- _2 = copy _3 as *mut u8 (Transmute);
29-
+ _3 = const 1_usize;
45+
+ _3 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize));
3046
+ _2 = const {0x1 as *mut u8};
3147
StorageDead(_3);
3248
StorageLive(_4);

‎tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,30 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
1919
debug i => _22;
2020
debug x => _23;
2121
}
22-
scope 18 (inlined <Enumerate<std::slice::Iter<'_, T>> as Iterator>::next) {
22+
scope 19 (inlined <Enumerate<std::slice::Iter<'_, T>> as Iterator>::next) {
2323
let mut _14: &mut std::slice::Iter<'_, T>;
2424
let mut _15: std::option::Option<&T>;
2525
let mut _19: (usize, bool);
2626
let mut _20: (usize, &T);
27-
scope 19 {
27+
scope 20 {
2828
let _18: usize;
29-
scope 24 {
29+
scope 25 {
3030
}
3131
}
32-
scope 20 {
33-
scope 21 {
34-
scope 27 (inlined <Option<(usize, &T)> as FromResidual<Option<Infallible>>>::from_residual) {
32+
scope 21 {
33+
scope 22 {
34+
scope 28 (inlined <Option<(usize, &T)> as FromResidual<Option<Infallible>>>::from_residual) {
3535
}
3636
}
3737
}
38-
scope 22 {
39-
scope 23 {
38+
scope 23 {
39+
scope 24 {
4040
}
4141
}
42-
scope 25 (inlined <Option<&T> as Try>::branch) {
42+
scope 26 (inlined <Option<&T> as Try>::branch) {
4343
let mut _16: isize;
4444
let _17: &T;
45-
scope 26 {
45+
scope 27 {
4646
}
4747
}
4848
}
@@ -60,10 +60,12 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
6060
scope 7 {
6161
}
6262
scope 12 (inlined without_provenance::<T>) {
63+
scope 13 (inlined without_provenance_mut::<T>) {
64+
}
6365
}
64-
scope 13 (inlined NonNull::<T>::as_ptr) {
66+
scope 14 (inlined NonNull::<T>::as_ptr) {
6567
}
66-
scope 14 (inlined std::ptr::mut_ptr::<impl *mut T>::add) {
68+
scope 15 (inlined std::ptr::mut_ptr::<impl *mut T>::add) {
6769
}
6870
}
6971
scope 8 (inlined <NonNull<[T]> as From<&[T]>>::from) {
@@ -79,11 +81,11 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
7981
}
8082
}
8183
}
82-
scope 15 (inlined <std::slice::Iter<'_, T> as Iterator>::enumerate) {
83-
scope 16 (inlined Enumerate::<std::slice::Iter<'_, T>>::new) {
84+
scope 16 (inlined <std::slice::Iter<'_, T> as Iterator>::enumerate) {
85+
scope 17 (inlined Enumerate::<std::slice::Iter<'_, T>>::new) {
8486
}
8587
}
86-
scope 17 (inlined <Enumerate<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) {
88+
scope 18 (inlined <Enumerate<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) {
8789
}
8890

8991
bb0: {

‎tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
3535
scope 7 {
3636
}
3737
scope 12 (inlined without_provenance::<T>) {
38+
scope 13 (inlined without_provenance_mut::<T>) {
39+
}
3840
}
39-
scope 13 (inlined NonNull::<T>::as_ptr) {
41+
scope 14 (inlined NonNull::<T>::as_ptr) {
4042
}
41-
scope 14 (inlined std::ptr::mut_ptr::<impl *mut T>::add) {
43+
scope 15 (inlined std::ptr::mut_ptr::<impl *mut T>::add) {
4244
}
4345
}
4446
scope 8 (inlined <NonNull<[T]> as From<&[T]>>::from) {
@@ -54,11 +56,11 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
5456
}
5557
}
5658
}
57-
scope 15 (inlined <std::slice::Iter<'_, T> as Iterator>::enumerate) {
58-
scope 16 (inlined Enumerate::<std::slice::Iter<'_, T>>::new) {
59+
scope 16 (inlined <std::slice::Iter<'_, T> as Iterator>::enumerate) {
60+
scope 17 (inlined Enumerate::<std::slice::Iter<'_, T>>::new) {
5961
}
6062
}
61-
scope 17 (inlined <Enumerate<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) {
63+
scope 18 (inlined <Enumerate<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) {
6264
}
6365

6466
bb0: {

‎tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () {
3232
scope 7 {
3333
}
3434
scope 12 (inlined without_provenance::<T>) {
35+
scope 13 (inlined without_provenance_mut::<T>) {
36+
}
3537
}
36-
scope 13 (inlined NonNull::<T>::as_ptr) {
38+
scope 14 (inlined NonNull::<T>::as_ptr) {
3739
}
38-
scope 14 (inlined std::ptr::mut_ptr::<impl *mut T>::add) {
40+
scope 15 (inlined std::ptr::mut_ptr::<impl *mut T>::add) {
3941
}
4042
}
4143
scope 8 (inlined <NonNull<[T]> as From<&[T]>>::from) {
@@ -51,7 +53,7 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () {
5153
}
5254
}
5355
}
54-
scope 15 (inlined <std::slice::Iter<'_, T> as IntoIterator>::into_iter) {
56+
scope 16 (inlined <std::slice::Iter<'_, T> as IntoIterator>::into_iter) {
5557
}
5658

5759
bb0: {

‎tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () {
3232
scope 7 {
3333
}
3434
scope 12 (inlined without_provenance::<T>) {
35+
scope 13 (inlined without_provenance_mut::<T>) {
36+
}
3537
}
36-
scope 13 (inlined NonNull::<T>::as_ptr) {
38+
scope 14 (inlined NonNull::<T>::as_ptr) {
3739
}
38-
scope 14 (inlined std::ptr::mut_ptr::<impl *mut T>::add) {
40+
scope 15 (inlined std::ptr::mut_ptr::<impl *mut T>::add) {
3941
}
4042
}
4143
scope 8 (inlined <NonNull<[T]> as From<&[T]>>::from) {
@@ -51,7 +53,7 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () {
5153
}
5254
}
5355
}
54-
scope 15 (inlined <std::slice::Iter<'_, T> as IntoIterator>::into_iter) {
56+
scope 16 (inlined <std::slice::Iter<'_, T> as IntoIterator>::into_iter) {
5557
}
5658

5759
bb0: {

‎tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
1818
scope 2 {
1919
debug x => _17;
2020
}
21-
scope 18 (inlined <Rev<std::slice::Iter<'_, T>> as Iterator>::next) {
21+
scope 19 (inlined <Rev<std::slice::Iter<'_, T>> as Iterator>::next) {
2222
let mut _14: &mut std::slice::Iter<'_, T>;
2323
}
2424
}
@@ -35,10 +35,12 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
3535
scope 7 {
3636
}
3737
scope 12 (inlined without_provenance::<T>) {
38+
scope 13 (inlined without_provenance_mut::<T>) {
39+
}
3840
}
39-
scope 13 (inlined NonNull::<T>::as_ptr) {
41+
scope 14 (inlined NonNull::<T>::as_ptr) {
4042
}
41-
scope 14 (inlined std::ptr::mut_ptr::<impl *mut T>::add) {
43+
scope 15 (inlined std::ptr::mut_ptr::<impl *mut T>::add) {
4244
}
4345
}
4446
scope 8 (inlined <NonNull<[T]> as From<&[T]>>::from) {
@@ -54,11 +56,11 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
5456
}
5557
}
5658
}
57-
scope 15 (inlined <std::slice::Iter<'_, T> as Iterator>::rev) {
58-
scope 16 (inlined Rev::<std::slice::Iter<'_, T>>::new) {
59+
scope 16 (inlined <std::slice::Iter<'_, T> as Iterator>::rev) {
60+
scope 17 (inlined Rev::<std::slice::Iter<'_, T>>::new) {
5961
}
6062
}
61-
scope 17 (inlined <Rev<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) {
63+
scope 18 (inlined <Rev<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) {
6264
}
6365

6466
bb0: {

‎tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
1818
scope 2 {
1919
debug x => _17;
2020
}
21-
scope 18 (inlined <Rev<std::slice::Iter<'_, T>> as Iterator>::next) {
21+
scope 19 (inlined <Rev<std::slice::Iter<'_, T>> as Iterator>::next) {
2222
let mut _14: &mut std::slice::Iter<'_, T>;
2323
}
2424
}
@@ -35,10 +35,12 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
3535
scope 7 {
3636
}
3737
scope 12 (inlined without_provenance::<T>) {
38+
scope 13 (inlined without_provenance_mut::<T>) {
39+
}
3840
}
39-
scope 13 (inlined NonNull::<T>::as_ptr) {
41+
scope 14 (inlined NonNull::<T>::as_ptr) {
4042
}
41-
scope 14 (inlined std::ptr::mut_ptr::<impl *mut T>::add) {
43+
scope 15 (inlined std::ptr::mut_ptr::<impl *mut T>::add) {
4244
}
4345
}
4446
scope 8 (inlined <NonNull<[T]> as From<&[T]>>::from) {
@@ -54,11 +56,11 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
5456
}
5557
}
5658
}
57-
scope 15 (inlined <std::slice::Iter<'_, T> as Iterator>::rev) {
58-
scope 16 (inlined Rev::<std::slice::Iter<'_, T>>::new) {
59+
scope 16 (inlined <std::slice::Iter<'_, T> as Iterator>::rev) {
60+
scope 17 (inlined Rev::<std::slice::Iter<'_, T>>::new) {
5961
}
6062
}
61-
scope 17 (inlined <Rev<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) {
63+
scope 18 (inlined <Rev<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) {
6264
}
6365

6466
bb0: {

0 commit comments

Comments
 (0)
Please sign in to comment.