Only store a LocalDefId in hir::Item.

Items are guaranteed to be HIR owner.
This commit is contained in:
Camille GILLOT 2021-01-30 17:47:51 +01:00
parent bd3cd5dbed
commit cebbba081e
86 changed files with 483 additions and 565 deletions

View file

@ -135,16 +135,15 @@ impl Clean<ExternalCrate> for CrateNum {
.filter_map(|&id| {
let item = cx.tcx.hir().item(id);
match item.kind {
hir::ItemKind::Mod(_) => as_primitive(Res::Def(
DefKind::Mod,
cx.tcx.hir().local_def_id(id.id).to_def_id(),
)),
hir::ItemKind::Mod(_) => {
as_primitive(Res::Def(DefKind::Mod, id.def_id.to_def_id()))
}
hir::ItemKind::Use(ref path, hir::UseKind::Single)
if item.vis.node.is_pub() =>
{
as_primitive(path.res).map(|(_, prim)| {
// Pretend the primitive is local.
(cx.tcx.hir().local_def_id(id.id).to_def_id(), prim)
(id.def_id.to_def_id(), prim)
})
}
_ => None,
@ -187,16 +186,13 @@ impl Clean<ExternalCrate> for CrateNum {
.filter_map(|&id| {
let item = cx.tcx.hir().item(id);
match item.kind {
hir::ItemKind::Mod(_) => as_keyword(Res::Def(
DefKind::Mod,
cx.tcx.hir().local_def_id(id.id).to_def_id(),
)),
hir::ItemKind::Mod(_) => {
as_keyword(Res::Def(DefKind::Mod, id.def_id.to_def_id()))
}
hir::ItemKind::Use(ref path, hir::UseKind::Single)
if item.vis.node.is_pub() =>
{
as_keyword(path.res).map(|(_, prim)| {
(cx.tcx.hir().local_def_id(id.id).to_def_id(), prim)
})
as_keyword(path.res).map(|(_, prim)| (id.def_id.to_def_id(), prim))
}
_ => None,
}
@ -912,7 +908,7 @@ fn clean_fn_or_proc_macro(
}
None => {
let mut func = (sig, generics, body_id).clean(cx);
let def_id = cx.tcx.hir().local_def_id(item.hir_id).to_def_id();
let def_id = item.def_id.to_def_id();
func.header.constness =
if is_const_fn(cx.tcx, def_id) && is_unstable_const_fn(cx.tcx, def_id).is_none() {
hir::Constness::Const
@ -1950,8 +1946,8 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
use hir::ItemKind;
let (item, renamed) = self;
let def_id = cx.tcx.hir().local_def_id(item.hir_id).to_def_id();
let mut name = renamed.unwrap_or_else(|| cx.tcx.hir().name(item.hir_id));
let def_id = item.def_id.to_def_id();
let mut name = renamed.unwrap_or_else(|| cx.tcx.hir().name(item.hir_id()));
cx.with_param_env(def_id, || {
let kind = match item.kind {
ItemKind::Static(ty, mutability, body_id) => {
@ -1999,7 +1995,7 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
fields: variant_data.fields().clean(cx),
fields_stripped: false,
}),
ItemKind::Impl(ref impl_) => return clean_impl(impl_, item.hir_id, cx),
ItemKind::Impl(ref impl_) => return clean_impl(impl_, item.hir_id(), cx),
// proc macros can have a name set by attributes
ItemKind::Fn(ref sig, ref generics, body_id) => {
clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx)
@ -2107,8 +2103,7 @@ fn clean_extern_crate(
cx: &DocContext<'_>,
) -> Vec<Item> {
// this is the ID of the `extern crate` statement
let def_id = cx.tcx.hir().local_def_id(krate.hir_id);
let cnum = cx.tcx.extern_mod_stmt_cnum(def_id).unwrap_or(LOCAL_CRATE);
let cnum = cx.tcx.extern_mod_stmt_cnum(krate.def_id).unwrap_or(LOCAL_CRATE);
// this is the ID of the crate itself
let crate_def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX };
let please_inline = krate.vis.node.is_pub()
@ -2127,7 +2122,7 @@ fn clean_extern_crate(
if let Some(items) = inline::try_inline(
cx,
cx.tcx.parent_module(krate.hir_id).to_def_id(),
cx.tcx.parent_module(krate.hir_id()).to_def_id(),
res,
name,
Some(krate.attrs),
@ -2196,7 +2191,6 @@ fn clean_use_statement(
// Also check whether imports were asked to be inlined, in case we're trying to re-export a
// crate in Rust 2018+
let def_id = cx.tcx.hir().local_def_id(import.hir_id).to_def_id();
let path = path.clean(cx);
let inner = if kind == hir::UseKind::Glob {
if !denied {
@ -2221,14 +2215,14 @@ fn clean_use_statement(
if let Some(mut items) = inline::try_inline(
cx,
cx.tcx.parent_module(import.hir_id).to_def_id(),
cx.tcx.parent_module(import.hir_id()).to_def_id(),
path.res,
name,
Some(import.attrs),
&mut visited,
) {
items.push(Item::from_def_id_and_parts(
def_id,
import.def_id.to_def_id(),
None,
ImportItem(Import::new_simple(name, resolve_use_source(cx, path), false)),
cx,
@ -2239,7 +2233,7 @@ fn clean_use_statement(
Import::new_simple(name, resolve_use_source(cx, path), true)
};
vec![Item::from_def_id_and_parts(def_id, None, ImportItem(inner), cx)]
vec![Item::from_def_id_and_parts(import.def_id.to_def_id(), None, ImportItem(inner), cx)]
}
impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Symbol>) {

View file

@ -1050,7 +1050,7 @@ impl<'a, 'hir, 'tcx> intravisit::Visitor<'hir> for HirCollector<'a, 'hir, 'tcx>
item.ident.to_string()
};
self.visit_testable(name, &item.attrs, item.hir_id, item.span, |this| {
self.visit_testable(name, &item.attrs, item.hir_id(), item.span, |this| {
intravisit::walk_item(this, item);
});
}

View file

@ -270,8 +270,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
let name = renamed.unwrap_or(item.ident.name);
if item.vis.node.is_pub() {
let def_id = self.cx.tcx.hir().local_def_id(item.hir_id);
self.store_path(def_id.to_def_id());
self.store_path(item.def_id.to_def_id());
}
match item.kind {
@ -305,7 +304,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
});
let ident = if is_glob { None } else { Some(name) };
if self.maybe_inline_local(
item.hir_id,
item.hir_id(),
path.res,
ident,
is_glob,
@ -322,7 +321,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
om.mods.push(self.visit_mod_contents(
item.span,
&item.vis,
item.hir_id,
item.hir_id(),
m,
Some(name),
));