diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 11032211236..78643841a0b 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -393,20 +393,12 @@ crate fn register_res(cx: &mut DocContext<'_>, res: Res) -> DefId { debug!("register_res({:?})", res); let (did, kind) = match res { - Res::Def(DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst, i) => { - // associated items are documented, but on the page of their parent - (cx.tcx.parent(i).unwrap(), ItemType::Trait) - } - Res::Def(DefKind::Variant, i) => { - // variant items are documented, but on the page of their parent - (cx.tcx.parent(i).expect("cannot get parent def id"), ItemType::Enum) - } // Each of these have their own page. Res::Def( kind @ - (Fn | TyAlias | Enum | Trait | Struct | Union | Mod | ForeignTy | Const | Static - | Macro(..) | TraitAlias), + (AssocTy | AssocFn | AssocConst | Variant | Fn | TyAlias | Enum | Trait | Struct + | Union | Mod | ForeignTy | Const | Static | Macro(..) | TraitAlias), i, ) => (i, kind.into()), // This is part of a trait definition; document the trait. diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 4f204913204..d4c5dda19f9 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -13,8 +13,10 @@ use rustc_attr::{ConstStability, StabilityLevel}; use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; +use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; use rustc_middle::ty; +use rustc_middle::ty::DefIdTree; use rustc_middle::ty::TyCtxt; use rustc_span::def_id::CRATE_DEF_INDEX; use rustc_target::spec::abi::Abi; @@ -502,7 +504,16 @@ crate fn href_with_root_path( cx: &Context<'_>, root_path: Option<&str>, ) -> Result<(String, ItemType, Vec), HrefError> { - let cache = &cx.cache(); + let tcx = cx.tcx(); + let def_kind = tcx.def_kind(did); + let did = match def_kind { + DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst | DefKind::Variant => { + // documented on their parent's page + tcx.parent(did).unwrap() + } + _ => did, + }; + let cache = cx.cache(); let relative_to = &cx.current; fn to_module_fqp(shortty: ItemType, fqp: &[String]) -> &[String] { if shortty == ItemType::Module { fqp } else { &fqp[..fqp.len() - 1] }