about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-09-08 16:34:57 +0200
committerGitHub <noreply@github.com>2025-09-08 16:34:57 +0200
commit00bffaaf236f70c2f5664f9e684f406ef74911ef (patch)
treefc617c4b0a8423da3f117a7f4cff34ca5c21e97f
parentd1ab870a07214a91a223fa60d7080064d13259fc (diff)
parent9a52a8354e50bd824bdefebc659d8c3c38eccc0a (diff)
downloadrust-00bffaaf236f70c2f5664f9e684f406ef74911ef.tar.gz
rust-00bffaaf236f70c2f5664f9e684f406ef74911ef.zip
Rollup merge of #146310 - nnethercote:fix-146249, r=lcnr
Allow static regions in `type_name`.

Fixes rust-lang/rust#146249.

r? `@lcnr`
-rw-r--r--compiler/rustc_const_eval/src/util/type_name.rs5
-rw-r--r--tests/ui/type/type-name-basic.rs15
2 files changed, 18 insertions, 2 deletions
diff --git a/compiler/rustc_const_eval/src/util/type_name.rs b/compiler/rustc_const_eval/src/util/type_name.rs
index 2ae6655901b..5bcf96abd8c 100644
--- a/compiler/rustc_const_eval/src/util/type_name.rs
+++ b/compiler/rustc_const_eval/src/util/type_name.rs
@@ -168,10 +168,11 @@ impl<'tcx> PrettyPrinter<'tcx> for TypeNamePrinter<'tcx> {
         // Bound regions are always printed (as `'_`), which gives some idea that they are special,
         // even though the `for` is omitted by the pretty printer.
         // E.g. `for<'a, 'b> fn(&'a u32, &'b u32)` is printed as "fn(&'_ u32, &'_ u32)".
+        let kind = region.kind();
         match region.kind() {
-            ty::ReErased | ty::ReEarlyParam(_) => false,
+            ty::ReErased | ty::ReEarlyParam(_) | ty::ReStatic => false,
             ty::ReBound(..) => true,
-            _ => unreachable!(),
+            _ => panic!("type_name unhandled region: {kind:?}"),
         }
     }
 
diff --git a/tests/ui/type/type-name-basic.rs b/tests/ui/type/type-name-basic.rs
index 343bcae175a..2c41cb80aea 100644
--- a/tests/ui/type/type-name-basic.rs
+++ b/tests/ui/type/type-name-basic.rs
@@ -107,4 +107,19 @@ pub fn main() {
     }
     let a = Wrap(&()).get();
     v!(a, "type_name_basic::main::Wrap<&()>::get::Info");
+
+    struct Issue146249<T>(T);
+    impl Issue146249<Box<dyn FnOnce()>> {
+        pub fn bar(&self) {
+            let f = || {};
+            v!(
+                f,
+                "type_name_basic::main::Issue146249<\
+                    alloc::boxed::Box<dyn core::ops::function::FnOnce()>\
+                >::bar::{{closure}}"
+            );
+        }
+    }
+    let v: Issue146249<Box<dyn FnOnce()>> = Issue146249(Box::new(|| {}));
+    v.bar();
 }