Remove TypeKind hack in favor of with_crate_prefix

This commit is contained in:
Joshua Nelson 2020-11-29 13:37:43 -05:00
parent 6ab1f05697
commit aa8c9b0d29

View File

@ -847,18 +847,12 @@ fn fold_item(&mut self, mut item: Item) -> Option<Item> {
// FIXME(jynelson): this shouldn't go through stringification, rustdoc should just use the DefId directly
let self_name = self_id.and_then(|self_id| {
use ty::TyKind;
if matches!(self.cx.tcx.def_kind(self_id), DefKind::Impl) {
// using `ty.to_string()` directly has issues with shortening paths
// FIXME: this is a hack, isn't there a better way?
let ty = self.cx.tcx.type_of(self_id);
let name = match ty.kind() {
TyKind::Adt(def, _) => Some(self.cx.tcx.item_name(def.did).to_string()),
other if other.is_primitive() => Some(ty.to_string()),
_ => None,
};
debug!("using type_of(): {:?}", name);
name
let name = ty::print::with_crate_prefix(|| ty.to_string());
debug!("using type_of(): {}", name);
Some(name)
} else {
let name = self.cx.tcx.opt_item_name(self_id).map(|sym| sym.to_string());
debug!("using item_name(): {:?}", name);