Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/rustc_const_eval/src/util/type_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ impl<'tcx> Printer<'tcx> for TypeNamePrinter<'tcx> {
}

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!(),
}
Expand Down
18 changes: 17 additions & 1 deletion tests/ui/type/type-name-basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
Expand Down Expand Up @@ -91,4 +97,14 @@ pub fn main() {
}
}
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");
}
Loading