From 7877d86163d802b2963d893850555d684c9d0eb1 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 28 Jan 2025 08:08:46 +0000 Subject: [PATCH 1/2] Add mir-opt pattern type tests --- .../pattern_types.main.PreCodegen.after.mir | 15 +++++++++++++++ tests/mir-opt/pattern_types.rs | 12 ++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/mir-opt/pattern_types.main.PreCodegen.after.mir create mode 100644 tests/mir-opt/pattern_types.rs diff --git a/tests/mir-opt/pattern_types.main.PreCodegen.after.mir b/tests/mir-opt/pattern_types.main.PreCodegen.after.mir new file mode 100644 index 0000000000000..e96526a01ff82 --- /dev/null +++ b/tests/mir-opt/pattern_types.main.PreCodegen.after.mir @@ -0,0 +1,15 @@ +// MIR for `main` after PreCodegen + +fn main() -> () { + let mut _0: (); + scope 1 { + debug x => const {transmute(0x00000002): (u32) is 1..=}; + scope 2 { + debug y => const {transmute(0x00000000): (u32) is 1..=}; + } + } + + bb0: { + return; + } +} diff --git a/tests/mir-opt/pattern_types.rs b/tests/mir-opt/pattern_types.rs new file mode 100644 index 0000000000000..3903fbad4ae89 --- /dev/null +++ b/tests/mir-opt/pattern_types.rs @@ -0,0 +1,12 @@ +#![feature(pattern_types)] +#![feature(pattern_type_macro)] + +use std::pat::pattern_type; + +// EMIT_MIR pattern_types.main.PreCodegen.after.mir +fn main() { + // CHECK: debug x => const {transmute(0x00000002): (u32) is 1..=} + let x: pattern_type!(u32 is 1..) = unsafe { std::mem::transmute(2) }; + // CHECK: debug y => const {transmute(0x00000000): (u32) is 1..=} + let y: pattern_type!(u32 is 1..) = unsafe { std::mem::transmute(0) }; +} From fd6713fce1d06ba283bc27331df354b7a9443d6b Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 27 Jan 2025 15:19:49 +0000 Subject: [PATCH 2/2] Make mir dumps more readable --- compiler/rustc_middle/src/ty/print/pretty.rs | 4 ++++ tests/mir-opt/pattern_types.main.PreCodegen.after.mir | 4 ++-- tests/mir-opt/pattern_types.rs | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index ac900edefe12f..027a4315b4bf3 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1740,6 +1740,10 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { " as ", )?; } + ty::Pat(base_ty, pat) => { + self.pretty_print_const_scalar_int(int, *base_ty, print_ty)?; + p!(write(" is {pat:?}")); + } // Nontrivial types with scalar bit representation _ => { let print = |this: &mut Self| { diff --git a/tests/mir-opt/pattern_types.main.PreCodegen.after.mir b/tests/mir-opt/pattern_types.main.PreCodegen.after.mir index e96526a01ff82..8c99902f9b8f0 100644 --- a/tests/mir-opt/pattern_types.main.PreCodegen.after.mir +++ b/tests/mir-opt/pattern_types.main.PreCodegen.after.mir @@ -3,9 +3,9 @@ fn main() -> () { let mut _0: (); scope 1 { - debug x => const {transmute(0x00000002): (u32) is 1..=}; + debug x => const 2_u32 is 1..=; scope 2 { - debug y => const {transmute(0x00000000): (u32) is 1..=}; + debug y => const 0_u32 is 1..=; } } diff --git a/tests/mir-opt/pattern_types.rs b/tests/mir-opt/pattern_types.rs index 3903fbad4ae89..217c64b90cbbc 100644 --- a/tests/mir-opt/pattern_types.rs +++ b/tests/mir-opt/pattern_types.rs @@ -5,8 +5,8 @@ use std::pat::pattern_type; // EMIT_MIR pattern_types.main.PreCodegen.after.mir fn main() { - // CHECK: debug x => const {transmute(0x00000002): (u32) is 1..=} + // CHECK: debug x => const 2_u32 is 1..= let x: pattern_type!(u32 is 1..) = unsafe { std::mem::transmute(2) }; - // CHECK: debug y => const {transmute(0x00000000): (u32) is 1..=} + // CHECK: debug y => const 0_u32 is 1..= let y: pattern_type!(u32 is 1..) = unsafe { std::mem::transmute(0) }; }