Skip to content

Commit bbcc39d

Browse files
committed
Start using pattern types in libcore
1 parent 928adba commit bbcc39d

15 files changed

+47
-20
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

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

461472
{

library/core/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@
183183
#![feature(no_core)]
184184
#![feature(no_sanitize)]
185185
#![feature(optimize_attribute)]
186+
#![feature(pattern_type_macro)]
187+
#![feature(pattern_types)]
186188
#![feature(prelude_import)]
187189
#![feature(repr_simd)]
188190
#![feature(rustc_allow_const_fn_unstable)]

library/core/src/num/niche_types.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,28 @@ use crate::cmp::Ordering;
88
use crate::fmt;
99
use crate::hash::{Hash, Hasher};
1010
use crate::marker::StructuralPartialEq;
11+
#[cfg(not(bootstrap))]
12+
use crate::pattern_type;
1113

1214
macro_rules! define_valid_range_type {
1315
($(
1416
$(#[$m:meta])*
1517
$vis:vis struct $name:ident($int:ident as $uint:ident in $low:literal..=$high:literal);
1618
)+) => {$(
17-
#[derive(Clone, Copy, Eq)]
19+
#[derive(Clone, Copy)]
1820
#[repr(transparent)]
19-
#[rustc_layout_scalar_valid_range_start($low)]
20-
#[rustc_layout_scalar_valid_range_end($high)]
21+
#[cfg_attr(bootstrap, rustc_layout_scalar_valid_range_start($low))]
22+
#[cfg_attr(bootstrap, rustc_layout_scalar_valid_range_end($high))]
2123
$(#[$m])*
24+
#[cfg(bootstrap)]
2225
$vis struct $name($int);
2326

27+
#[derive(Clone, Copy, Eq, PartialEq)]
28+
#[repr(transparent)]
29+
$(#[$m])*
30+
#[cfg(not(bootstrap))]
31+
$vis struct $name(pattern_type!($int is $low..=$high));
32+
2433
const _: () = {
2534
// With the `valid_range` attributes, it's always specified as unsigned
2635
assert!(<$uint>::MIN == 0);
@@ -51,7 +60,7 @@ macro_rules! define_valid_range_type {
5160
#[inline]
5261
pub const unsafe fn new_unchecked(val: $int) -> Self {
5362
// SAFETY: Caller promised that `val` is non-zero.
54-
unsafe { $name(val) }
63+
unsafe { $name(crate::mem::transmute(val)) }
5564
}
5665

5766
#[inline]
@@ -65,8 +74,13 @@ macro_rules! define_valid_range_type {
6574
// This is required to allow matching a constant. We don't get it from a derive
6675
// because the derived `PartialEq` would do a field projection, which is banned
6776
// by <https://github.com/rust-lang/compiler-team/issues/807>.
77+
#[cfg(bootstrap)]
6878
impl StructuralPartialEq for $name {}
6979

80+
#[cfg(bootstrap)]
81+
impl Eq for $name {}
82+
83+
#[cfg(bootstrap)]
7084
impl PartialEq for $name {
7185
#[inline]
7286
fn eq(&self, other: &Self) -> bool {

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({transmute(0x00000001): (usize) is 1..=usize::MAX}));
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({transmute(0x00000001): (usize) is 1..=usize::MAX}));
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({transmute(0x0000000000000001): (usize) is 1..=usize::MAX}));
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({transmute(0x0000000000000001): (usize) is 1..=usize::MAX}));
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({transmute(0x00000001): (usize) is 1..=usize::MAX}));
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({transmute(0x00000001): (usize) is 1..=usize::MAX}));
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({transmute(0x0000000000000001): (usize) is 1..=usize::MAX}));
5050
StorageLive(_7);
5151
- _7 = copy _6 as *const [bool; 0] (Transmute);
5252
- _5 = NonNull::<[bool; 0]> { pointer: copy _7 };

0 commit comments

Comments
 (0)