Return the actual DefId
for assoc. items in register_res
Before, if `register_res` were called on an associated item or enum variant, it would return the parent's `DefId`. Now, it returns the actual `DefId`. This change is a step toward removing `Type::ResolvedPath.did` and potentially removing `kind_side_channel` in rustdoc. It also just simplifies rustdoc's behavior.
This commit is contained in:
parent
8a48b376d5
commit
47266bacf1
@ -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.
|
||||
|
@ -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<String>), 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] }
|
||||
|
Loading…
x
Reference in New Issue
Block a user