Skip to content

Commit f49ad60

Browse files
authored
Rollup merge of #136176 - oli-obk:pattern-type-mir-opts, r=compiler-errors
Render pattern types nicely in mir dumps avoid falling through to the fallback rendering that just does a hex dump r? ``@scottmcm`` best reviewed commit by commit
2 parents 0b1d717 + fd6713f commit f49ad60

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

compiler/rustc_middle/src/ty/print/pretty.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1740,6 +1740,10 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
17401740
" as ",
17411741
)?;
17421742
}
1743+
ty::Pat(base_ty, pat) => {
1744+
self.pretty_print_const_scalar_int(int, *base_ty, print_ty)?;
1745+
p!(write(" is {pat:?}"));
1746+
}
17431747
// Nontrivial types with scalar bit representation
17441748
_ => {
17451749
let print = |this: &mut Self| {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// MIR for `main` after PreCodegen
2+
3+
fn main() -> () {
4+
let mut _0: ();
5+
scope 1 {
6+
debug x => const 2_u32 is 1..=;
7+
scope 2 {
8+
debug y => const 0_u32 is 1..=;
9+
}
10+
}
11+
12+
bb0: {
13+
return;
14+
}
15+
}

tests/mir-opt/pattern_types.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(pattern_types)]
2+
#![feature(pattern_type_macro)]
3+
4+
use std::pat::pattern_type;
5+
6+
// EMIT_MIR pattern_types.main.PreCodegen.after.mir
7+
fn main() {
8+
// CHECK: debug x => const 2_u32 is 1..=
9+
let x: pattern_type!(u32 is 1..) = unsafe { std::mem::transmute(2) };
10+
// CHECK: debug y => const 0_u32 is 1..=
11+
let y: pattern_type!(u32 is 1..) = unsafe { std::mem::transmute(0) };
12+
}

0 commit comments

Comments
 (0)