Skip to content

Commit 9a52a83

Browse files
committed
Allow static regions in type_name.
Fixes #146249.
1 parent 55b9b4d commit 9a52a83

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

compiler/rustc_const_eval/src/util/type_name.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,11 @@ impl<'tcx> PrettyPrinter<'tcx> for TypeNamePrinter<'tcx> {
168168
// Bound regions are always printed (as `'_`), which gives some idea that they are special,
169169
// even though the `for` is omitted by the pretty printer.
170170
// E.g. `for<'a, 'b> fn(&'a u32, &'b u32)` is printed as "fn(&'_ u32, &'_ u32)".
171+
let kind = region.kind();
171172
match region.kind() {
172-
ty::ReErased | ty::ReEarlyParam(_) => false,
173+
ty::ReErased | ty::ReEarlyParam(_) | ty::ReStatic => false,
173174
ty::ReBound(..) => true,
174-
_ => unreachable!(),
175+
_ => panic!("type_name unhandled region: {kind:?}"),
175176
}
176177
}
177178

tests/ui/type/type-name-basic.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,19 @@ pub fn main() {
107107
}
108108
let a = Wrap(&()).get();
109109
v!(a, "type_name_basic::main::Wrap<&()>::get::Info");
110+
111+
struct Issue146249<T>(T);
112+
impl Issue146249<Box<dyn FnOnce()>> {
113+
pub fn bar(&self) {
114+
let f = || {};
115+
v!(
116+
f,
117+
"type_name_basic::main::Issue146249<\
118+
alloc::boxed::Box<dyn core::ops::function::FnOnce()>\
119+
>::bar::{{closure}}"
120+
);
121+
}
122+
}
123+
let v: Issue146249<Box<dyn FnOnce()>> = Issue146249(Box::new(|| {}));
124+
v.bar();
110125
}

0 commit comments

Comments
 (0)