Rollup merge of #145700 - nnethercote:fix-145696, r=lcnr

Handle `ReEarlyParam` in `type_name`.

Fixes rust-lang/rust#145696.

r? `@lcnr`
This commit is contained in:
Jacob Pratt
2025-08-21 17:57:56 -04:00
committed by GitHub
2 changed files with 20 additions and 4 deletions
@@ -164,12 +164,12 @@ fn print_coroutine_with_kind(
}
impl<'tcx> PrettyPrinter<'tcx> for TypeNamePrinter<'tcx> {
fn should_print_optional_region(&self, _region: ty::Region<'_>) -> bool {
fn should_print_optional_region(&self, region: ty::Region<'_>) -> bool {
// 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)".
match _region.kind() {
ty::ReErased => false,
match region.kind() {
ty::ReErased | ty::ReEarlyParam(_) => false,
ty::ReBound(..) => true,
_ => unreachable!(),
}
+17 -1
View File
@@ -5,7 +5,7 @@
#![allow(dead_code)]
use std::any::type_name;
use std::any::{Any, type_name, type_name_of_val};
use std::borrow::Cow;
struct Foo<T>(T);
@@ -29,6 +29,12 @@ macro_rules! t {
}
}
macro_rules! v {
($v:expr, $str:literal) => {
assert_eq!(type_name_of_val(&$v), $str);
}
}
pub fn main() {
t!(bool, "bool");
t!(char, "char");
@@ -91,4 +97,14 @@ fn test() {
}
}
S::<u32>::test();
struct Wrap<T>(T);
impl Wrap<&()> {
fn get(&self) -> impl Any {
struct Info;
Info
}
}
let a = Wrap(&()).get();
v!(a, "type_name_basic::main::Wrap<&()>::get::Info");
}