Skip to content

Commit 48251c5

Browse files
committed
Start using pattern types in libcore
1 parent b17dba4 commit 48251c5

19 files changed

+76
-87
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,18 @@ pub(crate) fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) ->
459459
AdtKind::Enum => enums::build_enum_type_di_node(cx, unique_type_id),
460460
},
461461
ty::Tuple(_) => build_tuple_type_di_node(cx, unique_type_id),
462-
_ => bug!("debuginfo: unexpected type in type_di_node(): {:?}", t),
462+
ty::Pat(base, _) => return type_di_node(cx, base),
463+
// FIXME(unsafe_binders): impl debug info
464+
ty::UnsafeBinder(_) => unimplemented!(),
465+
ty::Alias(..)
466+
| ty::Param(_)
467+
| ty::Bound(..)
468+
| ty::Infer(_)
469+
| ty::Placeholder(_)
470+
| ty::CoroutineWitness(..)
471+
| ty::Error(_) => {
472+
bug!("debuginfo: unexpected type in type_di_node(): {:?}", t)
473+
}
463474
};
464475

465476
{

compiler/rustc_const_eval/src/interpret/call.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
8686
let (_, field) = layout.non_1zst_field(self).unwrap();
8787
self.unfold_transparent(field, may_unfold)
8888
}
89+
ty::Pat(base, _) => self.layout_of(*base).expect(
90+
"if the layout of a pattern type could be computed, so can the layout of its base",
91+
),
8992
// Not a transparent type, no further unfolding.
9093
_ => layout,
9194
}

library/core/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@
168168
#![feature(never_type)]
169169
#![feature(no_core)]
170170
#![feature(optimize_attribute)]
171+
#![feature(pattern_type_macro)]
172+
#![feature(pattern_types)]
171173
#![feature(prelude_import)]
172174
#![feature(repr_simd)]
173175
#![feature(rustc_allow_const_fn_unstable)]

library/core/src/num/niche_types.rs

Lines changed: 40 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,48 @@
55
)]
66

77
use crate::cmp::Ordering;
8-
use crate::fmt;
98
use crate::hash::{Hash, Hasher};
109
use crate::marker::StructuralPartialEq;
10+
use crate::{fmt, pattern_type};
1111

1212
macro_rules! define_valid_range_type {
1313
($(
1414
$(#[$m:meta])*
15-
$vis:vis struct $name:ident($int:ident as $uint:ident in $low:literal..=$high:literal);
15+
$vis:vis struct $name:ident($int:ident is $pat:pat);
1616
)+) => {$(
17-
#[derive(Clone, Copy, Eq)]
17+
#[derive(Clone, Copy)]
1818
#[repr(transparent)]
19-
#[rustc_layout_scalar_valid_range_start($low)]
20-
#[rustc_layout_scalar_valid_range_end($high)]
2119
$(#[$m])*
22-
$vis struct $name($int);
23-
24-
const _: () = {
25-
// With the `valid_range` attributes, it's always specified as unsigned
26-
assert!(<$uint>::MIN == 0);
27-
let ulow: $uint = $low;
28-
let uhigh: $uint = $high;
29-
assert!(ulow <= uhigh);
30-
31-
assert!(size_of::<$int>() == size_of::<$uint>());
32-
};
33-
20+
$vis struct $name(pattern_type!($int is $pat));
3421
impl $name {
3522
#[inline]
3623
pub const fn new(val: $int) -> Option<Self> {
37-
if (val as $uint) >= ($low as $uint) && (val as $uint) <= ($high as $uint) {
38-
// SAFETY: just checked the inclusive range
39-
Some(unsafe { $name(val) })
24+
#[allow(non_contiguous_range_endpoints)]
25+
if let $pat = val {
26+
// SAFETY: just checked that the value matches the pattern
27+
Some(unsafe { $name(crate::mem::transmute(val)) })
4028
} else {
4129
None
4230
}
4331
}
4432

4533
/// Constructs an instance of this type from the underlying integer
46-
/// primitive without checking whether its zero.
34+
/// primitive without checking whether its valid.
4735
///
4836
/// # Safety
49-
/// Immediate language UB if `val == 0`, as it violates the validity
37+
/// Immediate language UB if `val` is not in the range of the pattern type,
38+
/// as it violates the validity
5039
/// invariant of this type.
5140
#[inline]
5241
pub const unsafe fn new_unchecked(val: $int) -> Self {
53-
// SAFETY: Caller promised that `val` is non-zero.
54-
unsafe { $name(val) }
42+
// SAFETY: Caller promised that `val` is in the valid range.
43+
unsafe { $name(crate::mem::transmute(val)) }
5544
}
5645

5746
#[inline]
5847
pub const fn as_inner(self) -> $int {
59-
// SAFETY: This is a transparent wrapper, so unwrapping it is sound
60-
// (Not using `.0` due to MCP#807.)
61-
unsafe { crate::mem::transmute(self) }
48+
// SAFETY: pattern types are always legal values of their base type
49+
unsafe { crate::mem::transmute(self.0) }
6250
}
6351
}
6452

@@ -67,6 +55,8 @@ macro_rules! define_valid_range_type {
6755
// by <https://github.com/rust-lang/compiler-team/issues/807>.
6856
impl StructuralPartialEq for $name {}
6957

58+
impl Eq for $name {}
59+
7060
impl PartialEq for $name {
7161
#[inline]
7262
fn eq(&self, other: &Self) -> bool {
@@ -104,7 +94,7 @@ macro_rules! define_valid_range_type {
10494
}
10595

10696
define_valid_range_type! {
107-
pub struct Nanoseconds(u32 as u32 in 0..=999_999_999);
97+
pub struct Nanoseconds(u32 is 0..=999_999_999);
10898
}
10999

110100
impl Nanoseconds {
@@ -119,45 +109,30 @@ impl Default for Nanoseconds {
119109
}
120110
}
121111

122-
define_valid_range_type! {
123-
pub struct NonZeroU8Inner(u8 as u8 in 1..=0xff);
124-
pub struct NonZeroU16Inner(u16 as u16 in 1..=0xff_ff);
125-
pub struct NonZeroU32Inner(u32 as u32 in 1..=0xffff_ffff);
126-
pub struct NonZeroU64Inner(u64 as u64 in 1..=0xffffffff_ffffffff);
127-
pub struct NonZeroU128Inner(u128 as u128 in 1..=0xffffffffffffffff_ffffffffffffffff);
128-
129-
pub struct NonZeroI8Inner(i8 as u8 in 1..=0xff);
130-
pub struct NonZeroI16Inner(i16 as u16 in 1..=0xff_ff);
131-
pub struct NonZeroI32Inner(i32 as u32 in 1..=0xffff_ffff);
132-
pub struct NonZeroI64Inner(i64 as u64 in 1..=0xffffffff_ffffffff);
133-
pub struct NonZeroI128Inner(i128 as u128 in 1..=0xffffffffffffffff_ffffffffffffffff);
134-
}
135-
136-
#[cfg(target_pointer_width = "16")]
137-
define_valid_range_type! {
138-
pub struct UsizeNoHighBit(usize as usize in 0..=0x7fff);
139-
pub struct NonZeroUsizeInner(usize as usize in 1..=0xffff);
140-
pub struct NonZeroIsizeInner(isize as usize in 1..=0xffff);
141-
}
142-
#[cfg(target_pointer_width = "32")]
143-
define_valid_range_type! {
144-
pub struct UsizeNoHighBit(usize as usize in 0..=0x7fff_ffff);
145-
pub struct NonZeroUsizeInner(usize as usize in 1..=0xffff_ffff);
146-
pub struct NonZeroIsizeInner(isize as usize in 1..=0xffff_ffff);
147-
}
148-
#[cfg(target_pointer_width = "64")]
149-
define_valid_range_type! {
150-
pub struct UsizeNoHighBit(usize as usize in 0..=0x7fff_ffff_ffff_ffff);
151-
pub struct NonZeroUsizeInner(usize as usize in 1..=0xffff_ffff_ffff_ffff);
152-
pub struct NonZeroIsizeInner(isize as usize in 1..=0xffff_ffff_ffff_ffff);
153-
}
112+
const HALF_USIZE: usize = usize::MAX >> 1;
154113

155114
define_valid_range_type! {
156-
pub struct U32NotAllOnes(u32 as u32 in 0..=0xffff_fffe);
157-
pub struct I32NotAllOnes(i32 as u32 in 0..=0xffff_fffe);
158-
159-
pub struct U64NotAllOnes(u64 as u64 in 0..=0xffff_ffff_ffff_fffe);
160-
pub struct I64NotAllOnes(i64 as u64 in 0..=0xffff_ffff_ffff_fffe);
115+
pub struct NonZeroU8Inner(u8 is 1..);
116+
pub struct NonZeroU16Inner(u16 is 1..);
117+
pub struct NonZeroU32Inner(u32 is 1..);
118+
pub struct NonZeroU64Inner(u64 is 1..);
119+
pub struct NonZeroU128Inner(u128 is 1..);
120+
121+
pub struct NonZeroI8Inner(i8 is ..0 | 1..);
122+
pub struct NonZeroI16Inner(i16 is ..0 | 1..);
123+
pub struct NonZeroI32Inner(i32 is ..0 | 1..);
124+
pub struct NonZeroI64Inner(i64 is ..0 | 1..);
125+
pub struct NonZeroI128Inner(i128 is ..0 | 1..);
126+
127+
pub struct UsizeNoHighBit(usize is 0..=HALF_USIZE);
128+
pub struct NonZeroUsizeInner(usize is 1..);
129+
pub struct NonZeroIsizeInner(isize is ..0 | 1..);
130+
131+
pub struct U32NotAllOnes(u32 is 0..u32::MAX);
132+
pub struct I32NotAllOnes(i32 is ..-1 | 0..);
133+
134+
pub struct U64NotAllOnes(u64 is 0..u64::MAX);
135+
pub struct I64NotAllOnes(i64 is ..-1 | 0..);
161136
}
162137

163138
pub trait NotAllOnesHelper {

src/tools/miri/tests/fail/validity/cast_fn_ptr_invalid_callee_ret.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: constructing invalid value at .0: encountered 0, but expected something greater or equal to 1
1+
error: Undefined Behavior: constructing invalid value at .0.0: encountered 0, but expected something greater or equal to 1
22
--> tests/fail/validity/cast_fn_ptr_invalid_callee_ret.rs:LL:CC
33
|
44
LL | f();
5-
| ^^^ constructing invalid value at .0: encountered 0, but expected something greater or equal to 1
5+
| ^^^ constructing invalid value at .0.0: encountered 0, but expected something greater or equal to 1
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

src/tools/miri/tests/fail/validity/cast_fn_ptr_invalid_caller_arg.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: constructing invalid value at .0: encountered 0, but expected something greater or equal to 1
1+
error: Undefined Behavior: constructing invalid value at .0.0: encountered 0, but expected something greater or equal to 1
22
--> tests/fail/validity/cast_fn_ptr_invalid_caller_arg.rs:LL:CC
33
|
44
LL | Call(_res = f(*ptr), ReturnTo(retblock), UnwindContinue())
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0, but expected something greater or equal to 1
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0.0: encountered 0, but expected something greater or equal to 1
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
StorageLive(_4);
4646
StorageLive(_5);
4747
StorageLive(_6);
48-
_6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize));
48+
_6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..));
4949
StorageLive(_7);
5050
_7 = const {0x1 as *const [bool; 0]};
5151
_5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
StorageLive(_4);
4646
StorageLive(_5);
4747
StorageLive(_6);
48-
_6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize));
48+
_6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..));
4949
StorageLive(_7);
5050
_7 = const {0x1 as *const [bool; 0]};
5151
_5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
StorageLive(_4);
4646
StorageLive(_5);
4747
StorageLive(_6);
48-
_6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize));
48+
_6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..));
4949
StorageLive(_7);
5050
_7 = const {0x1 as *const [bool; 0]};
5151
_5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
StorageLive(_4);
4646
StorageLive(_5);
4747
StorageLive(_6);
48-
_6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize));
48+
_6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..));
4949
StorageLive(_7);
5050
_7 = const {0x1 as *const [bool; 0]};
5151
_5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
StorageLive(_5);
4747
StorageLive(_6);
4848
- _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as std::num::NonZero<usize> (Transmute);
49-
+ _6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize));
49+
+ _6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..));
5050
StorageLive(_7);
5151
- _7 = copy _6 as *const [bool; 0] (Transmute);
5252
- _5 = NonNull::<[bool; 0]> { pointer: copy _7 };

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
StorageLive(_5);
4747
StorageLive(_6);
4848
- _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as std::num::NonZero<usize> (Transmute);
49-
+ _6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize));
49+
+ _6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..));
5050
StorageLive(_7);
5151
- _7 = copy _6 as *const [bool; 0] (Transmute);
5252
- _5 = NonNull::<[bool; 0]> { pointer: copy _7 };

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
StorageLive(_5);
4747
StorageLive(_6);
4848
- _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as std::num::NonZero<usize> (Transmute);
49-
+ _6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize));
49+
+ _6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..));
5050
StorageLive(_7);
5151
- _7 = copy _6 as *const [bool; 0] (Transmute);
5252
- _5 = NonNull::<[bool; 0]> { pointer: copy _7 };

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
StorageLive(_5);
4747
StorageLive(_6);
4848
- _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as std::num::NonZero<usize> (Transmute);
49-
+ _6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize));
49+
+ _6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..));
5050
StorageLive(_7);
5151
- _7 = copy _6 as *const [bool; 0] (Transmute);
5252
- _5 = NonNull::<[bool; 0]> { pointer: copy _7 };

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
StorageLive(_3);
4343
- _3 = const std::ptr::Alignment::of::<u8>::{constant#0} as std::num::NonZero<usize> (Transmute);
4444
- _2 = copy _3 as *mut u8 (Transmute);
45-
+ _3 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize));
45+
+ _3 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize is 1..));
4646
+ _2 = const {0x1 as *mut u8};
4747
StorageDead(_3);
4848
StorageLive(_4);

tests/ui/consts/const-eval/raw-bytes.32bit.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ error[E0080]: it is undefined behavior to use this value
6868
--> $DIR/raw-bytes.rs:61:1
6969
|
7070
LL | const NULL_U8: NonZero<u8> = unsafe { mem::transmute(0u8) };
71-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0, but expected something greater or equal to 1
71+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0.0: encountered 0, but expected something greater or equal to 1
7272
|
7373
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
7474
= note: the raw bytes of the constant (size: 1, align: 1) {
@@ -79,7 +79,7 @@ error[E0080]: it is undefined behavior to use this value
7979
--> $DIR/raw-bytes.rs:63:1
8080
|
8181
LL | const NULL_USIZE: NonZero<usize> = unsafe { mem::transmute(0usize) };
82-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0, but expected something greater or equal to 1
82+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0.0: encountered 0, but expected something greater or equal to 1
8383
|
8484
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
8585
= note: the raw bytes of the constant (size: 4, align: 4) {

tests/ui/consts/const-eval/raw-bytes.64bit.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ error[E0080]: it is undefined behavior to use this value
6868
--> $DIR/raw-bytes.rs:61:1
6969
|
7070
LL | const NULL_U8: NonZero<u8> = unsafe { mem::transmute(0u8) };
71-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0, but expected something greater or equal to 1
71+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0.0: encountered 0, but expected something greater or equal to 1
7272
|
7373
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
7474
= note: the raw bytes of the constant (size: 1, align: 1) {
@@ -79,7 +79,7 @@ error[E0080]: it is undefined behavior to use this value
7979
--> $DIR/raw-bytes.rs:63:1
8080
|
8181
LL | const NULL_USIZE: NonZero<usize> = unsafe { mem::transmute(0usize) };
82-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0, but expected something greater or equal to 1
82+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0.0: encountered 0, but expected something greater or equal to 1
8383
|
8484
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
8585
= note: the raw bytes of the constant (size: 8, align: 8) {

tests/ui/consts/const-eval/ub-nonnull.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ error[E0080]: it is undefined behavior to use this value
1919
--> $DIR/ub-nonnull.rs:26:1
2020
|
2121
LL | const NULL_U8: NonZero<u8> = unsafe { mem::transmute(0u8) };
22-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0, but expected something greater or equal to 1
22+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0.0: encountered 0, but expected something greater or equal to 1
2323
|
2424
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
2525
= note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
@@ -30,7 +30,7 @@ error[E0080]: it is undefined behavior to use this value
3030
--> $DIR/ub-nonnull.rs:28:1
3131
|
3232
LL | const NULL_USIZE: NonZero<usize> = unsafe { mem::transmute(0usize) };
33-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0, but expected something greater or equal to 1
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0.0: encountered 0, but expected something greater or equal to 1
3434
|
3535
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
3636
= note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {

tests/ui/lint/invalid_value.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ LL | let _val: (NonZero<u32>, i32) = mem::uninitialized();
333333
|
334334
= note: `std::num::NonZero<u32>` must be non-null
335335
= note: because `core::num::niche_types::NonZeroU32Inner` must be non-null
336-
= note: integers must be initialized
337336

338337
error: the type `*const dyn Send` does not permit zero-initialization
339338
--> $DIR/invalid_value.rs:97:37
@@ -430,7 +429,6 @@ note: because `std::num::NonZero<u32>` must be non-null (in this field of the on
430429
LL | Banana(NonZero<u32>),
431430
| ^^^^^^^^^^^^
432431
= note: because `core::num::niche_types::NonZeroU32Inner` must be non-null
433-
= note: integers must be initialized
434432

435433
error: the type `bool` does not permit being left uninitialized
436434
--> $DIR/invalid_value.rs:111:26

0 commit comments

Comments
 (0)