From 0db865335513ea3a44349ef84bbd81cad89cbeed Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 24 Jan 2025 15:57:13 +0000 Subject: [PATCH 1/2] Start using pattern types in libcore --- .../src/debuginfo/metadata.rs | 13 ++- .../rustc_const_eval/src/interpret/call.rs | 3 + library/core/src/num/niche_types.rs | 102 +++++++----------- .../cast_fn_ptr_invalid_callee_ret.stderr | 2 +- .../cast_fn_ptr_invalid_caller_arg.stderr | 2 +- ...n.DataflowConstProp.32bit.panic-abort.diff | 2 +- ....DataflowConstProp.32bit.panic-unwind.diff | 2 +- ...n.DataflowConstProp.64bit.panic-abort.diff | 2 +- ....DataflowConstProp.64bit.panic-unwind.diff | 2 +- ...oxed_slice.main.GVN.32bit.panic-abort.diff | 2 +- ...xed_slice.main.GVN.32bit.panic-unwind.diff | 2 +- ...oxed_slice.main.GVN.64bit.panic-abort.diff | 2 +- ...xed_slice.main.GVN.64bit.panic-unwind.diff | 2 +- .../gvn_ptr_eq_with_constant.main.GVN.diff | 2 +- .../consts/const-eval/raw-bytes.32bit.stderr | 4 +- .../consts/const-eval/raw-bytes.64bit.stderr | 4 +- tests/ui/consts/const-eval/ub-nonnull.stderr | 4 +- tests/ui/lint/invalid_value.stderr | 2 - 18 files changed, 70 insertions(+), 84 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 5535ebe65859e..828407c135ebb 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -481,7 +481,18 @@ pub(crate) fn spanned_type_di_node<'ll, 'tcx>( AdtKind::Enum => enums::build_enum_type_di_node(cx, unique_type_id, span), }, ty::Tuple(_) => build_tuple_type_di_node(cx, unique_type_id), - _ => bug!("debuginfo: unexpected type in type_di_node(): {:?}", t), + ty::Pat(base, _) => return type_di_node(cx, base), + // FIXME(unsafe_binders): impl debug info + ty::UnsafeBinder(_) => unimplemented!(), + ty::Alias(..) + | ty::Param(_) + | ty::Bound(..) + | ty::Infer(_) + | ty::Placeholder(_) + | ty::CoroutineWitness(..) + | ty::Error(_) => { + bug!("debuginfo: unexpected type in type_di_node(): {:?}", t) + } }; { diff --git a/compiler/rustc_const_eval/src/interpret/call.rs b/compiler/rustc_const_eval/src/interpret/call.rs index 312ebe7ddd09d..f580e2d197e50 100644 --- a/compiler/rustc_const_eval/src/interpret/call.rs +++ b/compiler/rustc_const_eval/src/interpret/call.rs @@ -89,6 +89,9 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { let (_, field) = layout.non_1zst_field(self).unwrap(); self.unfold_transparent(field, may_unfold) } + ty::Pat(base, _) => self.layout_of(*base).expect( + "if the layout of a pattern type could be computed, so can the layout of its base", + ), // Not a transparent type, no further unfolding. _ => layout, } diff --git a/library/core/src/num/niche_types.rs b/library/core/src/num/niche_types.rs index 9ac0eb72bdcbc..42fc252f8d703 100644 --- a/library/core/src/num/niche_types.rs +++ b/library/core/src/num/niche_types.rs @@ -5,45 +5,33 @@ )] use crate::cmp::Ordering; -use crate::fmt; use crate::hash::{Hash, Hasher}; use crate::marker::StructuralPartialEq; +use crate::{fmt, pattern_type}; macro_rules! define_valid_range_type { ($( $(#[$m:meta])* - $vis:vis struct $name:ident($int:ident as $uint:ident in $low:literal..=$high:literal); + $vis:vis struct $name:ident($int:ident is $pat:pat); )+) => {$( - #[derive(Clone, Copy, Eq)] + #[derive(Clone, Copy)] #[repr(transparent)] - #[rustc_layout_scalar_valid_range_start($low)] - #[rustc_layout_scalar_valid_range_end($high)] $(#[$m])* - $vis struct $name($int); - - const _: () = { - // With the `valid_range` attributes, it's always specified as unsigned - assert!(<$uint>::MIN == 0); - let ulow: $uint = $low; - let uhigh: $uint = $high; - assert!(ulow <= uhigh); - - assert!(size_of::<$int>() == size_of::<$uint>()); - }; - + $vis struct $name(pattern_type!($int is $pat)); impl $name { #[inline] pub const fn new(val: $int) -> Option { - if (val as $uint) >= ($low as $uint) && (val as $uint) <= ($high as $uint) { - // SAFETY: just checked the inclusive range - Some(unsafe { $name(val) }) + #[allow(non_contiguous_range_endpoints)] + if let $pat = val { + // SAFETY: just checked that the value matches the pattern + Some(unsafe { $name(crate::mem::transmute(val)) }) } else { None } } /// Constructs an instance of this type from the underlying integer - /// primitive without checking whether its zero. + /// primitive without checking whether its valid. /// /// # Safety /// Immediate language UB if `val` is not within the valid range for this @@ -51,14 +39,13 @@ macro_rules! define_valid_range_type { #[inline] pub const unsafe fn new_unchecked(val: $int) -> Self { // SAFETY: Caller promised that `val` is within the valid range. - unsafe { $name(val) } + unsafe { $name(crate::mem::transmute(val)) } } #[inline] pub const fn as_inner(self) -> $int { - // SAFETY: This is a transparent wrapper, so unwrapping it is sound - // (Not using `.0` due to MCP#807.) - unsafe { crate::mem::transmute(self) } + // SAFETY: pattern types are always legal values of their base type + unsafe { crate::mem::transmute(self.0) } } } @@ -67,6 +54,8 @@ macro_rules! define_valid_range_type { // by . impl StructuralPartialEq for $name {} + impl Eq for $name {} + impl PartialEq for $name { #[inline] fn eq(&self, other: &Self) -> bool { @@ -104,7 +93,7 @@ macro_rules! define_valid_range_type { } define_valid_range_type! { - pub struct Nanoseconds(u32 as u32 in 0..=999_999_999); + pub struct Nanoseconds(u32 is 0..=999_999_999); } impl Nanoseconds { @@ -120,47 +109,32 @@ impl const Default for Nanoseconds { } } -define_valid_range_type! { - pub struct NonZeroU8Inner(u8 as u8 in 1..=0xff); - pub struct NonZeroU16Inner(u16 as u16 in 1..=0xff_ff); - pub struct NonZeroU32Inner(u32 as u32 in 1..=0xffff_ffff); - pub struct NonZeroU64Inner(u64 as u64 in 1..=0xffffffff_ffffffff); - pub struct NonZeroU128Inner(u128 as u128 in 1..=0xffffffffffffffff_ffffffffffffffff); - - pub struct NonZeroI8Inner(i8 as u8 in 1..=0xff); - pub struct NonZeroI16Inner(i16 as u16 in 1..=0xff_ff); - pub struct NonZeroI32Inner(i32 as u32 in 1..=0xffff_ffff); - pub struct NonZeroI64Inner(i64 as u64 in 1..=0xffffffff_ffffffff); - pub struct NonZeroI128Inner(i128 as u128 in 1..=0xffffffffffffffff_ffffffffffffffff); - - pub struct NonZeroCharInner(char as u32 in 1..=0x10ffff); -} +const HALF_USIZE: usize = usize::MAX >> 1; -#[cfg(target_pointer_width = "16")] -define_valid_range_type! { - pub struct UsizeNoHighBit(usize as usize in 0..=0x7fff); - pub struct NonZeroUsizeInner(usize as usize in 1..=0xffff); - pub struct NonZeroIsizeInner(isize as usize in 1..=0xffff); -} -#[cfg(target_pointer_width = "32")] define_valid_range_type! { - pub struct UsizeNoHighBit(usize as usize in 0..=0x7fff_ffff); - pub struct NonZeroUsizeInner(usize as usize in 1..=0xffff_ffff); - pub struct NonZeroIsizeInner(isize as usize in 1..=0xffff_ffff); -} -#[cfg(target_pointer_width = "64")] -define_valid_range_type! { - pub struct UsizeNoHighBit(usize as usize in 0..=0x7fff_ffff_ffff_ffff); - pub struct NonZeroUsizeInner(usize as usize in 1..=0xffff_ffff_ffff_ffff); - pub struct NonZeroIsizeInner(isize as usize in 1..=0xffff_ffff_ffff_ffff); -} + pub struct NonZeroU8Inner(u8 is 1..); + pub struct NonZeroU16Inner(u16 is 1..); + pub struct NonZeroU32Inner(u32 is 1..); + pub struct NonZeroU64Inner(u64 is 1..); + pub struct NonZeroU128Inner(u128 is 1..); -define_valid_range_type! { - pub struct U32NotAllOnes(u32 as u32 in 0..=0xffff_fffe); - pub struct I32NotAllOnes(i32 as u32 in 0..=0xffff_fffe); + pub struct NonZeroI8Inner(i8 is ..0 | 1..); + pub struct NonZeroI16Inner(i16 is ..0 | 1..); + pub struct NonZeroI32Inner(i32 is ..0 | 1..); + pub struct NonZeroI64Inner(i64 is ..0 | 1..); + pub struct NonZeroI128Inner(i128 is ..0 | 1..); + + pub struct UsizeNoHighBit(usize is 0..=HALF_USIZE); + pub struct NonZeroUsizeInner(usize is 1..); + pub struct NonZeroIsizeInner(isize is ..0 | 1..); + + pub struct U32NotAllOnes(u32 is 0..u32::MAX); + pub struct I32NotAllOnes(i32 is ..-1 | 0..); + + pub struct U64NotAllOnes(u64 is 0..u64::MAX); + pub struct I64NotAllOnes(i64 is ..-1 | 0..); - pub struct U64NotAllOnes(u64 as u64 in 0..=0xffff_ffff_ffff_fffe); - pub struct I64NotAllOnes(i64 as u64 in 0..=0xffff_ffff_ffff_fffe); + pub struct NonZeroCharInner(char is '\u{1}' ..= '\u{10ffff}'); } pub trait NotAllOnesHelper { @@ -181,7 +155,7 @@ impl NotAllOnesHelper for i64 { } define_valid_range_type! { - pub struct CodePointInner(u32 as u32 in 0..=0x10ffff); + pub struct CodePointInner(u32 is 0..=0x10ffff); } impl CodePointInner { diff --git a/src/tools/miri/tests/fail/validity/cast_fn_ptr_invalid_callee_ret.stderr b/src/tools/miri/tests/fail/validity/cast_fn_ptr_invalid_callee_ret.stderr index a00d167df2f70..6fc1bc01655cc 100644 --- a/src/tools/miri/tests/fail/validity/cast_fn_ptr_invalid_callee_ret.stderr +++ b/src/tools/miri/tests/fail/validity/cast_fn_ptr_invalid_callee_ret.stderr @@ -1,4 +1,4 @@ -error: Undefined Behavior: constructing invalid value at .0: encountered 0, but expected something greater or equal to 1 +error: Undefined Behavior: constructing invalid value at .0.0: encountered 0, but expected something greater or equal to 1 --> tests/fail/validity/cast_fn_ptr_invalid_callee_ret.rs:LL:CC | LL | f(); diff --git a/src/tools/miri/tests/fail/validity/cast_fn_ptr_invalid_caller_arg.stderr b/src/tools/miri/tests/fail/validity/cast_fn_ptr_invalid_caller_arg.stderr index c370e19ef313f..fa0c7dde677e7 100644 --- a/src/tools/miri/tests/fail/validity/cast_fn_ptr_invalid_caller_arg.stderr +++ b/src/tools/miri/tests/fail/validity/cast_fn_ptr_invalid_caller_arg.stderr @@ -1,4 +1,4 @@ -error: Undefined Behavior: constructing invalid value at .0: encountered 0, but expected something greater or equal to 1 +error: Undefined Behavior: constructing invalid value at .0.0: encountered 0, but expected something greater or equal to 1 --> tests/fail/validity/cast_fn_ptr_invalid_caller_arg.rs:LL:CC | LL | Call(_res = f(*ptr), ReturnTo(retblock), UnwindContinue()) diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff index 2c89670dcf7d7..9369720c6e5a6 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff @@ -45,7 +45,7 @@ StorageLive(_4); StorageLive(_5); StorageLive(_6); - _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); + _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..)); StorageLive(_7); _7 = const {0x1 as *const [bool; 0]}; _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff index 8fecfe224cc69..f20ecbe21d929 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff @@ -45,7 +45,7 @@ StorageLive(_4); StorageLive(_5); StorageLive(_6); - _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); + _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..)); StorageLive(_7); _7 = const {0x1 as *const [bool; 0]}; _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff index 976ea252c2f89..8751b0d193dd3 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff @@ -45,7 +45,7 @@ StorageLive(_4); StorageLive(_5); StorageLive(_6); - _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); + _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..)); StorageLive(_7); _7 = const {0x1 as *const [bool; 0]}; _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff index 6c59f5e3e2e86..d67f1a7dfc964 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff @@ -45,7 +45,7 @@ StorageLive(_4); StorageLive(_5); StorageLive(_6); - _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); + _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..)); StorageLive(_7); _7 = const {0x1 as *const [bool; 0]}; _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff index 1f9cf6d6aca83..df241d46f0115 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff @@ -46,7 +46,7 @@ StorageLive(_5); StorageLive(_6); - _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as std::num::NonZero (Transmute); -+ _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); ++ _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..)); StorageLive(_7); - _7 = copy _6 as *const [bool; 0] (Transmute); - _5 = NonNull::<[bool; 0]> { pointer: copy _7 }; diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff index a8760285fac11..b4fa37c704404 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff @@ -46,7 +46,7 @@ StorageLive(_5); StorageLive(_6); - _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as std::num::NonZero (Transmute); -+ _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); ++ _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..)); StorageLive(_7); - _7 = copy _6 as *const [bool; 0] (Transmute); - _5 = NonNull::<[bool; 0]> { pointer: copy _7 }; diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff index c398ae70a1a3e..fde840b4b7616 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff @@ -46,7 +46,7 @@ StorageLive(_5); StorageLive(_6); - _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as std::num::NonZero (Transmute); -+ _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); ++ _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..)); StorageLive(_7); - _7 = copy _6 as *const [bool; 0] (Transmute); - _5 = NonNull::<[bool; 0]> { pointer: copy _7 }; diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff index 02934c02587d2..cf9c9a852b441 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff @@ -46,7 +46,7 @@ StorageLive(_5); StorageLive(_6); - _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as std::num::NonZero (Transmute); -+ _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); ++ _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..)); StorageLive(_7); - _7 = copy _6 as *const [bool; 0] (Transmute); - _5 = NonNull::<[bool; 0]> { pointer: copy _7 }; diff --git a/tests/mir-opt/gvn_ptr_eq_with_constant.main.GVN.diff b/tests/mir-opt/gvn_ptr_eq_with_constant.main.GVN.diff index f56af33ea603f..5b8fb659eff12 100644 --- a/tests/mir-opt/gvn_ptr_eq_with_constant.main.GVN.diff +++ b/tests/mir-opt/gvn_ptr_eq_with_constant.main.GVN.diff @@ -42,7 +42,7 @@ StorageLive(_3); - _3 = const std::ptr::Alignment::of::::{constant#0} as std::num::NonZero (Transmute); - _2 = copy _3 as *mut u8 (Transmute); -+ _3 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); ++ _3 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..)); + _2 = const {0x1 as *mut u8}; StorageDead(_3); StorageLive(_4); diff --git a/tests/ui/consts/const-eval/raw-bytes.32bit.stderr b/tests/ui/consts/const-eval/raw-bytes.32bit.stderr index 2861f82ec53b1..be3b539b269a0 100644 --- a/tests/ui/consts/const-eval/raw-bytes.32bit.stderr +++ b/tests/ui/consts/const-eval/raw-bytes.32bit.stderr @@ -64,7 +64,7 @@ LL | const NULL_PTR: NonNull = unsafe { mem::transmute(0usize) }; 00 00 00 00 │ .... } -error[E0080]: constructing invalid value at .0: encountered 0, but expected something greater or equal to 1 +error[E0080]: constructing invalid value at .0.0: encountered 0, but expected something greater or equal to 1 --> $DIR/raw-bytes.rs:61:1 | LL | const NULL_U8: NonZero = unsafe { mem::transmute(0u8) }; @@ -75,7 +75,7 @@ LL | const NULL_U8: NonZero = unsafe { mem::transmute(0u8) }; 00 │ . } -error[E0080]: constructing invalid value at .0: encountered 0, but expected something greater or equal to 1 +error[E0080]: constructing invalid value at .0.0: encountered 0, but expected something greater or equal to 1 --> $DIR/raw-bytes.rs:63:1 | LL | const NULL_USIZE: NonZero = unsafe { mem::transmute(0usize) }; diff --git a/tests/ui/consts/const-eval/raw-bytes.64bit.stderr b/tests/ui/consts/const-eval/raw-bytes.64bit.stderr index 8e6dc66a40ee1..9950ac726ca76 100644 --- a/tests/ui/consts/const-eval/raw-bytes.64bit.stderr +++ b/tests/ui/consts/const-eval/raw-bytes.64bit.stderr @@ -64,7 +64,7 @@ LL | const NULL_PTR: NonNull = unsafe { mem::transmute(0usize) }; 00 00 00 00 00 00 00 00 │ ........ } -error[E0080]: constructing invalid value at .0: encountered 0, but expected something greater or equal to 1 +error[E0080]: constructing invalid value at .0.0: encountered 0, but expected something greater or equal to 1 --> $DIR/raw-bytes.rs:61:1 | LL | const NULL_U8: NonZero = unsafe { mem::transmute(0u8) }; @@ -75,7 +75,7 @@ LL | const NULL_U8: NonZero = unsafe { mem::transmute(0u8) }; 00 │ . } -error[E0080]: constructing invalid value at .0: encountered 0, but expected something greater or equal to 1 +error[E0080]: constructing invalid value at .0.0: encountered 0, but expected something greater or equal to 1 --> $DIR/raw-bytes.rs:63:1 | LL | const NULL_USIZE: NonZero = unsafe { mem::transmute(0usize) }; diff --git a/tests/ui/consts/const-eval/ub-nonnull.stderr b/tests/ui/consts/const-eval/ub-nonnull.stderr index e4486e3c500b9..be5c6f77a0877 100644 --- a/tests/ui/consts/const-eval/ub-nonnull.stderr +++ b/tests/ui/consts/const-eval/ub-nonnull.stderr @@ -15,7 +15,7 @@ error[E0080]: in-bounds pointer arithmetic failed: attempting to offset pointer LL | let out_of_bounds_ptr = &ptr[255]; | ^^^^^^^^^ evaluation of `OUT_OF_BOUNDS_PTR` failed here -error[E0080]: constructing invalid value at .0: encountered 0, but expected something greater or equal to 1 +error[E0080]: constructing invalid value at .0.0: encountered 0, but expected something greater or equal to 1 --> $DIR/ub-nonnull.rs:26:1 | LL | const NULL_U8: NonZero = unsafe { mem::transmute(0u8) }; @@ -26,7 +26,7 @@ LL | const NULL_U8: NonZero = unsafe { mem::transmute(0u8) }; HEX_DUMP } -error[E0080]: constructing invalid value at .0: encountered 0, but expected something greater or equal to 1 +error[E0080]: constructing invalid value at .0.0: encountered 0, but expected something greater or equal to 1 --> $DIR/ub-nonnull.rs:28:1 | LL | const NULL_USIZE: NonZero = unsafe { mem::transmute(0usize) }; diff --git a/tests/ui/lint/invalid_value.stderr b/tests/ui/lint/invalid_value.stderr index cc6a2a1c8e532..3dd2a521ff2e1 100644 --- a/tests/ui/lint/invalid_value.stderr +++ b/tests/ui/lint/invalid_value.stderr @@ -333,7 +333,6 @@ LL | let _val: (NonZero, i32) = mem::uninitialized(); | = note: `std::num::NonZero` must be non-null = note: because `core::num::niche_types::NonZeroU32Inner` must be non-null - = note: integers must be initialized error: the type `*const dyn Send` does not permit zero-initialization --> $DIR/invalid_value.rs:97:37 @@ -430,7 +429,6 @@ note: because `std::num::NonZero` must be non-null (in this field of the on LL | Banana(NonZero), | ^^^^^^^^^^^^ = note: because `core::num::niche_types::NonZeroU32Inner` must be non-null - = note: integers must be initialized error: the type `bool` does not permit being left uninitialized --> $DIR/invalid_value.rs:111:26 From 3727ca460f699baa135f714dd65309410f5cafbd Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Sat, 17 May 2025 14:35:25 +0000 Subject: [PATCH 2/2] Use `!null` pattern type in libcore Use `!null` pattern type in libcore --- .../example/mini_core.rs | 60 +++- .../example/mini_core_hello_world.rs | 13 +- compiler/rustc_codegen_ssa/src/base.rs | 9 +- .../rustc_const_eval/src/interpret/visitor.rs | 7 +- compiler/rustc_middle/src/ty/layout.rs | 4 +- .../src/elaborate_box_derefs.rs | 33 +- compiler/rustc_mir_transform/src/validate.rs | 17 +- library/core/src/ptr/non_null.rs | 29 +- library/std/src/os/unix/io/tests.rs | 3 +- library/std/src/os/wasi/io/tests.rs | 3 +- .../src/transmute/transmute_undefined_repr.rs | 4 + tests/auxiliary/minicore.rs | 9 + tests/codegen-llvm/loads.rs | 2 +- tests/mir-opt/box_expr.rs | 4 +- .../boxes.main.GVN.panic-abort.diff | 17 +- .../boxes.main.GVN.panic-unwind.diff | 17 +- .../transmute.unreachable_box.GVN.32bit.diff | 6 +- .../transmute.unreachable_box.GVN.64bit.diff | 6 +- ...n.DataflowConstProp.32bit.panic-abort.diff | 14 +- ....DataflowConstProp.32bit.panic-unwind.diff | 14 +- ...n.DataflowConstProp.64bit.panic-abort.diff | 14 +- ....DataflowConstProp.64bit.panic-unwind.diff | 14 +- ...oxed_slice.main.GVN.32bit.panic-abort.diff | 18 +- ...xed_slice.main.GVN.32bit.panic-unwind.diff | 18 +- ...oxed_slice.main.GVN.64bit.panic-abort.diff | 18 +- ...xed_slice.main.GVN.64bit.panic-unwind.diff | 18 +- ...reachable_box.DataflowConstProp.32bit.diff | 4 +- ...reachable_box.DataflowConstProp.64bit.diff | 4 +- ...ng_operand.test.GVN.32bit.panic-abort.diff | 132 ++++---- ...g_operand.test.GVN.32bit.panic-unwind.diff | 2 +- ...ng_operand.test.GVN.64bit.panic-abort.diff | 132 ++++---- ...g_operand.test.GVN.64bit.panic-unwind.diff | 2 +- ..._debuginfo.pointee.ElaborateBoxDerefs.diff | 2 +- .../gvn_ptr_eq_with_constant.main.GVN.diff | 36 ++- ...ric_rust_call.call.Inline.panic-abort.diff | 4 +- ...ic_rust_call.call.Inline.panic-unwind.diff | 4 +- ...inline_box_fn.call.Inline.panic-abort.diff | 4 +- ...nline_box_fn.call.Inline.panic-unwind.diff | 4 +- .../inline_shims.drop.Inline.panic-abort.diff | 40 +-- ...67_inline_as_ref_as_mut.b.Inline.after.mir | 4 +- ...67_inline_as_ref_as_mut.d.Inline.after.mir | 4 +- .../unsized_argument.caller.Inline.diff | 2 +- ...inhabited.LowerIntrinsics.panic-abort.diff | 2 +- ...nhabited.LowerIntrinsics.panic-unwind.diff | 2 +- ...ace.PreCodegen.after.32bit.panic-abort.mir | 24 +- ...ce.PreCodegen.after.32bit.panic-unwind.mir | 24 +- ...ace.PreCodegen.after.64bit.panic-abort.mir | 24 +- ...ce.PreCodegen.after.64bit.panic-unwind.mir | 24 +- .../loops.vec_move.PreCodegen.after.mir | 158 +++++----- ...ted_loop.PreCodegen.after.panic-unwind.mir | 122 ++++---- ...ard_loop.PreCodegen.after.panic-unwind.mir | 210 +++++++------ ...rse_loop.PreCodegen.after.panic-unwind.mir | 286 +++++++++--------- ...ext_back.PreCodegen.after.panic-unwind.mir | 68 +++-- ...ter_next.PreCodegen.after.panic-unwind.mir | 14 +- ..._to_slice.PreCodegen.after.panic-abort.mir | 34 ++- ...to_slice.PreCodegen.after.panic-unwind.mir | 34 ++- ...fg-pre-optimizations.after.panic-abort.mir | 2 +- ...g-pre-optimizations.after.panic-unwind.mir | 2 +- tests/ui/abi/compatibility.rs | 14 +- .../consts/const-eval/raw-bytes.32bit.stderr | 4 +- .../consts/const-eval/raw-bytes.64bit.stderr | 4 +- tests/ui/consts/const-eval/ub-nonnull.stderr | 6 +- tests/ui/lint/invalid_value.stderr | 2 - tests/ui/mir/ssa-analysis-regression-50041.rs | 6 +- 64 files changed, 1008 insertions(+), 809 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/example/mini_core.rs b/compiler/rustc_codegen_cranelift/example/mini_core.rs index 304d0d648561e..4de60f3a446b4 100644 --- a/compiler/rustc_codegen_cranelift/example/mini_core.rs +++ b/compiler/rustc_codegen_cranelift/example/mini_core.rs @@ -8,6 +8,7 @@ rustc_attrs, rustc_private, transparent_unions, + pattern_types, auto_traits, freeze_impls, thread_local @@ -15,6 +16,30 @@ #![no_core] #![allow(dead_code, internal_features, ambiguous_wide_pointer_comparisons)] +#[lang = "pointee_trait"] +pub trait Pointee: PointeeSized { + #[lang = "metadata_type"] + // needed so that layout_of will return `TooGeneric` instead of `Unknown` + // when asked for the layout of `*const T`. Which is important for making + // transmutes between raw pointers (and especially pattern types of raw pointers) + // work. + type Metadata: Copy + Sync + Unpin + Freeze; +} + +#[lang = "dyn_metadata"] +pub struct DynMetadata { + _vtable_ptr: NonNull, + _phantom: PhantomData, +} + +unsafe extern "C" { + /// Opaque type for accessing vtables. + /// + /// Private implementation detail of `DynMetadata::size_of` etc. + /// There is conceptually not actually any Abstract Machine memory behind this pointer. + type VTable; +} + #[lang = "pointee_sized"] pub trait PointeeSized {} @@ -105,7 +130,7 @@ unsafe impl<'a, T: PointeeSized> Sync for &'a T {} unsafe impl Sync for [T; N] {} #[lang = "freeze"] -unsafe auto trait Freeze {} +pub unsafe auto trait Freeze {} unsafe impl Freeze for PhantomData {} unsafe impl Freeze for *const T {} @@ -568,10 +593,24 @@ pub trait Deref { fn deref(&self) -> &Self::Target; } +#[rustc_builtin_macro(pattern_type)] +#[macro_export] +macro_rules! pattern_type { + ($($arg:tt)*) => { + /* compiler built-in */ + }; +} + +impl CoerceUnsized for pattern_type!(*const T is !null) where + T: Unsize +{ +} + +impl, U> DispatchFromDyn for pattern_type!(T is !null) {} + #[repr(transparent)] -#[rustc_layout_scalar_valid_range_start(1)] #[rustc_nonnull_optimization_guaranteed] -pub struct NonNull(pub *const T); +pub struct NonNull(pub pattern_type!(*const T is !null)); impl CoerceUnsized> for NonNull where T: Unsize {} impl DispatchFromDyn> for NonNull where T: Unsize {} @@ -598,7 +637,16 @@ impl Box { let size = size_of::(); let ptr = libc::malloc(size); intrinsics::copy(&val as *const T as *const u8, ptr, size); - Box(Unique { pointer: NonNull(ptr as *const T), _marker: PhantomData }, Global) + Box( + Unique { + pointer: NonNull(intrinsics::transmute::< + *mut u8, + pattern_type!(*const T is !null), + >(ptr)), + _marker: PhantomData, + }, + Global, + ) } } } @@ -607,7 +655,9 @@ impl Drop for Box { fn drop(&mut self) { // inner value is dropped by compiler unsafe { - libc::free(self.0.pointer.0 as *mut u8); + libc::free(intrinsics::transmute::( + self.0.pointer.0, + ) as *mut u8); } } } diff --git a/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs b/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs index a9388814a7f59..fd98578bcbb11 100644 --- a/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs +++ b/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs @@ -6,6 +6,7 @@ extern_types, thread_local, repr_simd, + pattern_types, rustc_private )] #![no_core] @@ -159,7 +160,10 @@ extern "C" fn bool_struct_in_11(_arg0: bool_11) {} #[allow(unreachable_code)] // FIXME false positive fn main() { - take_unique(Unique { pointer: unsafe { NonNull(1 as *mut ()) }, _marker: PhantomData }); + take_unique(Unique { + pointer: unsafe { NonNull(intrinsics::transmute(1 as *mut ())) }, + _marker: PhantomData, + }); take_f32(0.1); call_return_u128_pair(); @@ -225,7 +229,12 @@ fn main() { let noisy_unsized_drop = const { intrinsics::needs_drop::() }; assert!(noisy_unsized_drop); - Unique { pointer: NonNull(1 as *mut &str), _marker: PhantomData } as Unique; + Unique { + pointer: NonNull(intrinsics::transmute::<_, pattern_type!(*const &str is !null)>( + 1 as *mut &str, + )), + _marker: PhantomData, + } as Unique; struct MyDst(T); diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index ed2815b06c18a..fcfa7157cf4c3 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -27,7 +27,7 @@ use rustc_middle::mir::interpret::ErrorHandled; use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem, MonoItemPartitions}; use rustc_middle::query::Providers; use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutOf, TyAndLayout}; -use rustc_middle::ty::{self, Instance, Ty, TyCtxt}; +use rustc_middle::ty::{self, Instance, PatternKind, Ty, TyCtxt}; use rustc_middle::{bug, span_bug}; use rustc_session::Session; use rustc_session::config::{self, CrateType, EntryFnType}; @@ -275,6 +275,13 @@ pub(crate) fn coerce_unsized_into<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( let src_ty = src.layout.ty; let dst_ty = dst.layout.ty; match (src_ty.kind(), dst_ty.kind()) { + (&ty::Pat(s, sp), &ty::Pat(d, dp)) + if let (PatternKind::NotNull, PatternKind::NotNull) = (*sp, *dp) => + { + let src = src.project_type(bx, s); + let dst = dst.project_type(bx, d); + coerce_unsized_into(bx, src, dst) + } (&ty::Ref(..), &ty::Ref(..) | &ty::RawPtr(..)) | (&ty::RawPtr(..), &ty::RawPtr(..)) => { let (base, info) = match bx.load_operand(src).val { OperandValue::Pair(base, info) => unsize_ptr(bx, base, src_ty, dst_ty, Some(info)), diff --git a/compiler/rustc_const_eval/src/interpret/visitor.rs b/compiler/rustc_const_eval/src/interpret/visitor.rs index b5de10c7dcd11..9fb31ffdd303d 100644 --- a/compiler/rustc_const_eval/src/interpret/visitor.rs +++ b/compiler/rustc_const_eval/src/interpret/visitor.rs @@ -137,7 +137,12 @@ pub trait ValueVisitor<'tcx, M: Machine<'tcx>>: Sized { // ... that contains a `NonNull`... (gladly, only a single field here) assert_eq!(nonnull_ptr.layout().fields.count(), 1); - let raw_ptr = self.ecx().project_field(&nonnull_ptr, FieldIdx::ZERO)?; // the actual raw ptr + let pat_ty = self.ecx().project_field(&nonnull_ptr, FieldIdx::ZERO)?; // `*mut T is !null` + let base = match *pat_ty.layout().ty.kind() { + ty::Pat(base, _) => self.ecx().layout_of(base)?, + _ => unreachable!(), + }; + let raw_ptr = pat_ty.transmute(base, self.ecx())?; // The actual raw pointer // ... whose only field finally is a raw ptr we can dereference. self.visit_box(ty, &raw_ptr)?; diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 621d5c31e685e..a2d951366b012 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -17,7 +17,7 @@ use rustc_session::config::OptLevel; use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym}; use rustc_target::callconv::FnAbi; use rustc_target::spec::{HasTargetSpec, HasX86AbiOpt, Target, X86Abi}; -use tracing::debug; +use tracing::{debug, instrument, trace}; use {rustc_abi as abi, rustc_hir as hir}; use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags; @@ -380,6 +380,7 @@ pub enum SizeSkeleton<'tcx> { } impl<'tcx> SizeSkeleton<'tcx> { + #[instrument(level = "trace", skip(tcx, typing_env), ret)] pub fn compute( ty: Ty<'tcx>, tcx: TyCtxt<'tcx>, @@ -429,6 +430,7 @@ impl<'tcx> SizeSkeleton<'tcx> { }, || {}, ); + trace!(?tail); match tail.kind() { ty::Param(_) | ty::Alias(ty::Projection | ty::Inherent, _) => { diff --git a/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs b/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs index 808be19cbd817..b0e1e3846449d 100644 --- a/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs +++ b/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs @@ -10,7 +10,7 @@ use rustc_index::{IndexVec, indexvec}; use rustc_middle::mir::visit::MutVisitor; use rustc_middle::mir::*; use rustc_middle::span_bug; -use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_middle::ty::{self, PatternKind, Ty, TyCtxt}; use crate::patch::MirPatch; @@ -20,21 +20,27 @@ fn build_ptr_tys<'tcx>( pointee: Ty<'tcx>, unique_def: ty::AdtDef<'tcx>, nonnull_def: ty::AdtDef<'tcx>, -) -> (Ty<'tcx>, Ty<'tcx>, Ty<'tcx>) { +) -> (Ty<'tcx>, Ty<'tcx>, Ty<'tcx>, Ty<'tcx>) { let args = tcx.mk_args(&[pointee.into()]); let unique_ty = Ty::new_adt(tcx, unique_def, args); let nonnull_ty = Ty::new_adt(tcx, nonnull_def, args); let ptr_ty = Ty::new_imm_ptr(tcx, pointee); + let pat_ty = Ty::new_pat(tcx, ptr_ty, tcx.mk_pat(PatternKind::NotNull)); - (unique_ty, nonnull_ty, ptr_ty) + (unique_ty, nonnull_ty, pat_ty, ptr_ty) } /// Constructs the projection needed to access a Box's pointer pub(super) fn build_projection<'tcx>( unique_ty: Ty<'tcx>, nonnull_ty: Ty<'tcx>, -) -> [PlaceElem<'tcx>; 2] { - [PlaceElem::Field(FieldIdx::ZERO, unique_ty), PlaceElem::Field(FieldIdx::ZERO, nonnull_ty)] + pat_ty: Ty<'tcx>, +) -> [PlaceElem<'tcx>; 3] { + [ + PlaceElem::Field(FieldIdx::ZERO, unique_ty), + PlaceElem::Field(FieldIdx::ZERO, nonnull_ty), + PlaceElem::Field(FieldIdx::ZERO, pat_ty), + ] } struct ElaborateBoxDerefVisitor<'a, 'tcx> { @@ -66,7 +72,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for ElaborateBoxDerefVisitor<'a, 'tcx> { { let source_info = self.local_decls[place.local].source_info; - let (unique_ty, nonnull_ty, ptr_ty) = + let (unique_ty, nonnull_ty, pat_ty, ptr_ty) = build_ptr_tys(tcx, boxed_ty, self.unique_def, self.nonnull_def); let ptr_local = self.patch.new_temp(ptr_ty, source_info.span); @@ -78,7 +84,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for ElaborateBoxDerefVisitor<'a, 'tcx> { CastKind::Transmute, Operand::Copy( Place::from(place.local) - .project_deeper(&build_projection(unique_ty, nonnull_ty), tcx), + .project_deeper(&build_projection(unique_ty, nonnull_ty, pat_ty), tcx), ), ptr_ty, ), @@ -101,7 +107,9 @@ impl<'a, 'tcx> MutVisitor<'tcx> for ElaborateBoxDerefVisitor<'a, 'tcx> { && let ty::Adt(box_adt, box_args) = Ty::new_box(tcx, pointee).kind() { let args = tcx.mk_args(&[pointee.into()]); - let (unique_ty, nonnull_ty, ptr_ty) = + // We skip the pointer type by directly transmuting from the `*const u8` of + // `ShallowInitBox` to the pattern type that will get placed inside `NonNull` + let (unique_ty, nonnull_ty, pat_ty, _ptr_ty) = build_ptr_tys(tcx, pointee, self.unique_def, self.nonnull_def); let adt_kind = |def: ty::AdtDef<'tcx>, args| { Box::new(AggregateKind::Adt(def.did(), VariantIdx::ZERO, args, None, None)) @@ -114,11 +122,11 @@ impl<'a, 'tcx> MutVisitor<'tcx> for ElaborateBoxDerefVisitor<'a, 'tcx> { })) }; - let constptr = self.patch.new_temp(ptr_ty, source_info.span); + let constptr = self.patch.new_temp(pat_ty, source_info.span); self.patch.add_assign( location, constptr.into(), - Rvalue::Cast(CastKind::Transmute, mutptr_to_u8.clone(), ptr_ty), + Rvalue::Cast(CastKind::Transmute, mutptr_to_u8.clone(), pat_ty), ); let nonnull = self.patch.new_temp(nonnull_ty, source_info.span); @@ -199,10 +207,11 @@ impl<'tcx> crate::MirPass<'tcx> for ElaborateBoxDerefs { let new_projections = new_projections.get_or_insert_with(|| base.projection.to_vec()); - let (unique_ty, nonnull_ty, ptr_ty) = + let (unique_ty, nonnull_ty, pat_ty, ptr_ty) = build_ptr_tys(tcx, boxed_ty, unique_def, nonnull_def); - new_projections.extend_from_slice(&build_projection(unique_ty, nonnull_ty)); + new_projections + .extend_from_slice(&build_projection(unique_ty, nonnull_ty, pat_ty)); // While we can't project into `NonNull<_>` in a basic block // due to MCP#807, this is debug info where it's fine. new_projections.push(PlaceElem::Field(FieldIdx::ZERO, ptr_ty)); diff --git a/compiler/rustc_mir_transform/src/validate.rs b/compiler/rustc_mir_transform/src/validate.rs index 5a9018a62c574..b141d706e3cc0 100644 --- a/compiler/rustc_mir_transform/src/validate.rs +++ b/compiler/rustc_mir_transform/src/validate.rs @@ -669,24 +669,25 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { let fail_out_of_bounds = |this: &mut Self, location| { this.fail(location, format!("Out of bounds field {f:?} for {parent_ty:?}")); }; + + let kind = match parent_ty.ty.kind() { + &ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => { + self.tcx.type_of(def_id).instantiate(self.tcx, args).kind() + } + kind => kind, + }; + let check_equal = |this: &mut Self, location, f_ty| { if !this.mir_assign_valid_types(ty, f_ty) { this.fail( location, format!( - "Field projection `{place_ref:?}.{f:?}` specified type `{ty}`, but actual type is `{f_ty}`" + "Field projection `{place_ref:?}.{f:?}` specified type `{ty}`, but actual field type of `{kind:?}` is `{f_ty}`" ) ) } }; - let kind = match parent_ty.ty.kind() { - &ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => { - self.tcx.type_of(def_id).instantiate(self.tcx, args).kind() - } - kind => kind, - }; - match kind { ty::Tuple(fields) => { let Some(f_ty) = fields.get(f.as_usize()) else { diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index a762e969b52dc..22ecec92068c6 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -1,6 +1,6 @@ use crate::cmp::Ordering; use crate::marker::{Destruct, PointeeSized, Unsize}; -use crate::mem::{MaybeUninit, SizedTypeProperties}; +use crate::mem::{MaybeUninit, SizedTypeProperties, transmute}; use crate::num::NonZero; use crate::ops::{CoerceUnsized, DispatchFromDyn}; use crate::pin::PinCoerceUnsized; @@ -69,13 +69,10 @@ use crate::{fmt, hash, intrinsics, mem, ptr}; /// [null pointer optimization]: crate::option#representation #[stable(feature = "nonnull", since = "1.25.0")] #[repr(transparent)] -#[rustc_layout_scalar_valid_range_start(1)] #[rustc_nonnull_optimization_guaranteed] #[rustc_diagnostic_item = "NonNull"] pub struct NonNull { - // Remember to use `.as_ptr()` instead of `.pointer`, as field projecting to - // this is banned by . - pointer: *const T, + pointer: crate::pattern_type!(*const T is !null), } /// `NonNull` pointers are not `Send` because the data they reference may be aliased. @@ -99,9 +96,9 @@ impl NonNull { #[must_use] #[inline] pub const fn without_provenance(addr: NonZero) -> Self { - let pointer = crate::ptr::without_provenance(addr.get()); + let pointer: *const T = crate::ptr::without_provenance(addr.get()); // SAFETY: we know `addr` is non-zero. - unsafe { NonNull { pointer } } + unsafe { NonNull { pointer: transmute(pointer) } } } /// Creates a new `NonNull` that is dangling, but well-aligned. @@ -238,7 +235,7 @@ impl NonNull { "NonNull::new_unchecked requires that the pointer is non-null", (ptr: *mut () = ptr as *mut ()) => !ptr.is_null() ); - NonNull { pointer: ptr as _ } + NonNull { pointer: transmute(ptr) } } } @@ -281,7 +278,7 @@ impl NonNull { #[inline] pub const fn from_ref(r: &T) -> Self { // SAFETY: A reference cannot be null. - unsafe { NonNull { pointer: r as *const T } } + unsafe { NonNull { pointer: transmute(r as *const T) } } } /// Converts a mutable reference to a `NonNull` pointer. @@ -290,7 +287,7 @@ impl NonNull { #[inline] pub const fn from_mut(r: &mut T) -> Self { // SAFETY: A mutable reference cannot be null. - unsafe { NonNull { pointer: r as *mut T } } + unsafe { NonNull { pointer: transmute(r as *mut T) } } } /// Performs the same functionality as [`std::ptr::from_raw_parts`], except that a @@ -501,7 +498,7 @@ impl NonNull { #[inline] pub const fn cast(self) -> NonNull { // SAFETY: `self` is a `NonNull` pointer which is necessarily non-null - unsafe { NonNull { pointer: self.as_ptr() as *mut U } } + unsafe { NonNull { pointer: transmute(self.as_ptr() as *mut U) } } } /// Try to cast to a pointer of another type by checking alignment. @@ -580,7 +577,7 @@ impl NonNull { // Additionally safety contract of `offset` guarantees that the resulting pointer is // pointing to an allocation, there can't be an allocation at null, thus it's safe to // construct `NonNull`. - unsafe { NonNull { pointer: intrinsics::offset(self.as_ptr(), count) } } + unsafe { NonNull { pointer: transmute(intrinsics::offset(self.as_ptr(), count)) } } } /// Calculates the offset from a pointer in bytes. @@ -604,7 +601,7 @@ impl NonNull { // Additionally safety contract of `offset` guarantees that the resulting pointer is // pointing to an allocation, there can't be an allocation at null, thus it's safe to // construct `NonNull`. - unsafe { NonNull { pointer: self.as_ptr().byte_offset(count) } } + unsafe { NonNull { pointer: transmute(self.as_ptr().byte_offset(count)) } } } /// Adds an offset to a pointer (convenience for `.offset(count as isize)`). @@ -656,7 +653,7 @@ impl NonNull { // Additionally safety contract of `offset` guarantees that the resulting pointer is // pointing to an allocation, there can't be an allocation at null, thus it's safe to // construct `NonNull`. - unsafe { NonNull { pointer: intrinsics::offset(self.as_ptr(), count) } } + unsafe { NonNull { pointer: transmute(intrinsics::offset(self.as_ptr(), count)) } } } /// Calculates the offset from a pointer in bytes (convenience for `.byte_offset(count as isize)`). @@ -680,7 +677,7 @@ impl NonNull { // Additionally safety contract of `add` guarantees that the resulting pointer is pointing // to an allocation, there can't be an allocation at null, thus it's safe to construct // `NonNull`. - unsafe { NonNull { pointer: self.as_ptr().byte_add(count) } } + unsafe { NonNull { pointer: transmute(self.as_ptr().byte_add(count)) } } } /// Subtracts an offset from a pointer (convenience for @@ -762,7 +759,7 @@ impl NonNull { // Additionally safety contract of `sub` guarantees that the resulting pointer is pointing // to an allocation, there can't be an allocation at null, thus it's safe to construct // `NonNull`. - unsafe { NonNull { pointer: self.as_ptr().byte_sub(count) } } + unsafe { NonNull { pointer: transmute(self.as_ptr().byte_sub(count)) } } } /// Calculates the distance between two pointers within the same allocation. The returned value is in diff --git a/library/std/src/os/unix/io/tests.rs b/library/std/src/os/unix/io/tests.rs index fc147730578ac..ce5e7aac5a99d 100644 --- a/library/std/src/os/unix/io/tests.rs +++ b/library/std/src/os/unix/io/tests.rs @@ -2,8 +2,7 @@ use crate::os::unix::io::RawFd; #[test] fn test_raw_fd_layout() { - // `OwnedFd` and `BorrowedFd` use `rustc_layout_scalar_valid_range_start` - // and `rustc_layout_scalar_valid_range_end`, with values that depend on + // `OwnedFd` and `BorrowedFd` use pattern types, with ranges that depend on // the bit width of `RawFd`. If this ever changes, those values will need // to be updated. assert_eq!(size_of::(), 4); diff --git a/library/std/src/os/wasi/io/tests.rs b/library/std/src/os/wasi/io/tests.rs index c5c6a19a6c885..d18b9fe10cab0 100644 --- a/library/std/src/os/wasi/io/tests.rs +++ b/library/std/src/os/wasi/io/tests.rs @@ -2,8 +2,7 @@ use crate::os::wasi::io::RawFd; #[test] fn test_raw_fd_layout() { - // `OwnedFd` and `BorrowedFd` use `rustc_layout_scalar_valid_range_start` - // and `rustc_layout_scalar_valid_range_end`, with values that depend on + // `OwnedFd` and `BorrowedFd` use pattern types with ranges that depend on // the bit width of `RawFd`. If this ever changes, those values will need // to be updated. assert_eq!(size_of::(), 4); diff --git a/src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs b/src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs index 3e6aae475ecce..c097f7773099a 100644 --- a/src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs +++ b/src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs @@ -242,6 +242,10 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx> loop { ty = cx.tcx.try_normalize_erasing_regions(cx.typing_env(), ty).unwrap_or(ty); return match *ty.kind() { + ty::Pat(base, _) => { + ty = base; + continue; + }, ty::Array(sub_ty, _) if matches!(sub_ty.kind(), ty::Int(_) | ty::Uint(_)) => { ReducedTy::TypeErasure { raw_ptr_only: false } }, diff --git a/tests/auxiliary/minicore.rs b/tests/auxiliary/minicore.rs index a974dee8a8389..4d2bbf1a181ca 100644 --- a/tests/auxiliary/minicore.rs +++ b/tests/auxiliary/minicore.rs @@ -22,6 +22,7 @@ auto_traits, freeze_impls, negative_impls, + pattern_types, rustc_attrs, decl_macro, f16, @@ -262,6 +263,14 @@ pub enum c_void { __variant2, } +#[rustc_builtin_macro(pattern_type)] +#[macro_export] +macro_rules! pattern_type { + ($($arg:tt)*) => { + /* compiler built-in */ + }; +} + #[lang = "const_param_ty"] #[diagnostic::on_unimplemented(message = "`{Self}` can't be used as a const parameter type")] pub trait ConstParamTy_ {} diff --git a/tests/codegen-llvm/loads.rs b/tests/codegen-llvm/loads.rs index 88d67642b7250..e19af7a3c2bc1 100644 --- a/tests/codegen-llvm/loads.rs +++ b/tests/codegen-llvm/loads.rs @@ -58,7 +58,7 @@ pub fn load_raw_pointer<'a>(x: &*const i32) -> *const i32 { // CHECK-LABEL: @load_box #[no_mangle] pub fn load_box<'a>(x: Box>) -> Box { - // CHECK: load ptr, ptr %{{.*}}, align [[PTR_ALIGNMENT]], !nonnull !{{[0-9]+}}, !align ![[ALIGN_4_META]], !noundef !{{[0-9]+}} + // CHECK: load ptr, ptr %{{.*}}, align [[PTR_ALIGNMENT]], !nonnull !{{[0-9]+}}, !noundef !{{[0-9]+}} *x } diff --git a/tests/mir-opt/box_expr.rs b/tests/mir-opt/box_expr.rs index 6299c98718094..327b02ac2a02f 100644 --- a/tests/mir-opt/box_expr.rs +++ b/tests/mir-opt/box_expr.rs @@ -6,11 +6,11 @@ // EMIT_MIR box_expr.main.ElaborateDrops.diff fn main() { // CHECK-LABEL: fn main( - // CHECK: [[ptr:_.*]] = move {{_.*}} as *const S (Transmute); + // CHECK: [[ptr:_.*]] = move {{_.*}} as (*const S) is !null (Transmute); // CHECK: [[nonnull:_.*]] = NonNull:: { pointer: move [[ptr]] }; // CHECK: [[unique:_.*]] = Unique:: { pointer: move [[nonnull]], _marker: const PhantomData:: }; // CHECK: [[box:_.*]] = Box::(move [[unique]], const std::alloc::Global); - // CHECK: [[ptr:_.*]] = copy (([[box]].0: std::ptr::Unique).0: std::ptr::NonNull) as *const S (Transmute); + // CHECK: [[ptr:_.*]] = copy ((([[box]].0: std::ptr::Unique).0: std::ptr::NonNull).0: (*const S) is !null) as *const S (Transmute); // CHECK: (*[[ptr]]) = S::new() -> [return: [[ret:bb.*]], unwind: [[unwind:bb.*]]]; // CHECK: [[ret]]: { // CHECK: [[box2:_.*]] = move [[box]]; diff --git a/tests/mir-opt/const_prop/boxes.main.GVN.panic-abort.diff b/tests/mir-opt/const_prop/boxes.main.GVN.panic-abort.diff index 95eaf18b4703b..e38580e4d1032 100644 --- a/tests/mir-opt/const_prop/boxes.main.GVN.panic-abort.diff +++ b/tests/mir-opt/const_prop/boxes.main.GVN.panic-abort.diff @@ -8,7 +8,7 @@ let mut _3: std::boxed::Box; let mut _4: *mut u8; let mut _5: std::boxed::Box; - let mut _6: *const i32; + let mut _6: (*const i32) is !null; let mut _7: std::ptr::NonNull; let mut _8: std::ptr::Unique; let mut _9: *const i32; @@ -27,20 +27,17 @@ bb1: { StorageLive(_5); -- _6 = move _4 as *const i32 (Transmute); + _6 = move _4 as (*const i32) is !null (Transmute); - _7 = NonNull:: { pointer: move _6 }; -- _8 = Unique:: { pointer: move _7, _marker: const PhantomData:: }; -+ _6 = copy _4 as *const i32 (PtrToPtr); + _7 = NonNull:: { pointer: copy _6 }; -+ _8 = Unique:: { pointer: copy _7, _marker: const PhantomData:: }; + _8 = Unique:: { pointer: move _7, _marker: const PhantomData:: }; _5 = Box::(move _8, const std::alloc::Global); -- _9 = copy ((_5.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); -- (*_9) = const 42_i32; -+ _9 = copy _6; -+ (*_6) = const 42_i32; +- _9 = copy (((_5.0: std::ptr::Unique).0: std::ptr::NonNull).0: (*const i32) is !null) as *const i32 (Transmute); ++ _9 = copy _6 as *const i32 (Transmute); + (*_9) = const 42_i32; _3 = move _5; StorageDead(_5); - _10 = copy ((_3.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); + _10 = copy (((_3.0: std::ptr::Unique).0: std::ptr::NonNull).0: (*const i32) is !null) as *const i32 (Transmute); _2 = copy (*_10); - _1 = Add(move _2, const 0_i32); - StorageDead(_2); diff --git a/tests/mir-opt/const_prop/boxes.main.GVN.panic-unwind.diff b/tests/mir-opt/const_prop/boxes.main.GVN.panic-unwind.diff index 6d8d3a0dcfe29..ee0b6409a157a 100644 --- a/tests/mir-opt/const_prop/boxes.main.GVN.panic-unwind.diff +++ b/tests/mir-opt/const_prop/boxes.main.GVN.panic-unwind.diff @@ -8,7 +8,7 @@ let mut _3: std::boxed::Box; let mut _4: *mut u8; let mut _5: std::boxed::Box; - let mut _6: *const i32; + let mut _6: (*const i32) is !null; let mut _7: std::ptr::NonNull; let mut _8: std::ptr::Unique; let mut _9: *const i32; @@ -27,20 +27,17 @@ bb1: { StorageLive(_5); -- _6 = move _4 as *const i32 (Transmute); + _6 = move _4 as (*const i32) is !null (Transmute); - _7 = NonNull:: { pointer: move _6 }; -- _8 = Unique:: { pointer: move _7, _marker: const PhantomData:: }; -+ _6 = copy _4 as *const i32 (PtrToPtr); + _7 = NonNull:: { pointer: copy _6 }; -+ _8 = Unique:: { pointer: copy _7, _marker: const PhantomData:: }; + _8 = Unique:: { pointer: move _7, _marker: const PhantomData:: }; _5 = Box::(move _8, const std::alloc::Global); -- _9 = copy ((_5.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); -- (*_9) = const 42_i32; -+ _9 = copy _6; -+ (*_6) = const 42_i32; +- _9 = copy (((_5.0: std::ptr::Unique).0: std::ptr::NonNull).0: (*const i32) is !null) as *const i32 (Transmute); ++ _9 = copy _6 as *const i32 (Transmute); + (*_9) = const 42_i32; _3 = move _5; StorageDead(_5); - _10 = copy ((_3.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); + _10 = copy (((_3.0: std::ptr::Unique).0: std::ptr::NonNull).0: (*const i32) is !null) as *const i32 (Transmute); _2 = copy (*_10); - _1 = Add(move _2, const 0_i32); - StorageDead(_2); diff --git a/tests/mir-opt/const_prop/transmute.unreachable_box.GVN.32bit.diff b/tests/mir-opt/const_prop/transmute.unreachable_box.GVN.32bit.diff index b698d8f373575..db30977e60ef6 100644 --- a/tests/mir-opt/const_prop/transmute.unreachable_box.GVN.32bit.diff +++ b/tests/mir-opt/const_prop/transmute.unreachable_box.GVN.32bit.diff @@ -12,9 +12,9 @@ bb0: { StorageLive(_1); - _1 = const 1_usize as std::boxed::Box (Transmute); -- _2 = copy ((_1.0: std::ptr::Unique).0: std::ptr::NonNull) as *const Never (Transmute); -+ _1 = const Box::(Unique:: {{ pointer: NonNull:: {{ pointer: {0x1 as *const Never} }}, _marker: PhantomData:: }}, std::alloc::Global); -+ _2 = const std::ptr::NonNull:: {{ pointer: {0x1 as *const Never} }} as *const Never (Transmute); +- _2 = copy (((_1.0: std::ptr::Unique).0: std::ptr::NonNull).0: (*const Never) is !null) as *const Never (Transmute); ++ _1 = const Box::(Unique:: {{ pointer: NonNull:: {{ pointer: {0x1 as *const Never} is !null }}, _marker: PhantomData:: }}, std::alloc::Global); ++ _2 = const {0x1 as *const Never} is !null as *const Never (Transmute); unreachable; } } diff --git a/tests/mir-opt/const_prop/transmute.unreachable_box.GVN.64bit.diff b/tests/mir-opt/const_prop/transmute.unreachable_box.GVN.64bit.diff index b698d8f373575..db30977e60ef6 100644 --- a/tests/mir-opt/const_prop/transmute.unreachable_box.GVN.64bit.diff +++ b/tests/mir-opt/const_prop/transmute.unreachable_box.GVN.64bit.diff @@ -12,9 +12,9 @@ bb0: { StorageLive(_1); - _1 = const 1_usize as std::boxed::Box (Transmute); -- _2 = copy ((_1.0: std::ptr::Unique).0: std::ptr::NonNull) as *const Never (Transmute); -+ _1 = const Box::(Unique:: {{ pointer: NonNull:: {{ pointer: {0x1 as *const Never} }}, _marker: PhantomData:: }}, std::alloc::Global); -+ _2 = const std::ptr::NonNull:: {{ pointer: {0x1 as *const Never} }} as *const Never (Transmute); +- _2 = copy (((_1.0: std::ptr::Unique).0: std::ptr::NonNull).0: (*const Never) is !null) as *const Never (Transmute); ++ _1 = const Box::(Unique:: {{ pointer: NonNull:: {{ pointer: {0x1 as *const Never} is !null }}, _marker: PhantomData:: }}, std::alloc::Global); ++ _2 = const {0x1 as *const Never} is !null as *const Never (Transmute); unreachable; } } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff index 9369720c6e5a6..4fc66f1bf7200 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff @@ -21,7 +21,7 @@ scope 8 (inlined std::ptr::Alignment::as_nonzero) { } scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { - let _7: *const [bool; 0]; + let mut _7: (*const [bool; 0]) is !null; scope 10 { } scope 11 (inlined NonZero::::get) { @@ -47,17 +47,17 @@ StorageLive(_6); _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..)); StorageLive(_7); - _7 = const {0x1 as *const [bool; 0]}; - _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; + _7 = const {0x1 as *const [bool; 0]} is !null; + _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} is !null }}; StorageDead(_7); StorageDead(_6); - _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }}; + _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} is !null }}, _marker: PhantomData::<[bool; 0]> }}; StorageDead(_5); - _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}; + _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}; StorageDead(_4); - _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); + _2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global); StorageDead(_3); - _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) }}; + _1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }}; StorageDead(_2); _0 = const (); drop(_1) -> [return: bb1, unwind unreachable]; diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff index f20ecbe21d929..c9b9d2fb8bc96 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff @@ -21,7 +21,7 @@ scope 8 (inlined std::ptr::Alignment::as_nonzero) { } scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { - let _7: *const [bool; 0]; + let mut _7: (*const [bool; 0]) is !null; scope 10 { } scope 11 (inlined NonZero::::get) { @@ -47,17 +47,17 @@ StorageLive(_6); _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..)); StorageLive(_7); - _7 = const {0x1 as *const [bool; 0]}; - _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; + _7 = const {0x1 as *const [bool; 0]} is !null; + _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} is !null }}; StorageDead(_7); StorageDead(_6); - _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }}; + _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} is !null }}, _marker: PhantomData::<[bool; 0]> }}; StorageDead(_5); - _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}; + _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}; StorageDead(_4); - _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); + _2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global); StorageDead(_3); - _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) }}; + _1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }}; StorageDead(_2); _0 = const (); drop(_1) -> [return: bb1, unwind: bb2]; diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff index 8751b0d193dd3..9b455a71afa24 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff @@ -21,7 +21,7 @@ scope 8 (inlined std::ptr::Alignment::as_nonzero) { } scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { - let _7: *const [bool; 0]; + let mut _7: (*const [bool; 0]) is !null; scope 10 { } scope 11 (inlined NonZero::::get) { @@ -47,17 +47,17 @@ StorageLive(_6); _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..)); StorageLive(_7); - _7 = const {0x1 as *const [bool; 0]}; - _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; + _7 = const {0x1 as *const [bool; 0]} is !null; + _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} is !null }}; StorageDead(_7); StorageDead(_6); - _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }}; + _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} is !null }}, _marker: PhantomData::<[bool; 0]> }}; StorageDead(_5); - _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}; + _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}; StorageDead(_4); - _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); + _2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global); StorageDead(_3); - _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) }}; + _1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }}; StorageDead(_2); _0 = const (); drop(_1) -> [return: bb1, unwind unreachable]; diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff index d67f1a7dfc964..fb9e46fa2c517 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff @@ -21,7 +21,7 @@ scope 8 (inlined std::ptr::Alignment::as_nonzero) { } scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { - let _7: *const [bool; 0]; + let mut _7: (*const [bool; 0]) is !null; scope 10 { } scope 11 (inlined NonZero::::get) { @@ -47,17 +47,17 @@ StorageLive(_6); _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..)); StorageLive(_7); - _7 = const {0x1 as *const [bool; 0]}; - _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; + _7 = const {0x1 as *const [bool; 0]} is !null; + _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} is !null }}; StorageDead(_7); StorageDead(_6); - _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }}; + _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} is !null }}, _marker: PhantomData::<[bool; 0]> }}; StorageDead(_5); - _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}; + _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}; StorageDead(_4); - _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); + _2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global); StorageDead(_3); - _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) }}; + _1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }}; StorageDead(_2); _0 = const (); drop(_1) -> [return: bb1, unwind: bb2]; diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff index df241d46f0115..c8548a9f9a4b6 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff @@ -21,7 +21,7 @@ scope 8 (inlined std::ptr::Alignment::as_nonzero) { } scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { - let _7: *const [bool; 0]; + let mut _7: (*const [bool; 0]) is !null; scope 10 { } scope 11 (inlined NonZero::::get) { @@ -48,23 +48,23 @@ - _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as std::num::NonZero (Transmute); + _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..)); StorageLive(_7); -- _7 = copy _6 as *const [bool; 0] (Transmute); -- _5 = NonNull::<[bool; 0]> { pointer: copy _7 }; -+ _7 = const {0x1 as *const [bool; 0]}; -+ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; +- _7 = copy _6 as (*const [bool; 0]) is !null (Transmute); +- _5 = NonNull::<[bool; 0]> { pointer: move _7 }; ++ _7 = const {0x1 as *const [bool; 0]} is !null; ++ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} is !null }}; StorageDead(_7); StorageDead(_6); - _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> }; -+ _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }}; ++ _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} is !null }}, _marker: PhantomData::<[bool; 0]> }}; StorageDead(_5); - _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize, Implicit)); -+ _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}; ++ _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}; StorageDead(_4); - _2 = Box::<[bool]>(copy _3, const std::alloc::Global); -+ _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); ++ _2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global); StorageDead(_3); - _1 = A { foo: move _2 }; -+ _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) }}; ++ _1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }}; StorageDead(_2); _0 = const (); drop(_1) -> [return: bb1, unwind unreachable]; diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff index b4fa37c704404..5417d6555fc76 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff @@ -21,7 +21,7 @@ scope 8 (inlined std::ptr::Alignment::as_nonzero) { } scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { - let _7: *const [bool; 0]; + let mut _7: (*const [bool; 0]) is !null; scope 10 { } scope 11 (inlined NonZero::::get) { @@ -48,23 +48,23 @@ - _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as std::num::NonZero (Transmute); + _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..)); StorageLive(_7); -- _7 = copy _6 as *const [bool; 0] (Transmute); -- _5 = NonNull::<[bool; 0]> { pointer: copy _7 }; -+ _7 = const {0x1 as *const [bool; 0]}; -+ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; +- _7 = copy _6 as (*const [bool; 0]) is !null (Transmute); +- _5 = NonNull::<[bool; 0]> { pointer: move _7 }; ++ _7 = const {0x1 as *const [bool; 0]} is !null; ++ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} is !null }}; StorageDead(_7); StorageDead(_6); - _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> }; -+ _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }}; ++ _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} is !null }}, _marker: PhantomData::<[bool; 0]> }}; StorageDead(_5); - _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize, Implicit)); -+ _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}; ++ _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}; StorageDead(_4); - _2 = Box::<[bool]>(copy _3, const std::alloc::Global); -+ _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); ++ _2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global); StorageDead(_3); - _1 = A { foo: move _2 }; -+ _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) }}; ++ _1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }}; StorageDead(_2); _0 = const (); drop(_1) -> [return: bb1, unwind: bb2]; diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff index fde840b4b7616..e046cc38ea331 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff @@ -21,7 +21,7 @@ scope 8 (inlined std::ptr::Alignment::as_nonzero) { } scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { - let _7: *const [bool; 0]; + let mut _7: (*const [bool; 0]) is !null; scope 10 { } scope 11 (inlined NonZero::::get) { @@ -48,23 +48,23 @@ - _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as std::num::NonZero (Transmute); + _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..)); StorageLive(_7); -- _7 = copy _6 as *const [bool; 0] (Transmute); -- _5 = NonNull::<[bool; 0]> { pointer: copy _7 }; -+ _7 = const {0x1 as *const [bool; 0]}; -+ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; +- _7 = copy _6 as (*const [bool; 0]) is !null (Transmute); +- _5 = NonNull::<[bool; 0]> { pointer: move _7 }; ++ _7 = const {0x1 as *const [bool; 0]} is !null; ++ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} is !null }}; StorageDead(_7); StorageDead(_6); - _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> }; -+ _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }}; ++ _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} is !null }}, _marker: PhantomData::<[bool; 0]> }}; StorageDead(_5); - _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize, Implicit)); -+ _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}; ++ _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}; StorageDead(_4); - _2 = Box::<[bool]>(copy _3, const std::alloc::Global); -+ _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); ++ _2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global); StorageDead(_3); - _1 = A { foo: move _2 }; -+ _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) }}; ++ _1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }}; StorageDead(_2); _0 = const (); drop(_1) -> [return: bb1, unwind unreachable]; diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff index cf9c9a852b441..91cb8622b45ea 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff @@ -21,7 +21,7 @@ scope 8 (inlined std::ptr::Alignment::as_nonzero) { } scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { - let _7: *const [bool; 0]; + let mut _7: (*const [bool; 0]) is !null; scope 10 { } scope 11 (inlined NonZero::::get) { @@ -48,23 +48,23 @@ - _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as std::num::NonZero (Transmute); + _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..)); StorageLive(_7); -- _7 = copy _6 as *const [bool; 0] (Transmute); -- _5 = NonNull::<[bool; 0]> { pointer: copy _7 }; -+ _7 = const {0x1 as *const [bool; 0]}; -+ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; +- _7 = copy _6 as (*const [bool; 0]) is !null (Transmute); +- _5 = NonNull::<[bool; 0]> { pointer: move _7 }; ++ _7 = const {0x1 as *const [bool; 0]} is !null; ++ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} is !null }}; StorageDead(_7); StorageDead(_6); - _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> }; -+ _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }}; ++ _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} is !null }}, _marker: PhantomData::<[bool; 0]> }}; StorageDead(_5); - _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize, Implicit)); -+ _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}; ++ _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}; StorageDead(_4); - _2 = Box::<[bool]>(copy _3, const std::alloc::Global); -+ _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); ++ _2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global); StorageDead(_3); - _1 = A { foo: move _2 }; -+ _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) }}; ++ _1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: (*const [bool]) is !null }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }}; StorageDead(_2); _0 = const (); drop(_1) -> [return: bb1, unwind: bb2]; diff --git a/tests/mir-opt/dataflow-const-prop/transmute.unreachable_box.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_box.DataflowConstProp.32bit.diff index fa6c2e29e072e..3d40191e23f44 100644 --- a/tests/mir-opt/dataflow-const-prop/transmute.unreachable_box.DataflowConstProp.32bit.diff +++ b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_box.DataflowConstProp.32bit.diff @@ -12,8 +12,8 @@ bb0: { StorageLive(_1); - _1 = const 1_usize as std::boxed::Box (Transmute); -+ _1 = const Box::(Unique:: {{ pointer: NonNull:: {{ pointer: {0x1 as *const Never} }}, _marker: PhantomData:: }}, std::alloc::Global); - _2 = copy ((_1.0: std::ptr::Unique).0: std::ptr::NonNull) as *const Never (Transmute); ++ _1 = const Box::(Unique:: {{ pointer: NonNull:: {{ pointer: {0x1 as *const Never} is !null }}, _marker: PhantomData:: }}, std::alloc::Global); + _2 = copy (((_1.0: std::ptr::Unique).0: std::ptr::NonNull).0: (*const Never) is !null) as *const Never (Transmute); unreachable; } } diff --git a/tests/mir-opt/dataflow-const-prop/transmute.unreachable_box.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_box.DataflowConstProp.64bit.diff index fa6c2e29e072e..3d40191e23f44 100644 --- a/tests/mir-opt/dataflow-const-prop/transmute.unreachable_box.DataflowConstProp.64bit.diff +++ b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_box.DataflowConstProp.64bit.diff @@ -12,8 +12,8 @@ bb0: { StorageLive(_1); - _1 = const 1_usize as std::boxed::Box (Transmute); -+ _1 = const Box::(Unique:: {{ pointer: NonNull:: {{ pointer: {0x1 as *const Never} }}, _marker: PhantomData:: }}, std::alloc::Global); - _2 = copy ((_1.0: std::ptr::Unique).0: std::ptr::NonNull) as *const Never (Transmute); ++ _1 = const Box::(Unique:: {{ pointer: NonNull:: {{ pointer: {0x1 as *const Never} is !null }}, _marker: PhantomData:: }}, std::alloc::Global); + _2 = copy (((_1.0: std::ptr::Unique).0: std::ptr::NonNull).0: (*const Never) is !null) as *const Never (Transmute); unreachable; } } diff --git a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-abort.diff b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-abort.diff index 38beb81e1ead2..8048ac3a811ba 100644 --- a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-abort.diff +++ b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-abort.diff @@ -11,9 +11,9 @@ let mut _9: *const [()]; let mut _10: std::boxed::Box<()>; let mut _11: *const (); - let mut _16: usize; let mut _17: usize; - let mut _27: usize; + let mut _18: usize; + let mut _30: usize; scope 1 { debug vp_ctx => _1; let _5: *const (); @@ -27,7 +27,7 @@ debug _x => _8; } scope 18 (inlined foo) { - let mut _28: *const [()]; + let mut _31: *const [()]; } } scope 16 (inlined slice_from_raw_parts::<()>) { @@ -38,21 +38,24 @@ } scope 5 (inlined Box::<()>::new) { let mut _12: *mut u8; - let mut _13: *const (); + let mut _13: (*const ()) is !null; let mut _14: std::ptr::NonNull<()>; let mut _15: std::ptr::Unique<()>; + let mut _16: *const (); scope 6 (inlined alloc::alloc::exchange_malloc) { - let _18: std::alloc::Layout; - let mut _19: std::result::Result, std::alloc::AllocError>; - let mut _20: isize; - let mut _22: !; + let _19: std::alloc::Layout; + let mut _20: std::result::Result, std::alloc::AllocError>; + let mut _21: isize; + let mut _23: !; scope 7 { - let _21: std::ptr::NonNull<[u8]>; + let _22: std::ptr::NonNull<[u8]>; scope 8 { scope 11 (inlined NonNull::<[u8]>::as_mut_ptr) { scope 12 (inlined NonNull::<[u8]>::as_non_null_ptr) { scope 13 (inlined NonNull::<[u8]>::cast::) { - let mut _26: *mut [u8]; + let mut _27: (*const u8) is !null; + let mut _28: *mut u8; + let mut _29: *mut [u8]; scope 14 (inlined NonNull::<[u8]>::as_ptr) { } } @@ -65,9 +68,9 @@ } } scope 9 (inlined #[track_caller] Layout::from_size_align_unchecked) { - let mut _23: bool; - let _24: (); - let mut _25: std::ptr::Alignment; + let mut _24: bool; + let _25: (); + let mut _26: std::ptr::Alignment; } } } @@ -85,19 +88,20 @@ StorageLive(_14); StorageLive(_15); StorageLive(_16); -- _16 = const <() as std::mem::SizedTypeProperties>::SIZE; -+ _16 = const 0_usize; StorageLive(_17); -- _17 = const <() as std::mem::SizedTypeProperties>::ALIGN; -+ _17 = const 1_usize; +- _17 = const <() as std::mem::SizedTypeProperties>::SIZE; ++ _17 = const 0_usize; StorageLive(_18); - StorageLive(_20); +- _18 = const <() as std::mem::SizedTypeProperties>::ALIGN; ++ _18 = const 1_usize; + StorageLive(_19); StorageLive(_21); StorageLive(_22); - StorageLive(_24); StorageLive(_23); - _23 = UbChecks(); - switchInt(move _23) -> [0: bb6, otherwise: bb5]; + StorageLive(_25); + StorageLive(_24); + _24 = UbChecks(); + switchInt(move _24) -> [0: bb6, otherwise: bb5]; } bb1: { @@ -111,33 +115,41 @@ } bb3: { -- _22 = handle_alloc_error(move _18) -> unwind unreachable; -+ _22 = handle_alloc_error(const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }}) -> unwind unreachable; +- _23 = handle_alloc_error(move _19) -> unwind unreachable; ++ _23 = handle_alloc_error(const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }}) -> unwind unreachable; } bb4: { - _21 = copy ((_19 as Ok).0: std::ptr::NonNull<[u8]>); -- StorageLive(_26); + _22 = copy ((_20 as Ok).0: std::ptr::NonNull<[u8]>); +- StorageLive(_27); + nop; - _26 = copy _21 as *mut [u8] (Transmute); - _12 = copy _26 as *mut u8 (PtrToPtr); -- StorageDead(_26); + StorageLive(_28); + StorageLive(_29); + _29 = copy _22 as *mut [u8] (Transmute); + _28 = copy _29 as *mut u8 (PtrToPtr); + StorageDead(_29); + _27 = copy _28 as (*const u8) is !null (Transmute); + StorageDead(_28); + _12 = copy _27 as *mut u8 (Transmute); +- StorageDead(_27); + nop; - StorageDead(_19); - StorageDead(_24); + StorageDead(_20); + StorageDead(_25); + StorageDead(_23); StorageDead(_22); StorageDead(_21); - StorageDead(_20); + StorageDead(_19); StorageDead(_18); StorageDead(_17); - StorageDead(_16); -- _13 = copy _12 as *const () (PtrToPtr); -+ _13 = copy _26 as *const () (PtrToPtr); +- _13 = copy _12 as (*const ()) is !null (Transmute); ++ _13 = copy _27 as (*const ()) is !null (Transmute); _14 = NonNull::<()> { pointer: copy _13 }; - _15 = Unique::<()> { pointer: copy _14, _marker: const PhantomData::<()> }; + _15 = Unique::<()> { pointer: move _14, _marker: const PhantomData::<()> }; _3 = Box::<()>(move _15, const std::alloc::Global); -- (*_13) = move _4; -+ (*_13) = const (); + _16 = copy _13 as *const () (Transmute); +- (*_16) = move _4; ++ (*_16) = const (); + StorageDead(_16); StorageDead(_15); StorageDead(_14); StorageDead(_13); @@ -151,27 +163,27 @@ + nop; + nop; + _10 = copy (*_2); - _11 = copy ((_10.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute); + _11 = copy (((_10.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>).0: (*const ()) is !null) as *const () (Transmute); _5 = &raw const (*_11); - StorageLive(_6); + nop; StorageLive(_7); _7 = copy _5; - StorageLive(_27); - _27 = const 1_usize; -- _6 = *const [()] from (copy _7, copy _27); + StorageLive(_30); + _30 = const 1_usize; +- _6 = *const [()] from (copy _7, copy _30); + _6 = *const [()] from (copy _5, const 1_usize); - StorageDead(_27); + StorageDead(_30); StorageDead(_7); StorageLive(_8); StorageLive(_9); _9 = copy _6; - StorageLive(_28); -- _28 = copy _9; + StorageLive(_31); +- _31 = copy _9; - _8 = copy _9 as *mut () (PtrToPtr); -+ _28 = copy _6; ++ _31 = copy _6; + _8 = copy _5 as *mut () (PtrToPtr); - StorageDead(_28); + StorageDead(_31); StorageDead(_9); _0 = const (); StorageDead(_8); @@ -183,26 +195,26 @@ } bb5: { -- _24 = Layout::from_size_align_unchecked::precondition_check(copy _16, copy _17) -> [return: bb6, unwind unreachable]; -+ _24 = Layout::from_size_align_unchecked::precondition_check(const 0_usize, const 1_usize) -> [return: bb6, unwind unreachable]; +- _25 = Layout::from_size_align_unchecked::precondition_check(copy _17, copy _18) -> [return: bb6, unwind unreachable]; ++ _25 = Layout::from_size_align_unchecked::precondition_check(const 0_usize, const 1_usize) -> [return: bb6, unwind unreachable]; } bb6: { - StorageDead(_23); - StorageLive(_25); -- _25 = copy _17 as std::ptr::Alignment (Transmute); -- _18 = Layout { size: copy _16, align: move _25 }; -+ _25 = const std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0); -+ _18 = const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }}; - StorageDead(_25); - StorageLive(_19); -- _19 = std::alloc::Global::alloc_impl(const alloc::alloc::exchange_malloc::promoted[0], copy _18, const false) -> [return: bb7, unwind unreachable]; -+ _19 = std::alloc::Global::alloc_impl(const alloc::alloc::exchange_malloc::promoted[0], const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }}, const false) -> [return: bb7, unwind unreachable]; + StorageDead(_24); + StorageLive(_26); +- _26 = copy _18 as std::ptr::Alignment (Transmute); +- _19 = Layout { size: copy _17, align: move _26 }; ++ _26 = const std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0); ++ _19 = const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }}; + StorageDead(_26); + StorageLive(_20); +- _20 = std::alloc::Global::alloc_impl(const alloc::alloc::exchange_malloc::promoted[0], copy _19, const false) -> [return: bb7, unwind unreachable]; ++ _20 = std::alloc::Global::alloc_impl(const alloc::alloc::exchange_malloc::promoted[0], const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }}, const false) -> [return: bb7, unwind unreachable]; } bb7: { - _20 = discriminant(_19); - switchInt(move _20) -> [0: bb4, 1: bb3, otherwise: bb2]; + _21 = discriminant(_20); + switchInt(move _21) -> [0: bb4, 1: bb3, otherwise: bb2]; } + } + diff --git a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-unwind.diff b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-unwind.diff index 82a14a8b6ec99..a4c52a28c95d3 100644 --- a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-unwind.diff +++ b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-unwind.diff @@ -57,7 +57,7 @@ + nop; + nop; + _10 = copy (*_2); - _11 = copy ((_10.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute); + _11 = copy (((_10.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>).0: (*const ()) is !null) as *const () (Transmute); _5 = &raw const (*_11); - StorageLive(_6); + nop; diff --git a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-abort.diff b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-abort.diff index 047579cdb5094..16023fd2ec942 100644 --- a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-abort.diff +++ b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-abort.diff @@ -11,9 +11,9 @@ let mut _9: *const [()]; let mut _10: std::boxed::Box<()>; let mut _11: *const (); - let mut _16: usize; let mut _17: usize; - let mut _27: usize; + let mut _18: usize; + let mut _30: usize; scope 1 { debug vp_ctx => _1; let _5: *const (); @@ -27,7 +27,7 @@ debug _x => _8; } scope 18 (inlined foo) { - let mut _28: *const [()]; + let mut _31: *const [()]; } } scope 16 (inlined slice_from_raw_parts::<()>) { @@ -38,21 +38,24 @@ } scope 5 (inlined Box::<()>::new) { let mut _12: *mut u8; - let mut _13: *const (); + let mut _13: (*const ()) is !null; let mut _14: std::ptr::NonNull<()>; let mut _15: std::ptr::Unique<()>; + let mut _16: *const (); scope 6 (inlined alloc::alloc::exchange_malloc) { - let _18: std::alloc::Layout; - let mut _19: std::result::Result, std::alloc::AllocError>; - let mut _20: isize; - let mut _22: !; + let _19: std::alloc::Layout; + let mut _20: std::result::Result, std::alloc::AllocError>; + let mut _21: isize; + let mut _23: !; scope 7 { - let _21: std::ptr::NonNull<[u8]>; + let _22: std::ptr::NonNull<[u8]>; scope 8 { scope 11 (inlined NonNull::<[u8]>::as_mut_ptr) { scope 12 (inlined NonNull::<[u8]>::as_non_null_ptr) { scope 13 (inlined NonNull::<[u8]>::cast::) { - let mut _26: *mut [u8]; + let mut _27: (*const u8) is !null; + let mut _28: *mut u8; + let mut _29: *mut [u8]; scope 14 (inlined NonNull::<[u8]>::as_ptr) { } } @@ -65,9 +68,9 @@ } } scope 9 (inlined #[track_caller] Layout::from_size_align_unchecked) { - let mut _23: bool; - let _24: (); - let mut _25: std::ptr::Alignment; + let mut _24: bool; + let _25: (); + let mut _26: std::ptr::Alignment; } } } @@ -85,19 +88,20 @@ StorageLive(_14); StorageLive(_15); StorageLive(_16); -- _16 = const <() as std::mem::SizedTypeProperties>::SIZE; -+ _16 = const 0_usize; StorageLive(_17); -- _17 = const <() as std::mem::SizedTypeProperties>::ALIGN; -+ _17 = const 1_usize; +- _17 = const <() as std::mem::SizedTypeProperties>::SIZE; ++ _17 = const 0_usize; StorageLive(_18); - StorageLive(_20); +- _18 = const <() as std::mem::SizedTypeProperties>::ALIGN; ++ _18 = const 1_usize; + StorageLive(_19); StorageLive(_21); StorageLive(_22); - StorageLive(_24); StorageLive(_23); - _23 = UbChecks(); - switchInt(move _23) -> [0: bb6, otherwise: bb5]; + StorageLive(_25); + StorageLive(_24); + _24 = UbChecks(); + switchInt(move _24) -> [0: bb6, otherwise: bb5]; } bb1: { @@ -111,33 +115,41 @@ } bb3: { -- _22 = handle_alloc_error(move _18) -> unwind unreachable; -+ _22 = handle_alloc_error(const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }}) -> unwind unreachable; +- _23 = handle_alloc_error(move _19) -> unwind unreachable; ++ _23 = handle_alloc_error(const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }}) -> unwind unreachable; } bb4: { - _21 = copy ((_19 as Ok).0: std::ptr::NonNull<[u8]>); -- StorageLive(_26); + _22 = copy ((_20 as Ok).0: std::ptr::NonNull<[u8]>); +- StorageLive(_27); + nop; - _26 = copy _21 as *mut [u8] (Transmute); - _12 = copy _26 as *mut u8 (PtrToPtr); -- StorageDead(_26); + StorageLive(_28); + StorageLive(_29); + _29 = copy _22 as *mut [u8] (Transmute); + _28 = copy _29 as *mut u8 (PtrToPtr); + StorageDead(_29); + _27 = copy _28 as (*const u8) is !null (Transmute); + StorageDead(_28); + _12 = copy _27 as *mut u8 (Transmute); +- StorageDead(_27); + nop; - StorageDead(_19); - StorageDead(_24); + StorageDead(_20); + StorageDead(_25); + StorageDead(_23); StorageDead(_22); StorageDead(_21); - StorageDead(_20); + StorageDead(_19); StorageDead(_18); StorageDead(_17); - StorageDead(_16); -- _13 = copy _12 as *const () (PtrToPtr); -+ _13 = copy _26 as *const () (PtrToPtr); +- _13 = copy _12 as (*const ()) is !null (Transmute); ++ _13 = copy _27 as (*const ()) is !null (Transmute); _14 = NonNull::<()> { pointer: copy _13 }; - _15 = Unique::<()> { pointer: copy _14, _marker: const PhantomData::<()> }; + _15 = Unique::<()> { pointer: move _14, _marker: const PhantomData::<()> }; _3 = Box::<()>(move _15, const std::alloc::Global); -- (*_13) = move _4; -+ (*_13) = const (); + _16 = copy _13 as *const () (Transmute); +- (*_16) = move _4; ++ (*_16) = const (); + StorageDead(_16); StorageDead(_15); StorageDead(_14); StorageDead(_13); @@ -151,27 +163,27 @@ + nop; + nop; + _10 = copy (*_2); - _11 = copy ((_10.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute); + _11 = copy (((_10.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>).0: (*const ()) is !null) as *const () (Transmute); _5 = &raw const (*_11); - StorageLive(_6); + nop; StorageLive(_7); _7 = copy _5; - StorageLive(_27); - _27 = const 1_usize; -- _6 = *const [()] from (copy _7, copy _27); + StorageLive(_30); + _30 = const 1_usize; +- _6 = *const [()] from (copy _7, copy _30); + _6 = *const [()] from (copy _5, const 1_usize); - StorageDead(_27); + StorageDead(_30); StorageDead(_7); StorageLive(_8); StorageLive(_9); _9 = copy _6; - StorageLive(_28); -- _28 = copy _9; + StorageLive(_31); +- _31 = copy _9; - _8 = copy _9 as *mut () (PtrToPtr); -+ _28 = copy _6; ++ _31 = copy _6; + _8 = copy _5 as *mut () (PtrToPtr); - StorageDead(_28); + StorageDead(_31); StorageDead(_9); _0 = const (); StorageDead(_8); @@ -183,26 +195,26 @@ } bb5: { -- _24 = Layout::from_size_align_unchecked::precondition_check(copy _16, copy _17) -> [return: bb6, unwind unreachable]; -+ _24 = Layout::from_size_align_unchecked::precondition_check(const 0_usize, const 1_usize) -> [return: bb6, unwind unreachable]; +- _25 = Layout::from_size_align_unchecked::precondition_check(copy _17, copy _18) -> [return: bb6, unwind unreachable]; ++ _25 = Layout::from_size_align_unchecked::precondition_check(const 0_usize, const 1_usize) -> [return: bb6, unwind unreachable]; } bb6: { - StorageDead(_23); - StorageLive(_25); -- _25 = copy _17 as std::ptr::Alignment (Transmute); -- _18 = Layout { size: copy _16, align: move _25 }; -+ _25 = const std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0); -+ _18 = const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }}; - StorageDead(_25); - StorageLive(_19); -- _19 = std::alloc::Global::alloc_impl(const alloc::alloc::exchange_malloc::promoted[0], copy _18, const false) -> [return: bb7, unwind unreachable]; -+ _19 = std::alloc::Global::alloc_impl(const alloc::alloc::exchange_malloc::promoted[0], const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }}, const false) -> [return: bb7, unwind unreachable]; + StorageDead(_24); + StorageLive(_26); +- _26 = copy _18 as std::ptr::Alignment (Transmute); +- _19 = Layout { size: copy _17, align: move _26 }; ++ _26 = const std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0); ++ _19 = const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }}; + StorageDead(_26); + StorageLive(_20); +- _20 = std::alloc::Global::alloc_impl(const alloc::alloc::exchange_malloc::promoted[0], copy _19, const false) -> [return: bb7, unwind unreachable]; ++ _20 = std::alloc::Global::alloc_impl(const alloc::alloc::exchange_malloc::promoted[0], const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }}, const false) -> [return: bb7, unwind unreachable]; } bb7: { - _20 = discriminant(_19); - switchInt(move _20) -> [0: bb4, 1: bb3, otherwise: bb2]; + _21 = discriminant(_20); + switchInt(move _21) -> [0: bb4, 1: bb3, otherwise: bb2]; } + } + diff --git a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-unwind.diff b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-unwind.diff index 82a14a8b6ec99..a4c52a28c95d3 100644 --- a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-unwind.diff +++ b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-unwind.diff @@ -57,7 +57,7 @@ + nop; + nop; + _10 = copy (*_2); - _11 = copy ((_10.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute); + _11 = copy (((_10.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>).0: (*const ()) is !null) as *const () (Transmute); _5 = &raw const (*_11); - StorageLive(_6); + nop; diff --git a/tests/mir-opt/elaborate_box_deref_in_debuginfo.pointee.ElaborateBoxDerefs.diff b/tests/mir-opt/elaborate_box_deref_in_debuginfo.pointee.ElaborateBoxDerefs.diff index 279c1a1990dc8..6075d7895eeb3 100644 --- a/tests/mir-opt/elaborate_box_deref_in_debuginfo.pointee.ElaborateBoxDerefs.diff +++ b/tests/mir-opt/elaborate_box_deref_in_debuginfo.pointee.ElaborateBoxDerefs.diff @@ -3,7 +3,7 @@ fn pointee(_1: Box) -> () { - debug foo => (*_1); -+ debug foo => (*(((_1.0: std::ptr::Unique).0: std::ptr::NonNull).0: *const i32)); ++ debug foo => (*((((_1.0: std::ptr::Unique).0: std::ptr::NonNull).0: (*const i32) is !null).0: *const i32)); let mut _0: (); bb0: { diff --git a/tests/mir-opt/gvn_ptr_eq_with_constant.main.GVN.diff b/tests/mir-opt/gvn_ptr_eq_with_constant.main.GVN.diff index 5b8fb659eff12..55fea9aef9101 100644 --- a/tests/mir-opt/gvn_ptr_eq_with_constant.main.GVN.diff +++ b/tests/mir-opt/gvn_ptr_eq_with_constant.main.GVN.diff @@ -12,6 +12,7 @@ scope 5 (inlined std::ptr::Alignment::as_nonzero) { } scope 6 (inlined NonNull::::without_provenance) { + let mut _4: (*const u8) is !null; scope 7 { } scope 8 (inlined NonZero::::get) { @@ -29,9 +30,9 @@ } } scope 12 (inlined Foo::::cmp_ptr) { - let mut _4: *const u8; - let mut _5: *mut u8; - let mut _6: *const u8; + let mut _5: *const u8; + let mut _6: *mut u8; + let mut _7: *const u8; scope 13 (inlined std::ptr::eq::) { } } @@ -39,26 +40,29 @@ bb0: { StorageLive(_1); StorageLive(_2); + StorageLive(_4); StorageLive(_3); - _3 = const std::ptr::Alignment::of::::{constant#0} as std::num::NonZero (Transmute); -- _2 = copy _3 as *mut u8 (Transmute); +- _4 = copy _3 as (*const u8) is !null (Transmute); + _3 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..)); -+ _2 = const {0x1 as *mut u8}; ++ _4 = const {0x1 as *const u8} is !null; StorageDead(_3); - StorageLive(_4); +- _2 = copy _4 as *mut u8 (Transmute); ++ _2 = const {0x1 as *const u8} is !null as *mut u8 (Transmute); + StorageDead(_4); StorageLive(_5); -- _5 = copy _2; -- _4 = copy _2 as *const u8 (PtrToPtr); -+ _5 = const {0x1 as *mut u8}; -+ _4 = const {0x1 as *const u8}; - StorageDead(_5); StorageLive(_6); -- _6 = const Foo::::SENTINEL as *const u8 (PtrToPtr); -- _1 = Eq(copy _4, copy _6); -+ _6 = const {0x1 as *const u8}; -+ _1 = const true; + _6 = copy _2; +- _5 = copy _2 as *const u8 (PtrToPtr); ++ _5 = const {0x1 as *const u8} is !null as *const u8 (Transmute); StorageDead(_6); - StorageDead(_4); + StorageLive(_7); +- _7 = const Foo::::SENTINEL as *const u8 (PtrToPtr); +- _1 = Eq(copy _5, copy _7); ++ _7 = const {0x1 as *const u8}; ++ _1 = Eq(copy _5, const {0x1 as *const u8}); + StorageDead(_7); + StorageDead(_5); StorageDead(_2); StorageDead(_1); _0 = const (); diff --git a/tests/mir-opt/inline/dont_ice_on_generic_rust_call.call.Inline.panic-abort.diff b/tests/mir-opt/inline/dont_ice_on_generic_rust_call.call.Inline.panic-abort.diff index 86e8749fb0b51..d2e25368322f4 100644 --- a/tests/mir-opt/inline/dont_ice_on_generic_rust_call.call.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/dont_ice_on_generic_rust_call.call.Inline.panic-abort.diff @@ -10,7 +10,7 @@ + scope 1 (inlined > as FnMut>::call_mut) { + let mut _5: &mut dyn std::ops::FnMut; + let mut _6: *const dyn std::ops::FnMut; -+ let mut _7: std::ptr::NonNull>; ++ let mut _7: (*const dyn std::ops::FnMut) is !null; + } bb0: { @@ -22,7 +22,7 @@ + StorageLive(_6); + StorageLive(_7); + StorageLive(_5); -+ _7 = copy (((*_3).0: std::ptr::Unique>).0: std::ptr::NonNull>); ++ _7 = copy ((((*_3).0: std::ptr::Unique>).0: std::ptr::NonNull>).0: (*const dyn std::ops::FnMut) is !null); + _6 = copy _7 as *const dyn std::ops::FnMut (Transmute); + _5 = &mut (*_6); + _0 = as FnMut>::call_mut(move _5, move _4) -> [return: bb2, unwind unreachable]; diff --git a/tests/mir-opt/inline/dont_ice_on_generic_rust_call.call.Inline.panic-unwind.diff b/tests/mir-opt/inline/dont_ice_on_generic_rust_call.call.Inline.panic-unwind.diff index 50136ae8766b2..181f29866f923 100644 --- a/tests/mir-opt/inline/dont_ice_on_generic_rust_call.call.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/dont_ice_on_generic_rust_call.call.Inline.panic-unwind.diff @@ -10,7 +10,7 @@ + scope 1 (inlined > as FnMut>::call_mut) { + let mut _5: &mut dyn std::ops::FnMut; + let mut _6: *const dyn std::ops::FnMut; -+ let mut _7: std::ptr::NonNull>; ++ let mut _7: (*const dyn std::ops::FnMut) is !null; + } bb0: { @@ -22,7 +22,7 @@ + StorageLive(_6); + StorageLive(_7); + StorageLive(_5); -+ _7 = copy (((*_3).0: std::ptr::Unique>).0: std::ptr::NonNull>); ++ _7 = copy ((((*_3).0: std::ptr::Unique>).0: std::ptr::NonNull>).0: (*const dyn std::ops::FnMut) is !null); + _6 = copy _7 as *const dyn std::ops::FnMut (Transmute); + _5 = &mut (*_6); + _0 = as FnMut>::call_mut(move _5, move _4) -> [return: bb4, unwind: bb2]; diff --git a/tests/mir-opt/inline/inline_box_fn.call.Inline.panic-abort.diff b/tests/mir-opt/inline/inline_box_fn.call.Inline.panic-abort.diff index 97a8a99d9805e..67a46ec24d3bc 100644 --- a/tests/mir-opt/inline/inline_box_fn.call.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/inline_box_fn.call.Inline.panic-abort.diff @@ -10,7 +10,7 @@ + scope 1 (inlined as Fn<(i32,)>>::call) { + let mut _5: &dyn std::ops::Fn(i32); + let mut _6: *const dyn std::ops::Fn(i32); -+ let mut _7: std::ptr::NonNull; ++ let mut _7: (*const dyn std::ops::Fn(i32)) is !null; + } bb0: { @@ -23,7 +23,7 @@ + StorageLive(_6); + StorageLive(_7); + StorageLive(_5); -+ _7 = copy (((*_3).0: std::ptr::Unique).0: std::ptr::NonNull); ++ _7 = copy ((((*_3).0: std::ptr::Unique).0: std::ptr::NonNull).0: (*const dyn std::ops::Fn(i32)) is !null); + _6 = copy _7 as *const dyn std::ops::Fn(i32) (Transmute); + _5 = &(*_6); + _2 = >::call(move _5, move _4) -> [return: bb2, unwind unreachable]; diff --git a/tests/mir-opt/inline/inline_box_fn.call.Inline.panic-unwind.diff b/tests/mir-opt/inline/inline_box_fn.call.Inline.panic-unwind.diff index 3b18052616e2f..77ff90546e33b 100644 --- a/tests/mir-opt/inline/inline_box_fn.call.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/inline_box_fn.call.Inline.panic-unwind.diff @@ -10,7 +10,7 @@ + scope 1 (inlined as Fn<(i32,)>>::call) { + let mut _5: &dyn std::ops::Fn(i32); + let mut _6: *const dyn std::ops::Fn(i32); -+ let mut _7: std::ptr::NonNull; ++ let mut _7: (*const dyn std::ops::Fn(i32)) is !null; + } bb0: { @@ -23,7 +23,7 @@ + StorageLive(_6); + StorageLive(_7); + StorageLive(_5); -+ _7 = copy (((*_3).0: std::ptr::Unique).0: std::ptr::NonNull); ++ _7 = copy ((((*_3).0: std::ptr::Unique).0: std::ptr::NonNull).0: (*const dyn std::ops::Fn(i32)) is !null); + _6 = copy _7 as *const dyn std::ops::Fn(i32) (Transmute); + _5 = &(*_6); + _2 = >::call(move _5, move _4) -> [return: bb4, unwind: bb2]; diff --git a/tests/mir-opt/inline/inline_shims.drop.Inline.panic-abort.diff b/tests/mir-opt/inline/inline_shims.drop.Inline.panic-abort.diff index 9509739413b76..1aade88572f1a 100644 --- a/tests/mir-opt/inline/inline_shims.drop.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/inline_shims.drop.Inline.panic-abort.diff @@ -19,9 +19,10 @@ + scope 4 (inlined alloc::raw_vec::RawVec::::ptr) { + scope 5 (inlined alloc::raw_vec::RawVecInner::ptr::) { + scope 6 (inlined alloc::raw_vec::RawVecInner::non_null::) { -+ let mut _11: std::ptr::NonNull; ++ let mut _12: std::ptr::NonNull; + scope 7 (inlined Unique::::cast::) { + scope 8 (inlined NonNull::::cast::) { ++ let mut _11: (*const A) is !null; + scope 9 (inlined NonNull::::as_ptr) { + } + } @@ -39,15 +40,15 @@ + } + } + scope 14 (inlined drop_in_place::<[A]> - shim(Some([A]))) { -+ let mut _12: usize; -+ let mut _13: *mut A; -+ let mut _14: bool; ++ let mut _13: usize; ++ let mut _14: *mut A; ++ let mut _15: bool; + } + } + } + scope 15 (inlined drop_in_place::> - shim(Some(Option))) { -+ let mut _15: isize; + let mut _16: isize; ++ let mut _17: isize; + } bb0: { @@ -62,16 +63,19 @@ + StorageLive(_8); + StorageLive(_9); + StorageLive(_11); -+ _11 = copy (((((*_6).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).0: std::ptr::Unique).0: std::ptr::NonNull); ++ StorageLive(_12); ++ _12 = copy (((((*_6).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).0: std::ptr::Unique).0: std::ptr::NonNull); ++ _11 = copy _12 as (*const A) is !null (Transmute); ++ StorageDead(_12); + _9 = copy _11 as *mut A (Transmute); + StorageDead(_11); + _10 = copy ((*_6).1: usize); + _8 = *mut [A] from (copy _9, copy _10); + StorageDead(_9); -+ StorageLive(_12); + StorageLive(_13); + StorageLive(_14); -+ _12 = const 0_usize; ++ StorageLive(_15); ++ _13 = const 0_usize; + goto -> bb4; } @@ -83,33 +87,33 @@ StorageLive(_5); _5 = copy _2; - _0 = drop_in_place::>(move _5) -> [return: bb2, unwind unreachable]; -+ StorageLive(_15); -+ _15 = discriminant((*_5)); -+ switchInt(move _15) -> [0: bb5, otherwise: bb6]; ++ StorageLive(_16); ++ _16 = discriminant((*_5)); ++ switchInt(move _16) -> [0: bb5, otherwise: bb6]; } bb2: { ++ StorageDead(_15); + StorageDead(_14); + StorageDead(_13); -+ StorageDead(_12); + StorageDead(_8); + StorageDead(_10); + drop(((*_4).0: alloc::raw_vec::RawVec)) -> [return: bb1, unwind unreachable]; + } + + bb3: { -+ _13 = &raw mut (*_8)[_12]; -+ _12 = Add(move _12, const 1_usize); -+ drop((*_13)) -> [return: bb4, unwind unreachable]; ++ _14 = &raw mut (*_8)[_13]; ++ _13 = Add(move _13, const 1_usize); ++ drop((*_14)) -> [return: bb4, unwind unreachable]; + } + + bb4: { -+ _14 = Eq(copy _12, copy _10); -+ switchInt(move _14) -> [0: bb3, otherwise: bb2]; ++ _15 = Eq(copy _13, copy _10); ++ switchInt(move _15) -> [0: bb3, otherwise: bb2]; + } + + bb5: { -+ StorageDead(_15); ++ StorageDead(_16); StorageDead(_5); return; + } diff --git a/tests/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir b/tests/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir index 688e6967c2f85..7ec117ff85994 100644 --- a/tests/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir +++ b/tests/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir @@ -9,7 +9,7 @@ fn b(_1: &mut Box) -> &mut T { scope 1 (inlined as AsMut>::as_mut) { debug self => _4; let mut _5: *const T; - let mut _6: std::ptr::NonNull; + let mut _6: (*const T) is !null; } bb0: { @@ -19,7 +19,7 @@ fn b(_1: &mut Box) -> &mut T { _4 = copy _1; StorageLive(_5); StorageLive(_6); - _6 = copy (((*_4).0: std::ptr::Unique).0: std::ptr::NonNull); + _6 = copy ((((*_4).0: std::ptr::Unique).0: std::ptr::NonNull).0: (*const T) is !null); _5 = copy _6 as *const T (Transmute); _3 = &mut (*_5); StorageDead(_6); diff --git a/tests/mir-opt/inline/issue_58867_inline_as_ref_as_mut.d.Inline.after.mir b/tests/mir-opt/inline/issue_58867_inline_as_ref_as_mut.d.Inline.after.mir index 663741c62fb84..e2ab5194ddb27 100644 --- a/tests/mir-opt/inline/issue_58867_inline_as_ref_as_mut.d.Inline.after.mir +++ b/tests/mir-opt/inline/issue_58867_inline_as_ref_as_mut.d.Inline.after.mir @@ -8,7 +8,7 @@ fn d(_1: &Box) -> &T { scope 1 (inlined as AsRef>::as_ref) { debug self => _3; let mut _4: *const T; - let mut _5: std::ptr::NonNull; + let mut _5: (*const T) is !null; } bb0: { @@ -17,7 +17,7 @@ fn d(_1: &Box) -> &T { _3 = copy _1; StorageLive(_4); StorageLive(_5); - _5 = copy (((*_3).0: std::ptr::Unique).0: std::ptr::NonNull); + _5 = copy ((((*_3).0: std::ptr::Unique).0: std::ptr::NonNull).0: (*const T) is !null); _4 = copy _5 as *const T (Transmute); _2 = &(*_4); StorageDead(_5); diff --git a/tests/mir-opt/inline/unsized_argument.caller.Inline.diff b/tests/mir-opt/inline/unsized_argument.caller.Inline.diff index 644d6d320de04..bef8e43903e56 100644 --- a/tests/mir-opt/inline/unsized_argument.caller.Inline.diff +++ b/tests/mir-opt/inline/unsized_argument.caller.Inline.diff @@ -12,7 +12,7 @@ StorageLive(_2); StorageLive(_3); _3 = move _1; - _4 = copy ((_3.0: std::ptr::Unique<[i32]>).0: std::ptr::NonNull<[i32]>) as *const [i32] (Transmute); + _4 = copy (((_3.0: std::ptr::Unique<[i32]>).0: std::ptr::NonNull<[i32]>).0: (*const [i32]) is !null) as *const [i32] (Transmute); _2 = callee(move (*_4)) -> [return: bb1, unwind: bb3]; } diff --git a/tests/mir-opt/lower_intrinsics.transmute_to_box_uninhabited.LowerIntrinsics.panic-abort.diff b/tests/mir-opt/lower_intrinsics.transmute_to_box_uninhabited.LowerIntrinsics.panic-abort.diff index 4f8b7c4160f99..4d97a9f5c5251 100644 --- a/tests/mir-opt/lower_intrinsics.transmute_to_box_uninhabited.LowerIntrinsics.panic-abort.diff +++ b/tests/mir-opt/lower_intrinsics.transmute_to_box_uninhabited.LowerIntrinsics.panic-abort.diff @@ -17,7 +17,7 @@ } bb1: { - _2 = copy ((_1.0: std::ptr::Unique).0: std::ptr::NonNull) as *const Never (Transmute); + _2 = copy (((_1.0: std::ptr::Unique).0: std::ptr::NonNull).0: (*const Never) is !null) as *const Never (Transmute); PlaceMention((*_2)); unreachable; } diff --git a/tests/mir-opt/lower_intrinsics.transmute_to_box_uninhabited.LowerIntrinsics.panic-unwind.diff b/tests/mir-opt/lower_intrinsics.transmute_to_box_uninhabited.LowerIntrinsics.panic-unwind.diff index 4f8b7c4160f99..4d97a9f5c5251 100644 --- a/tests/mir-opt/lower_intrinsics.transmute_to_box_uninhabited.LowerIntrinsics.panic-unwind.diff +++ b/tests/mir-opt/lower_intrinsics.transmute_to_box_uninhabited.LowerIntrinsics.panic-unwind.diff @@ -17,7 +17,7 @@ } bb1: { - _2 = copy ((_1.0: std::ptr::Unique).0: std::ptr::NonNull) as *const Never (Transmute); + _2 = copy (((_1.0: std::ptr::Unique).0: std::ptr::NonNull).0: (*const Never) is !null) as *const Never (Transmute); PlaceMention((*_2)); unreachable; } diff --git a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-abort.mir b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-abort.mir index 791d6b71a6f78..e498708b5b8df 100644 --- a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-abort.mir @@ -8,7 +8,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { let _2: std::ptr::NonNull<[T]>; let mut _3: *mut [T]; let mut _4: *const [T]; - let _11: (); + let _13: (); scope 3 { let _8: std::ptr::alignment::AlignmentEnum; scope 4 { @@ -16,6 +16,8 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { } scope 13 (inlined Unique::<[T]>::cast::) { scope 14 (inlined NonNull::<[T]>::cast::) { + let mut _9: *mut u8; + let mut _10: (*const u8) is !null; scope 15 (inlined NonNull::<[T]>::as_ptr) { } } @@ -25,13 +27,13 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { } } scope 18 (inlined ::deallocate) { - let mut _9: *mut u8; + let mut _11: *mut u8; scope 19 (inlined Layout::size) { } scope 20 (inlined NonNull::::as_ptr) { } scope 21 (inlined std::alloc::dealloc) { - let mut _10: usize; + let mut _12: usize; scope 22 (inlined Layout::size) { } scope 23 (inlined Layout::align) { @@ -63,6 +65,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { } bb0: { + StorageLive(_3); StorageLive(_2); _2 = copy (((*_1).0: std::ptr::Unique<[T]>).0: std::ptr::NonNull<[T]>); StorageLive(_4); @@ -86,19 +89,24 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { bb2: { StorageLive(_9); _9 = copy _3 as *mut u8 (PtrToPtr); - StorageLive(_10); - _10 = discriminant(_8); - _11 = alloc::alloc::__rust_dealloc(move _9, move _5, move _10) -> [return: bb3, unwind unreachable]; + _10 = copy _9 as (*const u8) is !null (Transmute); + StorageDead(_9); + StorageLive(_11); + _11 = copy _10 as *mut u8 (Transmute); + StorageLive(_12); + _12 = discriminant(_8); + _13 = alloc::alloc::__rust_dealloc(move _11, move _5, move _12) -> [return: bb3, unwind unreachable]; } bb3: { - StorageDead(_10); - StorageDead(_9); + StorageDead(_12); + StorageDead(_11); goto -> bb4; } bb4: { StorageDead(_2); + StorageDead(_3); return; } } diff --git a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-unwind.mir b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-unwind.mir index 791d6b71a6f78..e498708b5b8df 100644 --- a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-unwind.mir @@ -8,7 +8,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { let _2: std::ptr::NonNull<[T]>; let mut _3: *mut [T]; let mut _4: *const [T]; - let _11: (); + let _13: (); scope 3 { let _8: std::ptr::alignment::AlignmentEnum; scope 4 { @@ -16,6 +16,8 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { } scope 13 (inlined Unique::<[T]>::cast::) { scope 14 (inlined NonNull::<[T]>::cast::) { + let mut _9: *mut u8; + let mut _10: (*const u8) is !null; scope 15 (inlined NonNull::<[T]>::as_ptr) { } } @@ -25,13 +27,13 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { } } scope 18 (inlined ::deallocate) { - let mut _9: *mut u8; + let mut _11: *mut u8; scope 19 (inlined Layout::size) { } scope 20 (inlined NonNull::::as_ptr) { } scope 21 (inlined std::alloc::dealloc) { - let mut _10: usize; + let mut _12: usize; scope 22 (inlined Layout::size) { } scope 23 (inlined Layout::align) { @@ -63,6 +65,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { } bb0: { + StorageLive(_3); StorageLive(_2); _2 = copy (((*_1).0: std::ptr::Unique<[T]>).0: std::ptr::NonNull<[T]>); StorageLive(_4); @@ -86,19 +89,24 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { bb2: { StorageLive(_9); _9 = copy _3 as *mut u8 (PtrToPtr); - StorageLive(_10); - _10 = discriminant(_8); - _11 = alloc::alloc::__rust_dealloc(move _9, move _5, move _10) -> [return: bb3, unwind unreachable]; + _10 = copy _9 as (*const u8) is !null (Transmute); + StorageDead(_9); + StorageLive(_11); + _11 = copy _10 as *mut u8 (Transmute); + StorageLive(_12); + _12 = discriminant(_8); + _13 = alloc::alloc::__rust_dealloc(move _11, move _5, move _12) -> [return: bb3, unwind unreachable]; } bb3: { - StorageDead(_10); - StorageDead(_9); + StorageDead(_12); + StorageDead(_11); goto -> bb4; } bb4: { StorageDead(_2); + StorageDead(_3); return; } } diff --git a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-abort.mir b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-abort.mir index 791d6b71a6f78..e498708b5b8df 100644 --- a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-abort.mir @@ -8,7 +8,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { let _2: std::ptr::NonNull<[T]>; let mut _3: *mut [T]; let mut _4: *const [T]; - let _11: (); + let _13: (); scope 3 { let _8: std::ptr::alignment::AlignmentEnum; scope 4 { @@ -16,6 +16,8 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { } scope 13 (inlined Unique::<[T]>::cast::) { scope 14 (inlined NonNull::<[T]>::cast::) { + let mut _9: *mut u8; + let mut _10: (*const u8) is !null; scope 15 (inlined NonNull::<[T]>::as_ptr) { } } @@ -25,13 +27,13 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { } } scope 18 (inlined ::deallocate) { - let mut _9: *mut u8; + let mut _11: *mut u8; scope 19 (inlined Layout::size) { } scope 20 (inlined NonNull::::as_ptr) { } scope 21 (inlined std::alloc::dealloc) { - let mut _10: usize; + let mut _12: usize; scope 22 (inlined Layout::size) { } scope 23 (inlined Layout::align) { @@ -63,6 +65,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { } bb0: { + StorageLive(_3); StorageLive(_2); _2 = copy (((*_1).0: std::ptr::Unique<[T]>).0: std::ptr::NonNull<[T]>); StorageLive(_4); @@ -86,19 +89,24 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { bb2: { StorageLive(_9); _9 = copy _3 as *mut u8 (PtrToPtr); - StorageLive(_10); - _10 = discriminant(_8); - _11 = alloc::alloc::__rust_dealloc(move _9, move _5, move _10) -> [return: bb3, unwind unreachable]; + _10 = copy _9 as (*const u8) is !null (Transmute); + StorageDead(_9); + StorageLive(_11); + _11 = copy _10 as *mut u8 (Transmute); + StorageLive(_12); + _12 = discriminant(_8); + _13 = alloc::alloc::__rust_dealloc(move _11, move _5, move _12) -> [return: bb3, unwind unreachable]; } bb3: { - StorageDead(_10); - StorageDead(_9); + StorageDead(_12); + StorageDead(_11); goto -> bb4; } bb4: { StorageDead(_2); + StorageDead(_3); return; } } diff --git a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-unwind.mir b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-unwind.mir index 791d6b71a6f78..e498708b5b8df 100644 --- a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-unwind.mir @@ -8,7 +8,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { let _2: std::ptr::NonNull<[T]>; let mut _3: *mut [T]; let mut _4: *const [T]; - let _11: (); + let _13: (); scope 3 { let _8: std::ptr::alignment::AlignmentEnum; scope 4 { @@ -16,6 +16,8 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { } scope 13 (inlined Unique::<[T]>::cast::) { scope 14 (inlined NonNull::<[T]>::cast::) { + let mut _9: *mut u8; + let mut _10: (*const u8) is !null; scope 15 (inlined NonNull::<[T]>::as_ptr) { } } @@ -25,13 +27,13 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { } } scope 18 (inlined ::deallocate) { - let mut _9: *mut u8; + let mut _11: *mut u8; scope 19 (inlined Layout::size) { } scope 20 (inlined NonNull::::as_ptr) { } scope 21 (inlined std::alloc::dealloc) { - let mut _10: usize; + let mut _12: usize; scope 22 (inlined Layout::size) { } scope 23 (inlined Layout::align) { @@ -63,6 +65,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { } bb0: { + StorageLive(_3); StorageLive(_2); _2 = copy (((*_1).0: std::ptr::Unique<[T]>).0: std::ptr::NonNull<[T]>); StorageLive(_4); @@ -86,19 +89,24 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { bb2: { StorageLive(_9); _9 = copy _3 as *mut u8 (PtrToPtr); - StorageLive(_10); - _10 = discriminant(_8); - _11 = alloc::alloc::__rust_dealloc(move _9, move _5, move _10) -> [return: bb3, unwind unreachable]; + _10 = copy _9 as (*const u8) is !null (Transmute); + StorageDead(_9); + StorageLive(_11); + _11 = copy _10 as *mut u8 (Transmute); + StorageLive(_12); + _12 = discriminant(_8); + _13 = alloc::alloc::__rust_dealloc(move _11, move _5, move _12) -> [return: bb3, unwind unreachable]; } bb3: { - StorageDead(_10); - StorageDead(_9); + StorageDead(_12); + StorageDead(_11); goto -> bb4; } bb4: { StorageDead(_2); + StorageDead(_3); return; } } diff --git a/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir index 4260ec3eaedf1..7ed67824d5e78 100644 --- a/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir @@ -3,17 +3,17 @@ fn vec_move(_1: Vec) -> () { debug v => _1; let mut _0: (); - let mut _21: std::vec::IntoIter; let mut _22: std::vec::IntoIter; - let mut _23: &mut std::vec::IntoIter; - let mut _24: std::option::Option; - let mut _25: isize; - let _27: (); + let mut _23: std::vec::IntoIter; + let mut _24: &mut std::vec::IntoIter; + let mut _25: std::option::Option; + let mut _26: isize; + let _28: (); scope 1 { - debug iter => _22; - let _26: impl Sized; + debug iter => _23; + let _27: impl Sized; scope 2 { - debug x => _26; + debug x => _27; } } scope 3 (inlined as IntoIterator>::into_iter) { @@ -24,16 +24,16 @@ fn vec_move(_1: Vec) -> () { let mut _10: *mut impl Sized; let mut _11: *const impl Sized; let mut _12: usize; - let _28: &std::vec::Vec; - let mut _29: &std::mem::ManuallyDrop>; - let mut _30: &alloc::raw_vec::RawVec; - let mut _31: &std::mem::ManuallyDrop>; - let _32: &std::vec::Vec; - let mut _33: &std::mem::ManuallyDrop>; - let _34: &std::vec::Vec; - let mut _35: &std::mem::ManuallyDrop>; - let mut _36: &alloc::raw_vec::RawVec; - let mut _37: &std::mem::ManuallyDrop>; + let _29: &std::vec::Vec; + let mut _30: &std::mem::ManuallyDrop>; + let mut _31: &alloc::raw_vec::RawVec; + let mut _32: &std::mem::ManuallyDrop>; + let _33: &std::vec::Vec; + let mut _34: &std::mem::ManuallyDrop>; + let _35: &std::vec::Vec; + let mut _36: &std::mem::ManuallyDrop>; + let mut _37: &alloc::raw_vec::RawVec; + let mut _38: &std::mem::ManuallyDrop>; scope 4 { debug me => _2; scope 5 { @@ -46,33 +46,33 @@ fn vec_move(_1: Vec) -> () { debug begin => _7; scope 8 { debug end => _11; - let _19: usize; + let _20: usize; scope 9 { - debug cap => _19; + debug cap => _20; } scope 39 (inlined > as Deref>::deref) { - debug self => _37; + debug self => _38; } scope 40 (inlined alloc::raw_vec::RawVec::::capacity) { - debug self => _36; - let mut _38: &alloc::raw_vec::RawVecInner; + debug self => _37; + let mut _39: &alloc::raw_vec::RawVecInner; scope 41 (inlined std::mem::size_of::) { } scope 42 (inlined alloc::raw_vec::RawVecInner::capacity) { - debug self => _38; + debug self => _39; debug elem_size => const ::SIZE; - let mut _20: core::num::niche_types::UsizeNoHighBit; + let mut _21: (usize) is 0..=9223372036854775807; scope 43 (inlined core::num::niche_types::UsizeNoHighBit::as_inner) { - debug self => _20; + debug ((self: core::num::niche_types::UsizeNoHighBit).0: (usize) is 0..=9223372036854775807) => _21; } } } } scope 25 (inlined > as Deref>::deref) { - debug self => _33; + debug self => _34; } scope 26 (inlined Vec::::len) { - debug self => _32; + debug self => _33; let mut _13: bool; scope 27 { } @@ -82,6 +82,7 @@ fn vec_move(_1: Vec) -> () { debug count => _12; let mut _14: *mut u8; let mut _18: *mut u8; + let mut _19: *const impl Sized; scope 29 (inlined std::ptr::mut_ptr::::cast::) { debug self => _7; } @@ -98,19 +99,19 @@ fn vec_move(_1: Vec) -> () { } scope 32 (inlined std::ptr::mut_ptr::::with_metadata_of::) { debug self => _18; - debug meta => _5; + debug meta => _19; scope 33 (inlined std::ptr::metadata::) { - debug ptr => _5; + debug ptr => _19; } scope 34 (inlined std::ptr::from_raw_parts_mut::) { } } } scope 35 (inlined > as Deref>::deref) { - debug self => _35; + debug self => _36; } scope 36 (inlined Vec::::len) { - debug self => _34; + debug self => _35; let mut _9: bool; scope 37 { } @@ -125,15 +126,15 @@ fn vec_move(_1: Vec) -> () { } } scope 17 (inlined > as Deref>::deref) { - debug self => _31; + debug self => _32; } scope 18 (inlined alloc::raw_vec::RawVec::::non_null) { - debug self => _30; + debug self => _31; scope 19 (inlined alloc::raw_vec::RawVecInner::non_null::) { let mut _4: std::ptr::NonNull; scope 20 (inlined Unique::::cast::) { scope 21 (inlined NonNull::::cast::) { - let mut _5: *const impl Sized; + let mut _5: (*const impl Sized) is !null; scope 22 (inlined NonNull::::as_ptr) { } } @@ -144,10 +145,10 @@ fn vec_move(_1: Vec) -> () { } } scope 11 (inlined > as Deref>::deref) { - debug self => _29; + debug self => _30; } scope 12 (inlined Vec::::allocator) { - debug self => _28; + debug self => _29; scope 13 (inlined alloc::raw_vec::RawVec::::allocator) { scope 14 (inlined alloc::raw_vec::RawVecInner::allocator) { } @@ -166,35 +167,36 @@ fn vec_move(_1: Vec) -> () { } bb0: { - StorageLive(_21); + StorageLive(_22); StorageLive(_6); StorageLive(_7); StorageLive(_11); - StorageLive(_19); + StorageLive(_20); StorageLive(_5); - StorageLive(_4); StorageLive(_17); StorageLive(_2); _2 = ManuallyDrop::> { value: copy _1 }; StorageLive(_3); - // DBG: _29 = &_2; - // DBG: _28 = &(_2.0: std::vec::Vec); + // DBG: _30 = &_2; + // DBG: _29 = &(_2.0: std::vec::Vec); _3 = &raw const ((((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).2: std::alloc::Global); StorageDead(_3); - // DBG: _31 = &_2; - // DBG: _30 = &((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec); + // DBG: _32 = &_2; + // DBG: _31 = &((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec); + StorageLive(_4); _4 = copy (((((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).0: std::ptr::Unique).0: std::ptr::NonNull); - _5 = copy _4 as *const impl Sized (Transmute); + _5 = copy _4 as (*const impl Sized) is !null (Transmute); _6 = NonNull:: { pointer: copy _5 }; - _7 = copy _4 as *mut impl Sized (Transmute); + StorageDead(_4); + _7 = copy _5 as *mut impl Sized (Transmute); switchInt(const ::IS_ZST) -> [0: bb1, otherwise: bb2]; } bb1: { StorageLive(_10); StorageLive(_8); - // DBG: _35 = &_2; - // DBG: _34 = &(_2.0: std::vec::Vec); + // DBG: _36 = &_2; + // DBG: _35 = &(_2.0: std::vec::Vec); _8 = copy ((_2.0: std::vec::Vec).1: usize); StorageLive(_9); _9 = Le(copy _8, const ::MAX_SLICE_LEN); @@ -209,8 +211,8 @@ fn vec_move(_1: Vec) -> () { bb2: { StorageLive(_12); - // DBG: _33 = &_2; - // DBG: _32 = &(_2.0: std::vec::Vec); + // DBG: _34 = &_2; + // DBG: _33 = &(_2.0: std::vec::Vec); _12 = copy ((_2.0: std::vec::Vec).1: usize); StorageLive(_13); _13 = Le(copy _12, const ::MAX_SLICE_LEN); @@ -218,11 +220,11 @@ fn vec_move(_1: Vec) -> () { StorageDead(_13); StorageLive(_18); StorageLive(_14); - _14 = copy _4 as *mut u8 (Transmute); + _14 = copy _5 as *mut u8 (Transmute); StorageLive(_15); _15 = copy _12 as isize (IntToInt); StorageLive(_16); - _16 = copy _4 as *const u8 (Transmute); + _16 = copy _5 as *const u8 (Transmute); _17 = arith_offset::(move _16, move _15) -> [return: bb3, unwind unreachable]; } @@ -231,6 +233,9 @@ fn vec_move(_1: Vec) -> () { _18 = copy _17 as *mut u8 (PtrToPtr); StorageDead(_15); StorageDead(_14); + StorageLive(_19); + _19 = copy _5 as *const impl Sized (Transmute); + StorageDead(_19); StorageDead(_18); StorageDead(_12); _11 = copy _17 as *const impl Sized (PtrToPtr); @@ -238,69 +243,68 @@ fn vec_move(_1: Vec) -> () { } bb4: { - // DBG: _37 = &_2; - // DBG: _36 = &((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec); - // DBG: _38 = &(((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner); + // DBG: _38 = &_2; + // DBG: _37 = &((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec); + // DBG: _39 = &(((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner); + StorageLive(_21); switchInt(const ::SIZE) -> [0: bb5, otherwise: bb6]; } bb5: { - _19 = const usize::MAX; + _20 = const usize::MAX; goto -> bb7; } bb6: { - StorageLive(_20); - _20 = copy ((((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).1: core::num::niche_types::UsizeNoHighBit); - _19 = copy _20 as usize (Transmute); - StorageDead(_20); + _21 = copy (((((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).1: core::num::niche_types::UsizeNoHighBit).0: (usize) is 0..=9223372036854775807); + _20 = copy _21 as usize (Transmute); goto -> bb7; } bb7: { - _21 = std::vec::IntoIter:: { buf: copy _6, phantom: const ZeroSized: PhantomData, cap: move _19, alloc: const ManuallyDrop:: {{ value: std::alloc::Global }}, ptr: copy _6, end: copy _11 }; + StorageDead(_21); + _22 = std::vec::IntoIter:: { buf: copy _6, phantom: const ZeroSized: PhantomData, cap: move _20, alloc: const ManuallyDrop:: {{ value: std::alloc::Global }}, ptr: copy _6, end: copy _11 }; StorageDead(_2); StorageDead(_17); - StorageDead(_4); StorageDead(_5); - StorageDead(_19); + StorageDead(_20); StorageDead(_11); StorageDead(_7); StorageDead(_6); - StorageLive(_22); - _22 = move _21; + StorageLive(_23); + _23 = move _22; goto -> bb8; } bb8: { - StorageLive(_24); - _23 = &mut _22; - _24 = as Iterator>::next(move _23) -> [return: bb9, unwind: bb15]; + StorageLive(_25); + _24 = &mut _23; + _25 = as Iterator>::next(move _24) -> [return: bb9, unwind: bb15]; } bb9: { - _25 = discriminant(_24); - switchInt(move _25) -> [0: bb10, 1: bb12, otherwise: bb14]; + _26 = discriminant(_25); + switchInt(move _26) -> [0: bb10, 1: bb12, otherwise: bb14]; } bb10: { - StorageDead(_24); - drop(_22) -> [return: bb11, unwind continue]; + StorageDead(_25); + drop(_23) -> [return: bb11, unwind continue]; } bb11: { + StorageDead(_23); StorageDead(_22); - StorageDead(_21); return; } bb12: { - _26 = move ((_24 as Some).0: impl Sized); - _27 = opaque::(move _26) -> [return: bb13, unwind: bb15]; + _27 = move ((_25 as Some).0: impl Sized); + _28 = opaque::(move _27) -> [return: bb13, unwind: bb15]; } bb13: { - StorageDead(_24); + StorageDead(_25); goto -> bb8; } @@ -309,7 +313,7 @@ fn vec_move(_1: Vec) -> () { } bb15 (cleanup): { - drop(_22) -> [return: bb16, unwind terminate(cleanup)]; + drop(_23) -> [return: bb16, unwind terminate(cleanup)]; } bb16 (cleanup): { diff --git a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir index 28b12cdf36755..5eacef047621d 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir @@ -4,33 +4,33 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { debug slice => _1; debug f => _2; let mut _0: (); - let mut _10: std::slice::Iter<'_, T>; - let mut _11: std::iter::Enumerate>; - let mut _12: std::iter::Enumerate>; - let mut _13: &mut std::iter::Enumerate>; - let mut _14: std::option::Option<(usize, &T)>; - let mut _15: isize; - let mut _18: &impl Fn(usize, &T); - let mut _19: (usize, &T); - let _20: (); + let mut _13: std::slice::Iter<'_, T>; + let mut _14: std::iter::Enumerate>; + let mut _15: std::iter::Enumerate>; + let mut _16: &mut std::iter::Enumerate>; + let mut _17: std::option::Option<(usize, &T)>; + let mut _18: isize; + let mut _21: &impl Fn(usize, &T); + let mut _22: (usize, &T); + let _23: (); scope 1 { - debug iter => _12; - let _16: usize; - let _17: &T; + debug iter => _15; + let _19: usize; + let _20: &T; scope 2 { - debug i => _16; - debug x => _17; + debug i => _19; + debug x => _20; } } scope 3 (inlined core::slice::::iter) { scope 4 (inlined std::slice::Iter::<'_, T>::new) { let _3: usize; - let mut _7: *mut T; - let mut _8: *mut T; + let mut _10: *mut T; + let mut _11: *mut T; scope 5 { - let _6: std::ptr::NonNull; + let _9: std::ptr::NonNull; scope 6 { - let _9: *const T; + let _12: *const T; scope 7 { } scope 11 (inlined std::ptr::without_provenance::) { @@ -44,9 +44,12 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } scope 8 (inlined NonNull::<[T]>::from_ref) { let mut _4: *const [T]; + let mut _5: (*const [T]) is !null; } scope 9 (inlined NonNull::<[T]>::cast::) { - let mut _5: *const T; + let mut _6: *mut [T]; + let mut _7: *mut T; + let mut _8: (*const T) is !null; scope 10 (inlined NonNull::<[T]>::as_ptr) { } } @@ -61,61 +64,70 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } bb0: { - StorageLive(_10); + StorageLive(_13); StorageLive(_3); - StorageLive(_6); StorageLive(_9); - StorageLive(_4); + StorageLive(_12); + StorageLive(_5); + StorageLive(_8); _3 = PtrMetadata(copy _1); + StorageLive(_4); _4 = &raw const (*_1); - StorageLive(_5); - _5 = copy _4 as *const T (PtrToPtr); - _6 = NonNull:: { pointer: copy _5 }; - StorageDead(_5); + _5 = copy _4 as (*const [T]) is !null (Transmute); + StorageDead(_4); + StorageLive(_7); + StorageLive(_6); + _6 = copy _5 as *mut [T] (Transmute); + _7 = copy _6 as *mut T (PtrToPtr); + StorageDead(_6); + _8 = copy _7 as (*const T) is !null (Transmute); + StorageDead(_7); + _9 = NonNull:: { pointer: copy _8 }; switchInt(const ::IS_ZST) -> [0: bb1, otherwise: bb2]; } bb1: { - StorageLive(_8); - StorageLive(_7); - _7 = copy _4 as *mut T (PtrToPtr); - _8 = Offset(copy _7, copy _3); - StorageDead(_7); - _9 = copy _8 as *const T (PtrToPtr); - StorageDead(_8); + StorageLive(_11); + StorageLive(_10); + _10 = copy _8 as *mut T (Transmute); + _11 = Offset(copy _10, copy _3); + StorageDead(_10); + _12 = copy _11 as *const T (PtrToPtr); + StorageDead(_11); goto -> bb3; } bb2: { - _9 = copy _3 as *const T (Transmute); + _12 = copy _3 as *const T (Transmute); goto -> bb3; } bb3: { - _10 = std::slice::Iter::<'_, T> { ptr: copy _6, end_or_len: copy _9, _marker: const ZeroSized: PhantomData<&T> }; - StorageDead(_4); + _13 = std::slice::Iter::<'_, T> { ptr: copy _9, end_or_len: copy _12, _marker: const ZeroSized: PhantomData<&T> }; + StorageDead(_8); + StorageDead(_5); + StorageDead(_12); StorageDead(_9); - StorageDead(_6); StorageDead(_3); - _11 = Enumerate::> { iter: copy _10, count: const 0_usize }; - StorageDead(_10); - StorageLive(_12); - _12 = copy _11; + _14 = Enumerate::> { iter: copy _13, count: const 0_usize }; + StorageDead(_13); + StorageLive(_15); + _15 = copy _14; goto -> bb4; } bb4: { - _13 = &mut _12; - _14 = > as Iterator>::next(move _13) -> [return: bb5, unwind: bb11]; + _16 = &mut _15; + _17 = > as Iterator>::next(move _16) -> [return: bb5, unwind: bb11]; } bb5: { - _15 = discriminant(_14); - switchInt(move _15) -> [0: bb6, 1: bb8, otherwise: bb10]; + _18 = discriminant(_17); + switchInt(move _18) -> [0: bb6, 1: bb8, otherwise: bb10]; } bb6: { - StorageDead(_12); + StorageDead(_15); drop(_2) -> [return: bb7, unwind continue]; } @@ -124,18 +136,18 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } bb8: { - _16 = copy (((_14 as Some).0: (usize, &T)).0: usize); - _17 = copy (((_14 as Some).0: (usize, &T)).1: &T); - StorageLive(_18); - _18 = &_2; - StorageLive(_19); - _19 = copy ((_14 as Some).0: (usize, &T)); - _20 = >::call(move _18, move _19) -> [return: bb9, unwind: bb11]; + _19 = copy (((_17 as Some).0: (usize, &T)).0: usize); + _20 = copy (((_17 as Some).0: (usize, &T)).1: &T); + StorageLive(_21); + _21 = &_2; + StorageLive(_22); + _22 = copy ((_17 as Some).0: (usize, &T)); + _23 = >::call(move _21, move _22) -> [return: bb9, unwind: bb11]; } bb9: { - StorageDead(_19); - StorageDead(_18); + StorageDead(_22); + StorageDead(_21); goto -> bb4; } diff --git a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir index 2b5d8c27d7109..88e240ab33752 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir @@ -4,29 +4,29 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { debug slice => _1; debug f => _2; let mut _0: (); - let mut _22: std::option::Option<&T>; - let mut _24: &impl Fn(&T); - let mut _25: (&T,); - let _26: (); + let mut _25: std::option::Option<&T>; + let mut _27: &impl Fn(&T); + let mut _28: (&T,); + let _29: (); scope 1 { - debug ((iter: std::slice::Iter<'_, T>).0: std::ptr::NonNull) => _6; - debug ((iter: std::slice::Iter<'_, T>).1: *const T) => _9; + debug ((iter: std::slice::Iter<'_, T>).0: std::ptr::NonNull) => _9; + debug ((iter: std::slice::Iter<'_, T>).1: *const T) => _12; debug ((iter: std::slice::Iter<'_, T>).2: std::marker::PhantomData<&T>) => const ZeroSized: PhantomData<&T>; - let _23: &T; + let _26: &T; scope 2 { - debug x => _23; + debug x => _26; } scope 16 (inlined as Iterator>::next) { - let mut _6: std::ptr::NonNull; - let _10: std::ptr::NonNull; - let _12: std::ptr::NonNull; - let mut _15: bool; - let mut _19: usize; - let _21: &T; + let mut _9: std::ptr::NonNull; + let _13: std::ptr::NonNull; + let _15: std::ptr::NonNull; + let mut _18: bool; + let mut _22: usize; + let _24: &T; scope 17 { - let _11: *const T; + let _14: *const T; scope 18 { - let _18: usize; + let _21: usize; scope 19 { scope 22 (inlined #[track_caller] core::num::::unchecked_sub) { scope 23 (inlined core::ub_checks::check_language_ub) { @@ -42,21 +42,21 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } } scope 26 (inlined as PartialEq>::eq) { - let mut _13: *mut T; - let mut _14: *mut T; + let mut _16: *mut T; + let mut _17: *mut T; scope 27 (inlined NonNull::::as_ptr) { } scope 28 (inlined NonNull::::as_ptr) { } } scope 29 (inlined NonNull::::add) { - let mut _16: *const T; - let mut _17: *const T; + let mut _19: *mut T; + let mut _20: (*const T) is !null; scope 30 (inlined NonNull::::as_ptr) { } } scope 31 (inlined NonNull::::as_ref::<'_>) { - let _20: *const T; + let _23: *const T; scope 32 (inlined NonNull::::as_ptr) { } scope 33 (inlined std::ptr::mut_ptr::::cast_const) { @@ -69,11 +69,11 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { scope 3 (inlined core::slice::::iter) { scope 4 (inlined std::slice::Iter::<'_, T>::new) { let _3: usize; - let mut _7: *mut T; - let mut _8: *mut T; + let mut _10: *mut T; + let mut _11: *mut T; scope 5 { scope 6 { - let _9: *const T; + let _12: *const T; scope 7 { } scope 11 (inlined std::ptr::without_provenance::) { @@ -87,9 +87,12 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } scope 8 (inlined NonNull::<[T]>::from_ref) { let mut _4: *const [T]; + let mut _5: (*const [T]) is !null; } scope 9 (inlined NonNull::<[T]>::cast::) { - let mut _5: *const T; + let mut _6: *mut [T]; + let mut _7: *mut T; + let mut _8: (*const T) is !null; scope 10 (inlined NonNull::<[T]>::as_ptr) { } } @@ -101,104 +104,114 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { bb0: { StorageLive(_3); - StorageLive(_4); + StorageLive(_5); + StorageLive(_8); _3 = PtrMetadata(copy _1); + StorageLive(_4); _4 = &raw const (*_1); - StorageLive(_5); - _5 = copy _4 as *const T (PtrToPtr); - _6 = NonNull:: { pointer: copy _5 }; - StorageDead(_5); + _5 = copy _4 as (*const [T]) is !null (Transmute); + StorageDead(_4); + StorageLive(_7); + StorageLive(_6); + _6 = copy _5 as *mut [T] (Transmute); + _7 = copy _6 as *mut T (PtrToPtr); + StorageDead(_6); + _8 = copy _7 as (*const T) is !null (Transmute); + StorageDead(_7); + _9 = NonNull:: { pointer: copy _8 }; switchInt(const ::IS_ZST) -> [0: bb1, otherwise: bb2]; } bb1: { - StorageLive(_8); - StorageLive(_7); - _7 = copy _4 as *mut T (PtrToPtr); - _8 = Offset(copy _7, copy _3); - StorageDead(_7); - _9 = copy _8 as *const T (PtrToPtr); - StorageDead(_8); + StorageLive(_11); + StorageLive(_10); + _10 = copy _8 as *mut T (Transmute); + _11 = Offset(copy _10, copy _3); + StorageDead(_10); + _12 = copy _11 as *const T (PtrToPtr); + StorageDead(_11); goto -> bb3; } bb2: { - _9 = copy _3 as *const T (Transmute); + _12 = copy _3 as *const T (Transmute); goto -> bb3; } bb3: { - StorageDead(_4); + StorageDead(_8); + StorageDead(_5); StorageDead(_3); goto -> bb4; } bb4: { - StorageLive(_22); - StorageLive(_10); - StorageLive(_11); - StorageLive(_18); - StorageLive(_19); - StorageLive(_12); + StorageLive(_25); + StorageLive(_13); + StorageLive(_14); StorageLive(_21); - _10 = copy _6; - _11 = copy _9; + StorageLive(_22); + StorageLive(_15); + StorageLive(_24); + StorageLive(_16); + _13 = copy _9; + _14 = copy _12; switchInt(const ::IS_ZST) -> [0: bb5, otherwise: bb8]; } bb5: { - StorageLive(_15); - _12 = copy _11 as std::ptr::NonNull (Transmute); - StorageLive(_13); - _13 = copy _10 as *mut T (Transmute); - StorageLive(_14); - _14 = copy _12 as *mut T (Transmute); - _15 = Eq(copy _13, copy _14); - StorageDead(_14); - StorageDead(_13); - switchInt(move _15) -> [0: bb6, otherwise: bb7]; + StorageLive(_18); + _15 = copy _14 as std::ptr::NonNull (Transmute); + _16 = copy _13 as *mut T (Transmute); + StorageLive(_17); + _17 = copy _15 as *mut T (Transmute); + _18 = Eq(copy _16, copy _17); + StorageDead(_17); + switchInt(move _18) -> [0: bb6, otherwise: bb7]; } bb6: { - StorageDead(_15); - StorageLive(_17); - StorageLive(_16); - _16 = copy _10 as *const T (Transmute); - _17 = Offset(copy _16, const 1_usize); - StorageDead(_16); - _6 = NonNull:: { pointer: copy _17 }; - StorageDead(_17); + StorageDead(_18); + StorageLive(_20); + StorageLive(_19); + _19 = Offset(copy _16, const 1_usize); + _20 = copy _19 as (*const T) is !null (Transmute); + StorageDead(_19); + _9 = NonNull:: { pointer: move _20 }; + StorageDead(_20); goto -> bb13; } bb7: { + StorageDead(_18); + StorageDead(_16); + StorageDead(_24); StorageDead(_15); + StorageDead(_22); StorageDead(_21); - StorageDead(_12); - StorageDead(_19); - StorageDead(_18); - StorageDead(_11); - StorageDead(_10); + StorageDead(_14); + StorageDead(_13); goto -> bb10; } bb8: { - _18 = copy _11 as usize (Transmute); - switchInt(copy _18) -> [0: bb9, otherwise: bb12]; + _21 = copy _14 as usize (Transmute); + switchInt(copy _21) -> [0: bb9, otherwise: bb12]; } bb9: { + StorageDead(_16); + StorageDead(_24); + StorageDead(_15); + StorageDead(_22); StorageDead(_21); - StorageDead(_12); - StorageDead(_19); - StorageDead(_18); - StorageDead(_11); - StorageDead(_10); + StorageDead(_14); + StorageDead(_13); goto -> bb10; } bb10: { - StorageDead(_22); + StorageDead(_25); drop(_2) -> [return: bb11, unwind continue]; } @@ -207,35 +220,36 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb12: { - _19 = SubUnchecked(copy _18, const 1_usize); - _9 = copy _19 as *const T (Transmute); + _22 = SubUnchecked(copy _21, const 1_usize); + _12 = copy _22 as *const T (Transmute); goto -> bb13; } bb13: { - StorageLive(_20); - _20 = copy _10 as *const T (Transmute); - _21 = &(*_20); - StorageDead(_20); - _22 = Option::<&T>::Some(copy _21); + StorageLive(_23); + _23 = copy _13 as *const T (Transmute); + _24 = &(*_23); + StorageDead(_23); + _25 = Option::<&T>::Some(copy _24); + StorageDead(_16); + StorageDead(_24); + StorageDead(_15); + StorageDead(_22); StorageDead(_21); - StorageDead(_12); - StorageDead(_19); - StorageDead(_18); - StorageDead(_11); - StorageDead(_10); - _23 = copy ((_22 as Some).0: &T); - StorageLive(_24); - _24 = &_2; - StorageLive(_25); - _25 = (copy _23,); - _26 = >::call(move _24, move _25) -> [return: bb14, unwind: bb15]; + StorageDead(_14); + StorageDead(_13); + _26 = copy ((_25 as Some).0: &T); + StorageLive(_27); + _27 = &_2; + StorageLive(_28); + _28 = (copy _26,); + _29 = >::call(move _27, move _28) -> [return: bb14, unwind: bb15]; } bb14: { + StorageDead(_28); + StorageDead(_27); StorageDead(_25); - StorageDead(_24); - StorageDead(_22); goto -> bb4; } diff --git a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir index e40bff5ea3504..8f4c79166a2f7 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir @@ -4,35 +4,35 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { debug slice => _1; debug f => _2; let mut _0: (); - let mut _10: std::slice::Iter<'_, T>; - let mut _11: std::iter::Rev>; - let mut _12: std::iter::Rev>; - let mut _33: std::option::Option<&T>; - let mut _35: &impl Fn(&T); - let mut _36: (&T,); - let _37: (); + let mut _13: std::slice::Iter<'_, T>; + let mut _14: std::iter::Rev>; + let mut _15: std::iter::Rev>; + let mut _37: std::option::Option<&T>; + let mut _39: &impl Fn(&T); + let mut _40: (&T,); + let _41: (); scope 1 { - debug iter => _12; - let _34: &T; + debug iter => _15; + let _38: &T; scope 2 { - debug x => _34; + debug x => _38; } scope 18 (inlined > as Iterator>::next) { scope 19 (inlined as DoubleEndedIterator>::next_back) { - let mut _13: *const T; - let mut _18: bool; - let mut _19: *const T; - let _32: &T; + let mut _16: *const T; + let mut _21: bool; + let mut _22: *const T; + let _36: &T; scope 20 { - let _14: std::ptr::NonNull; - let _20: usize; + let _17: std::ptr::NonNull; + let _23: usize; scope 21 { } scope 22 { scope 25 (inlined as PartialEq>::eq) { - let mut _15: std::ptr::NonNull; - let mut _16: *mut T; - let mut _17: *mut T; + let mut _18: std::ptr::NonNull; + let mut _19: *mut T; + let mut _20: *mut T; scope 26 (inlined NonNull::::as_ptr) { } scope 27 (inlined NonNull::::as_ptr) { @@ -45,15 +45,15 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { } } scope 28 (inlined std::slice::Iter::<'_, T>::next_back_unchecked) { - let _26: std::ptr::NonNull; + let _30: std::ptr::NonNull; scope 29 (inlined std::slice::Iter::<'_, T>::pre_dec_end) { - let mut _21: *mut *const T; - let mut _22: *mut std::ptr::NonNull; - let mut _23: std::ptr::NonNull; - let mut _27: *mut *const T; - let mut _28: *mut usize; - let mut _29: usize; - let mut _30: usize; + let mut _24: *mut *const T; + let mut _25: *mut std::ptr::NonNull; + let mut _26: std::ptr::NonNull; + let mut _31: *mut *const T; + let mut _32: *mut usize; + let mut _33: usize; + let mut _34: usize; scope 30 { scope 31 { } @@ -66,8 +66,9 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { } } scope 39 (inlined NonNull::::offset) { - let mut _24: *const T; - let mut _25: *const T; + let mut _27: *mut T; + let mut _28: *mut T; + let mut _29: (*const T) is !null; scope 40 (inlined NonNull::::as_ptr) { } } @@ -80,7 +81,7 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { } } scope 41 (inlined NonNull::::as_ref::<'_>) { - let _31: *const T; + let _35: *const T; scope 42 (inlined NonNull::::as_ptr) { } scope 43 (inlined std::ptr::mut_ptr::::cast_const) { @@ -93,12 +94,12 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { scope 3 (inlined core::slice::::iter) { scope 4 (inlined std::slice::Iter::<'_, T>::new) { let _3: usize; - let mut _7: *mut T; - let mut _8: *mut T; + let mut _10: *mut T; + let mut _11: *mut T; scope 5 { - let _6: std::ptr::NonNull; + let _9: std::ptr::NonNull; scope 6 { - let _9: *const T; + let _12: *const T; scope 7 { } scope 11 (inlined std::ptr::without_provenance::) { @@ -112,9 +113,12 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { } scope 8 (inlined NonNull::<[T]>::from_ref) { let mut _4: *const [T]; + let mut _5: (*const [T]) is !null; } scope 9 (inlined NonNull::<[T]>::cast::) { - let mut _5: *const T; + let mut _6: *mut [T]; + let mut _7: *mut T; + let mut _8: (*const T) is !null; scope 10 (inlined NonNull::<[T]>::as_ptr) { } } @@ -129,165 +133,177 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb0: { - StorageLive(_10); + StorageLive(_13); StorageLive(_3); - StorageLive(_6); StorageLive(_9); - StorageLive(_4); + StorageLive(_12); + StorageLive(_5); + StorageLive(_8); _3 = PtrMetadata(copy _1); + StorageLive(_4); _4 = &raw const (*_1); - StorageLive(_5); - _5 = copy _4 as *const T (PtrToPtr); - _6 = NonNull:: { pointer: copy _5 }; - StorageDead(_5); + _5 = copy _4 as (*const [T]) is !null (Transmute); + StorageDead(_4); + StorageLive(_7); + StorageLive(_6); + _6 = copy _5 as *mut [T] (Transmute); + _7 = copy _6 as *mut T (PtrToPtr); + StorageDead(_6); + _8 = copy _7 as (*const T) is !null (Transmute); + StorageDead(_7); + _9 = NonNull:: { pointer: copy _8 }; switchInt(const ::IS_ZST) -> [0: bb1, otherwise: bb2]; } bb1: { - StorageLive(_8); - StorageLive(_7); - _7 = copy _4 as *mut T (PtrToPtr); - _8 = Offset(copy _7, copy _3); - StorageDead(_7); - _9 = copy _8 as *const T (PtrToPtr); - StorageDead(_8); + StorageLive(_11); + StorageLive(_10); + _10 = copy _8 as *mut T (Transmute); + _11 = Offset(copy _10, copy _3); + StorageDead(_10); + _12 = copy _11 as *const T (PtrToPtr); + StorageDead(_11); goto -> bb3; } bb2: { - _9 = copy _3 as *const T (Transmute); + _12 = copy _3 as *const T (Transmute); goto -> bb3; } bb3: { - _10 = std::slice::Iter::<'_, T> { ptr: copy _6, end_or_len: copy _9, _marker: const ZeroSized: PhantomData<&T> }; - StorageDead(_4); + _13 = std::slice::Iter::<'_, T> { ptr: copy _9, end_or_len: copy _12, _marker: const ZeroSized: PhantomData<&T> }; + StorageDead(_8); + StorageDead(_5); + StorageDead(_12); StorageDead(_9); - StorageDead(_6); StorageDead(_3); - _11 = Rev::> { iter: copy _10 }; - StorageDead(_10); - StorageLive(_12); - _12 = copy _11; + _14 = Rev::> { iter: copy _13 }; + StorageDead(_13); + StorageLive(_15); + _15 = copy _14; goto -> bb4; } bb4: { - StorageLive(_33); - StorageLive(_20); - StorageLive(_19); - StorageLive(_14); - StorageLive(_32); - StorageLive(_18); + StorageLive(_37); + StorageLive(_23); + StorageLive(_22); + StorageLive(_17); + StorageLive(_36); + StorageLive(_21); switchInt(const ::IS_ZST) -> [0: bb5, otherwise: bb6]; } bb5: { - StorageLive(_13); - _13 = copy ((_12.0: std::slice::Iter<'_, T>).1: *const T); - _14 = copy _13 as std::ptr::NonNull (Transmute); - StorageDead(_13); StorageLive(_16); - StorageLive(_15); - _15 = copy ((_12.0: std::slice::Iter<'_, T>).0: std::ptr::NonNull); - _16 = copy _15 as *mut T (Transmute); - StorageDead(_15); - StorageLive(_17); - _17 = copy _14 as *mut T (Transmute); - _18 = Eq(copy _16, copy _17); - StorageDead(_17); + _16 = copy ((_15.0: std::slice::Iter<'_, T>).1: *const T); + _17 = copy _16 as std::ptr::NonNull (Transmute); StorageDead(_16); + StorageLive(_19); + StorageLive(_18); + _18 = copy ((_15.0: std::slice::Iter<'_, T>).0: std::ptr::NonNull); + _19 = copy _18 as *mut T (Transmute); + StorageDead(_18); + StorageLive(_20); + _20 = copy _17 as *mut T (Transmute); + _21 = Eq(copy _19, copy _20); + StorageDead(_20); + StorageDead(_19); goto -> bb7; } bb6: { - _19 = copy ((_12.0: std::slice::Iter<'_, T>).1: *const T); - _20 = copy _19 as usize (Transmute); - _18 = Eq(copy _20, const 0_usize); + _22 = copy ((_15.0: std::slice::Iter<'_, T>).1: *const T); + _23 = copy _22 as usize (Transmute); + _21 = Eq(copy _23, const 0_usize); goto -> bb7; } bb7: { - switchInt(move _18) -> [0: bb8, otherwise: bb17]; + switchInt(move _21) -> [0: bb8, otherwise: bb17]; } bb8: { + StorageLive(_30); + StorageLive(_32); + StorageLive(_25); StorageLive(_26); - StorageLive(_28); - StorageLive(_22); - StorageLive(_23); switchInt(const ::IS_ZST) -> [0: bb9, otherwise: bb12]; } bb9: { - StorageLive(_21); - _21 = &raw mut ((_12.0: std::slice::Iter<'_, T>).1: *const T); - _22 = copy _21 as *mut std::ptr::NonNull (PtrToPtr); - StorageDead(_21); - _23 = copy (*_22); + StorageLive(_24); + _24 = &raw mut ((_15.0: std::slice::Iter<'_, T>).1: *const T); + _25 = copy _24 as *mut std::ptr::NonNull (PtrToPtr); + StorageDead(_24); + _26 = copy (*_25); switchInt(const ::IS_ZST) -> [0: bb10, otherwise: bb11]; } bb10: { - StorageLive(_25); - StorageLive(_24); - _24 = copy _23 as *const T (Transmute); - _25 = Offset(copy _24, const -1_isize); - StorageDead(_24); - _23 = NonNull:: { pointer: copy _25 }; - StorageDead(_25); + StorageLive(_29); + StorageLive(_28); + StorageLive(_27); + _27 = copy _26 as *mut T (Transmute); + _28 = Offset(copy _27, const -1_isize); + StorageDead(_27); + _29 = copy _28 as (*const T) is !null (Transmute); + StorageDead(_28); + _26 = NonNull:: { pointer: move _29 }; + StorageDead(_29); goto -> bb11; } bb11: { - (*_22) = move _23; - _26 = copy (*_22); + (*_25) = move _26; + _30 = copy (*_25); goto -> bb13; } bb12: { - StorageLive(_27); - _27 = &raw mut ((_12.0: std::slice::Iter<'_, T>).1: *const T); - _28 = copy _27 as *mut usize (PtrToPtr); - StorageDead(_27); - StorageLive(_30); - StorageLive(_29); - _29 = copy (*_28); - _30 = SubUnchecked(move _29, const 1_usize); - StorageDead(_29); - (*_28) = move _30; - StorageDead(_30); - _26 = copy ((_12.0: std::slice::Iter<'_, T>).0: std::ptr::NonNull); + StorageLive(_31); + _31 = &raw mut ((_15.0: std::slice::Iter<'_, T>).1: *const T); + _32 = copy _31 as *mut usize (PtrToPtr); + StorageDead(_31); + StorageLive(_34); + StorageLive(_33); + _33 = copy (*_32); + _34 = SubUnchecked(move _33, const 1_usize); + StorageDead(_33); + (*_32) = move _34; + StorageDead(_34); + _30 = copy ((_15.0: std::slice::Iter<'_, T>).0: std::ptr::NonNull); goto -> bb13; } bb13: { - StorageDead(_23); - StorageDead(_22); - StorageDead(_28); - StorageLive(_31); - _31 = copy _26 as *const T (Transmute); - _32 = &(*_31); - StorageDead(_31); StorageDead(_26); - _33 = Option::<&T>::Some(copy _32); - StorageDead(_18); + StorageDead(_25); StorageDead(_32); - StorageDead(_14); - StorageDead(_19); - StorageDead(_20); - _34 = copy ((_33 as Some).0: &T); StorageLive(_35); - _35 = &_2; - StorageLive(_36); - _36 = (copy _34,); - _37 = >::call(move _35, move _36) -> [return: bb14, unwind: bb15]; + _35 = copy _30 as *const T (Transmute); + _36 = &(*_35); + StorageDead(_35); + StorageDead(_30); + _37 = Option::<&T>::Some(copy _36); + StorageDead(_21); + StorageDead(_36); + StorageDead(_17); + StorageDead(_22); + StorageDead(_23); + _38 = copy ((_37 as Some).0: &T); + StorageLive(_39); + _39 = &_2; + StorageLive(_40); + _40 = (copy _38,); + _41 = >::call(move _39, move _40) -> [return: bb14, unwind: bb15]; } bb14: { - StorageDead(_36); - StorageDead(_35); - StorageDead(_33); + StorageDead(_40); + StorageDead(_39); + StorageDead(_37); goto -> bb4; } @@ -300,13 +316,13 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb17: { - StorageDead(_18); - StorageDead(_32); - StorageDead(_14); - StorageDead(_19); - StorageDead(_20); - StorageDead(_33); - StorageDead(_12); + StorageDead(_21); + StorageDead(_36); + StorageDead(_17); + StorageDead(_22); + StorageDead(_23); + StorageDead(_37); + StorageDead(_15); drop(_2) -> [return: bb18, unwind continue]; } diff --git a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.panic-unwind.mir index 62b738c36bf4b..1f2d7d7c81f04 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.panic-unwind.mir @@ -7,7 +7,7 @@ fn slice_iter_mut_next_back(_1: &mut std::slice::IterMut<'_, T>) -> Option<&mut let mut _2: *mut T; let mut _7: bool; let mut _8: *mut T; - let mut _21: &mut T; + let mut _22: &mut T; scope 2 { let _3: std::ptr::NonNull; let _9: usize; @@ -30,15 +30,15 @@ fn slice_iter_mut_next_back(_1: &mut std::slice::IterMut<'_, T>) -> Option<&mut } } scope 10 (inlined std::slice::IterMut::<'_, T>::next_back_unchecked) { - let mut _15: std::ptr::NonNull; + let mut _16: std::ptr::NonNull; scope 11 (inlined std::slice::IterMut::<'_, T>::pre_dec_end) { let mut _10: *mut *mut T; let mut _11: *mut std::ptr::NonNull; let mut _12: std::ptr::NonNull; - let mut _16: *mut *mut T; - let mut _17: *mut usize; - let mut _18: usize; + let mut _17: *mut *mut T; + let mut _18: *mut usize; let mut _19: usize; + let mut _20: usize; scope 12 { scope 13 { } @@ -51,8 +51,9 @@ fn slice_iter_mut_next_back(_1: &mut std::slice::IterMut<'_, T>) -> Option<&mut } } scope 21 (inlined NonNull::::offset) { - let mut _13: *const T; - let mut _14: *const T; + let mut _13: *mut T; + let mut _14: *mut T; + let mut _15: (*const T) is !null; scope 22 (inlined NonNull::::as_ptr) { } } @@ -65,7 +66,7 @@ fn slice_iter_mut_next_back(_1: &mut std::slice::IterMut<'_, T>) -> Option<&mut } } scope 23 (inlined NonNull::::as_mut::<'_>) { - let mut _20: *mut T; + let mut _21: *mut T; scope 24 (inlined NonNull::::as_ptr) { } } @@ -77,7 +78,7 @@ fn slice_iter_mut_next_back(_1: &mut std::slice::IterMut<'_, T>) -> Option<&mut StorageLive(_8); StorageLive(_3); StorageLive(_2); - StorageLive(_21); + StorageLive(_22); StorageLive(_7); switchInt(const ::IS_ZST) -> [0: bb1, otherwise: bb2]; } @@ -110,8 +111,8 @@ fn slice_iter_mut_next_back(_1: &mut std::slice::IterMut<'_, T>) -> Option<&mut } bb4: { - StorageLive(_15); - StorageLive(_17); + StorageLive(_16); + StorageLive(_18); StorageLive(_11); StorageLive(_12); switchInt(const ::IS_ZST) -> [0: bb5, otherwise: bb8]; @@ -127,48 +128,51 @@ fn slice_iter_mut_next_back(_1: &mut std::slice::IterMut<'_, T>) -> Option<&mut } bb6: { + StorageLive(_15); StorageLive(_14); StorageLive(_13); - _13 = copy _12 as *const T (Transmute); + _13 = copy _12 as *mut T (Transmute); _14 = Offset(copy _13, const -1_isize); StorageDead(_13); - _12 = NonNull:: { pointer: copy _14 }; + _15 = copy _14 as (*const T) is !null (Transmute); StorageDead(_14); + _12 = NonNull:: { pointer: move _15 }; + StorageDead(_15); goto -> bb7; } bb7: { (*_11) = move _12; - _15 = copy (*_11); + _16 = copy (*_11); goto -> bb9; } bb8: { - StorageLive(_16); - _16 = &raw mut ((*_1).1: *mut T); - _17 = copy _16 as *mut usize (PtrToPtr); - StorageDead(_16); + StorageLive(_17); + _17 = &raw mut ((*_1).1: *mut T); + _18 = copy _17 as *mut usize (PtrToPtr); + StorageDead(_17); + StorageLive(_20); StorageLive(_19); - StorageLive(_18); - _18 = copy (*_17); - _19 = SubUnchecked(move _18, const 1_usize); - StorageDead(_18); - (*_17) = move _19; + _19 = copy (*_18); + _20 = SubUnchecked(move _19, const 1_usize); StorageDead(_19); - _15 = copy ((*_1).0: std::ptr::NonNull); + (*_18) = move _20; + StorageDead(_20); + _16 = copy ((*_1).0: std::ptr::NonNull); goto -> bb9; } bb9: { StorageDead(_12); StorageDead(_11); - StorageDead(_17); - StorageLive(_20); - _20 = copy _15 as *mut T (Transmute); - _21 = &mut (*_20); - StorageDead(_20); - StorageDead(_15); - _0 = Option::<&mut T>::Some(copy _21); + StorageDead(_18); + StorageLive(_21); + _21 = copy _16 as *mut T (Transmute); + _22 = &mut (*_21); + StorageDead(_21); + StorageDead(_16); + _0 = Option::<&mut T>::Some(copy _22); goto -> bb11; } @@ -179,7 +183,7 @@ fn slice_iter_mut_next_back(_1: &mut std::slice::IterMut<'_, T>) -> Option<&mut bb11: { StorageDead(_7); - StorageDead(_21); + StorageDead(_22); StorageDead(_2); StorageDead(_3); StorageDead(_8); diff --git a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-unwind.mir index cc0fce26149e3..6cf1c59158e87 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-unwind.mir @@ -37,8 +37,8 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { } } scope 14 (inlined NonNull::::add) { - let mut _8: *const T; - let mut _9: *const T; + let mut _8: *mut T; + let mut _9: (*const T) is !null; scope 15 (inlined NonNull::::as_ptr) { } } @@ -60,6 +60,7 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { StorageLive(_12); StorageLive(_4); StorageLive(_14); + StorageLive(_5); _2 = copy ((*_1).0: std::ptr::NonNull); _3 = copy ((*_1).1: *const T); switchInt(const ::IS_ZST) -> [0: bb1, otherwise: bb4]; @@ -68,13 +69,11 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { bb1: { StorageLive(_7); _4 = copy _3 as std::ptr::NonNull (Transmute); - StorageLive(_5); _5 = copy _2 as *mut T (Transmute); StorageLive(_6); _6 = copy _4 as *mut T (Transmute); _7 = Eq(copy _5, copy _6); StorageDead(_6); - StorageDead(_5); switchInt(move _7) -> [0: bb2, otherwise: bb3]; } @@ -83,10 +82,10 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { StorageLive(_10); StorageLive(_9); StorageLive(_8); - _8 = copy _2 as *const T (Transmute); - _9 = Offset(copy _8, const 1_usize); + _8 = Offset(copy _5, const 1_usize); + _9 = copy _8 as (*const T) is !null (Transmute); StorageDead(_8); - _10 = NonNull:: { pointer: copy _9 }; + _10 = NonNull:: { pointer: move _9 }; StorageDead(_9); ((*_1).0: std::ptr::NonNull) = move _10; StorageDead(_10); @@ -125,6 +124,7 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { } bb8: { + StorageDead(_5); StorageDead(_14); StorageDead(_4); StorageDead(_12); diff --git a/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-abort.mir index 2eee8a97db0d4..7a656ba12956c 100644 --- a/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-abort.mir @@ -7,8 +7,8 @@ fn vec_deref_to_slice(_1: &Vec) -> &[u8] { debug self => _1; scope 2 (inlined Vec::::as_slice) { debug self => _1; - let mut _3: *const u8; - let mut _4: usize; + let mut _4: *const u8; + let mut _5: usize; scope 3 (inlined Vec::::as_ptr) { debug self => _1; scope 4 (inlined alloc::raw_vec::RawVec::::ptr) { @@ -17,6 +17,7 @@ fn vec_deref_to_slice(_1: &Vec) -> &[u8] { let mut _2: std::ptr::NonNull; scope 7 (inlined Unique::::cast::) { scope 8 (inlined NonNull::::cast::) { + let mut _3: (*const u8) is !null; scope 9 (inlined NonNull::::as_ptr) { } } @@ -30,9 +31,9 @@ fn vec_deref_to_slice(_1: &Vec) -> &[u8] { } } scope 12 (inlined #[track_caller] std::slice::from_raw_parts::<'_, u8>) { - debug data => _3; - debug len => _4; - let _5: *const [u8]; + debug data => _4; + debug len => _5; + let _6: *const [u8]; scope 13 (inlined core::ub_checks::check_language_ub) { scope 14 (inlined core::ub_checks::check_language_ub::runtime) { } @@ -42,10 +43,10 @@ fn vec_deref_to_slice(_1: &Vec) -> &[u8] { scope 16 (inlined std::mem::align_of::) { } scope 17 (inlined slice_from_raw_parts::) { - debug data => _3; - debug len => _4; + debug data => _4; + debug len => _5; scope 18 (inlined std::ptr::from_raw_parts::<[u8], u8>) { - debug data_pointer => _3; + debug data_pointer => _4; } } } @@ -53,19 +54,22 @@ fn vec_deref_to_slice(_1: &Vec) -> &[u8] { } bb0: { - StorageLive(_2); StorageLive(_3); - _2 = copy (((((*_1).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).0: std::ptr::Unique).0: std::ptr::NonNull); - _3 = copy _2 as *const u8 (Transmute); StorageLive(_4); - _4 = copy ((*_1).1: usize); + StorageLive(_2); + _2 = copy (((((*_1).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).0: std::ptr::Unique).0: std::ptr::NonNull); + _3 = copy _2 as (*const u8) is !null (Transmute); + StorageDead(_2); + _4 = copy _3 as *const u8 (Transmute); StorageLive(_5); - _5 = *const [u8] from (copy _3, copy _4); - _0 = &(*_5); + _5 = copy ((*_1).1: usize); + StorageLive(_6); + _6 = *const [u8] from (copy _4, copy _5); + _0 = &(*_6); + StorageDead(_6); StorageDead(_5); StorageDead(_4); StorageDead(_3); - StorageDead(_2); return; } } diff --git a/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-unwind.mir index 2eee8a97db0d4..7a656ba12956c 100644 --- a/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-unwind.mir @@ -7,8 +7,8 @@ fn vec_deref_to_slice(_1: &Vec) -> &[u8] { debug self => _1; scope 2 (inlined Vec::::as_slice) { debug self => _1; - let mut _3: *const u8; - let mut _4: usize; + let mut _4: *const u8; + let mut _5: usize; scope 3 (inlined Vec::::as_ptr) { debug self => _1; scope 4 (inlined alloc::raw_vec::RawVec::::ptr) { @@ -17,6 +17,7 @@ fn vec_deref_to_slice(_1: &Vec) -> &[u8] { let mut _2: std::ptr::NonNull; scope 7 (inlined Unique::::cast::) { scope 8 (inlined NonNull::::cast::) { + let mut _3: (*const u8) is !null; scope 9 (inlined NonNull::::as_ptr) { } } @@ -30,9 +31,9 @@ fn vec_deref_to_slice(_1: &Vec) -> &[u8] { } } scope 12 (inlined #[track_caller] std::slice::from_raw_parts::<'_, u8>) { - debug data => _3; - debug len => _4; - let _5: *const [u8]; + debug data => _4; + debug len => _5; + let _6: *const [u8]; scope 13 (inlined core::ub_checks::check_language_ub) { scope 14 (inlined core::ub_checks::check_language_ub::runtime) { } @@ -42,10 +43,10 @@ fn vec_deref_to_slice(_1: &Vec) -> &[u8] { scope 16 (inlined std::mem::align_of::) { } scope 17 (inlined slice_from_raw_parts::) { - debug data => _3; - debug len => _4; + debug data => _4; + debug len => _5; scope 18 (inlined std::ptr::from_raw_parts::<[u8], u8>) { - debug data_pointer => _3; + debug data_pointer => _4; } } } @@ -53,19 +54,22 @@ fn vec_deref_to_slice(_1: &Vec) -> &[u8] { } bb0: { - StorageLive(_2); StorageLive(_3); - _2 = copy (((((*_1).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).0: std::ptr::Unique).0: std::ptr::NonNull); - _3 = copy _2 as *const u8 (Transmute); StorageLive(_4); - _4 = copy ((*_1).1: usize); + StorageLive(_2); + _2 = copy (((((*_1).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).0: std::ptr::Unique).0: std::ptr::NonNull); + _3 = copy _2 as (*const u8) is !null (Transmute); + StorageDead(_2); + _4 = copy _3 as *const u8 (Transmute); StorageLive(_5); - _5 = *const [u8] from (copy _3, copy _4); - _0 = &(*_5); + _5 = copy ((*_1).1: usize); + StorageLive(_6); + _6 = *const [u8] from (copy _4, copy _5); + _0 = &(*_6); + StorageDead(_6); StorageDead(_5); StorageDead(_4); StorageDead(_3); - StorageDead(_2); return; } } diff --git a/tests/mir-opt/retag.box_to_raw_mut.SimplifyCfg-pre-optimizations.after.panic-abort.mir b/tests/mir-opt/retag.box_to_raw_mut.SimplifyCfg-pre-optimizations.after.panic-abort.mir index 4861abead2f32..39bb397d1dd96 100644 --- a/tests/mir-opt/retag.box_to_raw_mut.SimplifyCfg-pre-optimizations.after.panic-abort.mir +++ b/tests/mir-opt/retag.box_to_raw_mut.SimplifyCfg-pre-optimizations.after.panic-abort.mir @@ -9,7 +9,7 @@ fn box_to_raw_mut(_1: &mut Box) -> *mut i32 { bb0: { Retag([fn entry] _1); _2 = copy (*_1); - _3 = copy ((_2.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); + _3 = copy (((_2.0: std::ptr::Unique).0: std::ptr::NonNull).0: (*const i32) is !null) as *const i32 (Transmute); _0 = &raw mut (*_3); Retag([raw] _0); return; diff --git a/tests/mir-opt/retag.box_to_raw_mut.SimplifyCfg-pre-optimizations.after.panic-unwind.mir b/tests/mir-opt/retag.box_to_raw_mut.SimplifyCfg-pre-optimizations.after.panic-unwind.mir index 4861abead2f32..39bb397d1dd96 100644 --- a/tests/mir-opt/retag.box_to_raw_mut.SimplifyCfg-pre-optimizations.after.panic-unwind.mir +++ b/tests/mir-opt/retag.box_to_raw_mut.SimplifyCfg-pre-optimizations.after.panic-unwind.mir @@ -9,7 +9,7 @@ fn box_to_raw_mut(_1: &mut Box) -> *mut i32 { bb0: { Retag([fn entry] _1); _2 = copy (*_1); - _3 = copy ((_2.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); + _3 = copy (((_2.0: std::ptr::Unique).0: std::ptr::NonNull).0: (*const i32) is !null) as *const i32 (Transmute); _0 = &raw mut (*_3); Retag([raw] _0); return; diff --git a/tests/ui/abi/compatibility.rs b/tests/ui/abi/compatibility.rs index 906f372dd4411..eb4e7fd28b2f0 100644 --- a/tests/ui/abi/compatibility.rs +++ b/tests/ui/abi/compatibility.rs @@ -60,7 +60,7 @@ //@[nvptx64] compile-flags: --target nvptx64-nvidia-cuda //@[nvptx64] needs-llvm-components: nvptx //@ ignore-backends: gcc -#![feature(no_core, rustc_attrs, lang_items)] +#![feature(no_core, rustc_attrs, lang_items, pattern_types)] #![feature(unsized_fn_params, transparent_unions)] #![no_core] #![allow(unused, improper_ctypes_definitions, internal_features)] @@ -89,18 +89,12 @@ mod prelude { } #[repr(transparent)] - #[rustc_layout_scalar_valid_range_start(1)] #[rustc_nonnull_optimization_guaranteed] pub struct NonNull { - pointer: *const T, + pointer: pattern_type!(*const T is !null), } impl Copy for NonNull {} - #[repr(transparent)] - #[rustc_layout_scalar_valid_range_start(1)] - #[rustc_nonnull_optimization_guaranteed] - pub struct NonZero(T); - // This just stands in for a non-trivial type. pub struct Vec { ptr: NonNull, @@ -209,7 +203,7 @@ test_abi_compatible!(isize_int, isize, i64); // Compatibility of 1-ZST. test_abi_compatible!(zst_unit, Zst, ()); test_abi_compatible!(zst_array, Zst, [u8; 0]); -test_abi_compatible!(nonzero_int, NonZero, i32); +test_abi_compatible!(nonzero_int, pattern_type!(i32 is 1..=0x7FFF_FFFF), i32); // `#[repr(C)]` enums should not change ABI based on individual variant inhabitedness. // (However, this is *not* a guarantee. We only guarantee same layout, not same ABI.) @@ -326,6 +320,6 @@ test_nonnull!(mut_unsized, &mut [i32]); test_nonnull!(fn_, fn()); test_nonnull!(nonnull, NonNull); test_nonnull!(nonnull_unsized, NonNull); -test_nonnull!(non_zero, NonZero); +test_nonnull!(non_zero, pattern_type!(i32 is 1..=0x7FFF_FFFF)); fn main() {} diff --git a/tests/ui/consts/const-eval/raw-bytes.32bit.stderr b/tests/ui/consts/const-eval/raw-bytes.32bit.stderr index be3b539b269a0..3712f4293328e 100644 --- a/tests/ui/consts/const-eval/raw-bytes.32bit.stderr +++ b/tests/ui/consts/const-eval/raw-bytes.32bit.stderr @@ -53,7 +53,7 @@ LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::tran 78 00 00 00 ff ff ff ff │ x....... } -error[E0080]: constructing invalid value: encountered 0, but expected something greater or equal to 1 +error[E0080]: constructing invalid value at .pointer: encountered 0, but expected something greater or equal to 1 --> $DIR/raw-bytes.rs:58:1 | LL | const NULL_PTR: NonNull = unsafe { mem::transmute(0usize) }; @@ -108,7 +108,7 @@ LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) }; 14 00 00 00 │ .... } -error[E0080]: constructing invalid value: encountered 0, but expected something greater or equal to 1 +error[E0080]: constructing invalid value at .pointer: encountered 0, but expected something greater or equal to 1 --> $DIR/raw-bytes.rs:78:1 | LL | const NULL_FAT_PTR: NonNull = unsafe { diff --git a/tests/ui/consts/const-eval/raw-bytes.64bit.stderr b/tests/ui/consts/const-eval/raw-bytes.64bit.stderr index 9950ac726ca76..d507896772db4 100644 --- a/tests/ui/consts/const-eval/raw-bytes.64bit.stderr +++ b/tests/ui/consts/const-eval/raw-bytes.64bit.stderr @@ -53,7 +53,7 @@ LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::tran 78 00 00 00 ff ff ff ff │ x....... } -error[E0080]: constructing invalid value: encountered 0, but expected something greater or equal to 1 +error[E0080]: constructing invalid value at .pointer: encountered 0, but expected something greater or equal to 1 --> $DIR/raw-bytes.rs:58:1 | LL | const NULL_PTR: NonNull = unsafe { mem::transmute(0usize) }; @@ -108,7 +108,7 @@ LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) }; 14 00 00 00 │ .... } -error[E0080]: constructing invalid value: encountered 0, but expected something greater or equal to 1 +error[E0080]: constructing invalid value at .pointer: encountered 0, but expected something greater or equal to 1 --> $DIR/raw-bytes.rs:78:1 | LL | const NULL_FAT_PTR: NonNull = unsafe { diff --git a/tests/ui/consts/const-eval/ub-nonnull.stderr b/tests/ui/consts/const-eval/ub-nonnull.stderr index be5c6f77a0877..a51c8ca279aa3 100644 --- a/tests/ui/consts/const-eval/ub-nonnull.stderr +++ b/tests/ui/consts/const-eval/ub-nonnull.stderr @@ -1,4 +1,4 @@ -error[E0080]: constructing invalid value: encountered 0, but expected something greater or equal to 1 +error[E0080]: constructing invalid value at .pointer: encountered 0, but expected something greater or equal to 1 --> $DIR/ub-nonnull.rs:16:1 | LL | const NULL_PTR: NonNull = unsafe { mem::transmute(0usize) }; @@ -69,7 +69,7 @@ LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) }; HEX_DUMP } -error[E0080]: constructing invalid value: encountered 0, but expected something greater or equal to 1 +error[E0080]: constructing invalid value at .pointer: encountered 0, but expected something greater or equal to 1 --> $DIR/ub-nonnull.rs:53:1 | LL | const NULL_FAT_PTR: NonNull = unsafe { @@ -80,7 +80,7 @@ LL | const NULL_FAT_PTR: NonNull = unsafe { HEX_DUMP } -error[E0080]: constructing invalid value: encountered a maybe-null pointer, but expected something that is definitely non-zero +error[E0080]: constructing invalid value at .pointer: encountered a maybe-null pointer, but expected something that is definitely non-zero --> $DIR/ub-nonnull.rs:61:1 | LL | const MAYBE_NULL_PTR: NonNull<()> = unsafe { mem::transmute((&raw const S).wrapping_add(4)) }; diff --git a/tests/ui/lint/invalid_value.stderr b/tests/ui/lint/invalid_value.stderr index 3dd2a521ff2e1..63df1e5d11d68 100644 --- a/tests/ui/lint/invalid_value.stderr +++ b/tests/ui/lint/invalid_value.stderr @@ -314,7 +314,6 @@ LL | let _val: NonNull = mem::uninitialized(); | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | = note: `std::ptr::NonNull` must be non-null - = note: raw pointers must be initialized error: the type `(NonZero, i32)` does not permit zero-initialization --> $DIR/invalid_value.rs:94:41 @@ -623,7 +622,6 @@ LL | let _val: NonNull = MaybeUninit::uninit().assume_init(); | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | = note: `std::ptr::NonNull` must be non-null - = note: raw pointers must be initialized error: the type `bool` does not permit being left uninitialized --> $DIR/invalid_value.rs:158:26 diff --git a/tests/ui/mir/ssa-analysis-regression-50041.rs b/tests/ui/mir/ssa-analysis-regression-50041.rs index 82654c8c0b55c..28690624f63ec 100644 --- a/tests/ui/mir/ssa-analysis-regression-50041.rs +++ b/tests/ui/mir/ssa-analysis-regression-50041.rs @@ -2,10 +2,10 @@ //@ compile-flags: -Z mir-opt-level=4 #![crate_type = "lib"] -#![feature(lang_items)] +#![feature(lang_items, pattern_type_macro, pattern_types)] #![no_std] -struct NonNull(*const T); +struct NonNull(pattern_type!(*const T is !null)); struct Unique(NonNull); @@ -20,7 +20,7 @@ impl Drop for Box { } #[inline(never)] -fn dealloc(_: *const T) {} +fn dealloc(_: pattern_type!(*const T is !null)) {} pub struct Foo(T);