Skip to content

Commit 51d3c9a

Browse files
authored
Unrolled build for #145700
Rollup merge of #145700 - nnethercote:fix-145696, r=lcnr Handle `ReEarlyParam` in `type_name`. Fixes #145696. r? `@lcnr`
2 parents 6ba0ce4 + 95b3b61 commit 51d3c9a

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

compiler/rustc_const_eval/src/util/type_name.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ impl<'tcx> Printer<'tcx> for TypeNamePrinter<'tcx> {
164164
}
165165

166166
impl<'tcx> PrettyPrinter<'tcx> for TypeNamePrinter<'tcx> {
167-
fn should_print_optional_region(&self, _region: ty::Region<'_>) -> bool {
167+
fn should_print_optional_region(&self, region: ty::Region<'_>) -> bool {
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-
match _region.kind() {
172-
ty::ReErased => false,
171+
match region.kind() {
172+
ty::ReErased | ty::ReEarlyParam(_) => false,
173173
ty::ReBound(..) => true,
174174
_ => unreachable!(),
175175
}

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#![allow(dead_code)]
77

8-
use std::any::type_name;
8+
use std::any::{Any, type_name, type_name_of_val};
99
use std::borrow::Cow;
1010

1111
struct Foo<T>(T);
@@ -29,6 +29,12 @@ macro_rules! t {
2929
}
3030
}
3131

32+
macro_rules! v {
33+
($v:expr, $str:literal) => {
34+
assert_eq!(type_name_of_val(&$v), $str);
35+
}
36+
}
37+
3238
pub fn main() {
3339
t!(bool, "bool");
3440
t!(char, "char");
@@ -91,4 +97,14 @@ pub fn main() {
9197
}
9298
}
9399
S::<u32>::test();
100+
101+
struct Wrap<T>(T);
102+
impl Wrap<&()> {
103+
fn get(&self) -> impl Any {
104+
struct Info;
105+
Info
106+
}
107+
}
108+
let a = Wrap(&()).get();
109+
v!(a, "type_name_basic::main::Wrap<&()>::get::Info");
94110
}

0 commit comments

Comments
 (0)