about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeón Orell Valerian Liehr <me@fmease.dev>2025-01-29 06:03:24 +0100
committerGitHub <noreply@github.com>2025-01-29 06:03:24 +0100
commitf49ad60feebe807f23e9ae3c387baac7d02e116f (patch)
treed027ec72c7229edf0782cb3a80650e6146a5cd34
parent0b1d71775877c14e7a7ffb9c8023d85ae7d54a57 (diff)
parentfd6713fce1d06ba283bc27331df354b7a9443d6b (diff)
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
-rw-r--r--compiler/rustc_middle/src/ty/print/pretty.rs4
-rw-r--r--tests/mir-opt/pattern_types.main.PreCodegen.after.mir15
-rw-r--r--tests/mir-opt/pattern_types.rs12
3 files changed, 31 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs
index ac900edefe1..027a4315b4b 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
new file mode 100644
index 00000000000..8c99902f9b8
--- /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 2_u32 is 1..=;
+        scope 2 {
+            debug y => const 0_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 00000000000..217c64b90cb
--- /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 2_u32 is 1..=
+    let x: pattern_type!(u32 is 1..) = unsafe { std::mem::transmute(2) };
+    // CHECK: debug y => const 0_u32 is 1..=
+    let y: pattern_type!(u32 is 1..) = unsafe { std::mem::transmute(0) };
+}