How to get the name of a type (rustc_middle::ty::Ty) in rustc

I have a rustc_middle::ty::Ty, so how I get the full path of it, such as crate1::m1::m2::struct1?

I don’t know the API of the compiler but I suspect that this is not possible directly without matching on the type to determine if it is not a composite type and then resolving the identifier.

You can do rustc_middle::ty::print::with_no_trimmed_paths!({ format!("{}", ty) }). Note that without with_no_trimmed_paths you will get an ICE.

1 Like