1
Fork 0

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

@ -1058,7 +1058,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
fn visit_item(&mut self, item: &'tcx Item<'tcx>) {
let target = Target::from_item(item);
self.check_attributes(
item.hir_id,
item.hir_id(),
item.attrs,
&item.span,
target,

View file

@ -188,8 +188,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
match node {
Node::Item(item) => match item.kind {
hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) => {
let def_id = self.tcx.hir().local_def_id(item.hir_id);
let def = self.tcx.adt_def(def_id);
let def = self.tcx.adt_def(item.def_id);
self.repr_has_repr_c = def.repr.c();
intravisit::walk_item(self, &item);
@ -395,9 +394,10 @@ struct LifeSeeder<'k, 'tcx> {
impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
fn visit_item(&mut self, item: &hir::Item<'_>) {
let allow_dead_code = has_allow_dead_code_or_lang_attr(self.tcx, item.hir_id, &item.attrs);
let allow_dead_code =
has_allow_dead_code_or_lang_attr(self.tcx, item.hir_id(), &item.attrs);
if allow_dead_code {
self.worklist.push(item.hir_id);
self.worklist.push(item.hir_id());
}
match item.kind {
hir::ItemKind::Enum(ref enum_def, _) => {
@ -413,7 +413,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
}
hir::ItemKind::Impl(hir::Impl { ref of_trait, items, .. }) => {
if of_trait.is_some() {
self.worklist.push(item.hir_id);
self.worklist.push(item.hir_id());
}
for impl_item_ref in items {
let impl_item = self.krate.impl_item(impl_item_ref.id);
@ -430,7 +430,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
}
hir::ItemKind::Struct(ref variant_data, _) => {
if let Some(ctor_hir_id) = variant_data.ctor_hir_id() {
self.struct_constructors.insert(ctor_hir_id, item.hir_id);
self.struct_constructors.insert(ctor_hir_id, item.hir_id());
}
}
_ => (),
@ -525,7 +525,7 @@ impl DeadVisitor<'tcx> {
| hir::ItemKind::Struct(..)
| hir::ItemKind::Union(..)
);
should_warn && !self.symbol_is_live(item.hir_id)
should_warn && !self.symbol_is_live(item.hir_id())
}
fn should_warn_about_field(&mut self, field: &hir::StructField<'_>) -> bool {
@ -627,7 +627,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
hir::ItemKind::Struct(..) => "constructed", // Issue #52325
_ => "used",
};
self.warn_dead_code(item.hir_id, span, item.ident.name, participle);
self.warn_dead_code(item.hir_id(), span, item.ident.name, participle);
} else {
// Only continue if we didn't warn
intravisit::walk_item(self, item);

View file

@ -27,7 +27,7 @@ struct DiagnosticItemCollector<'tcx> {
impl<'v, 'tcx> ItemLikeVisitor<'v> for DiagnosticItemCollector<'tcx> {
fn visit_item(&mut self, item: &hir::Item<'_>) {
self.observe_item(&item.attrs, item.hir_id);
self.observe_item(&item.attrs, item.hir_id());
}
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) {

View file

@ -32,8 +32,7 @@ struct EntryContext<'a, 'tcx> {
impl<'a, 'tcx> ItemLikeVisitor<'tcx> for EntryContext<'a, 'tcx> {
fn visit_item(&mut self, item: &'tcx Item<'tcx>) {
let def_id = self.map.local_def_id(item.hir_id);
let def_key = self.map.def_key(def_id);
let def_key = self.map.def_key(item.def_id);
let at_root = def_key.parent == Some(CRATE_DEF_INDEX);
find_item(item, self, at_root);
}
@ -116,18 +115,18 @@ fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
}
EntryPointType::MainNamed => {
if ctxt.main_fn.is_none() {
ctxt.main_fn = Some((item.hir_id, item.span));
ctxt.main_fn = Some((item.hir_id(), item.span));
} else {
struct_span_err!(ctxt.session, item.span, E0136, "multiple `main` functions")
.emit();
}
}
EntryPointType::OtherMain => {
ctxt.non_main_fns.push((item.hir_id, item.span));
ctxt.non_main_fns.push((item.hir_id(), item.span));
}
EntryPointType::MainAttr => {
if ctxt.attr_main_fn.is_none() {
ctxt.attr_main_fn = Some((item.hir_id, item.span));
ctxt.attr_main_fn = Some((item.hir_id(), item.span));
} else {
struct_span_err!(
ctxt.session,
@ -142,7 +141,7 @@ fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
}
EntryPointType::Start => {
if ctxt.start_fn.is_none() {
ctxt.start_fn = Some((item.hir_id, item.span));
ctxt.start_fn = Some((item.hir_id(), item.span));
} else {
struct_span_err!(ctxt.session, item.span, E0138, "multiple `start` functions")
.span_label(ctxt.start_fn.unwrap().1, "previous `#[start]` function here")

View file

@ -56,7 +56,7 @@ impl<'a, 'hir> OuterVisitor<'a, 'hir> {
impl<'a, 'hir> ItemLikeVisitor<'hir> for OuterVisitor<'a, 'hir> {
fn visit_item(&mut self, i: &'hir hir::Item<'hir>) {
let mut inner_visitor = self.new_inner_visitor(self.hir_map);
inner_visitor.check(i.hir_id, |this| intravisit::walk_item(this, i));
inner_visitor.check(i.hir_id(), |this| intravisit::walk_item(this, i));
}
fn visit_trait_item(&mut self, i: &'hir hir::TraitItem<'hir>) {

View file

@ -120,7 +120,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
}
fn visit_item(&mut self, i: &'v hir::Item<'v>) {
self.record("Item", Id::Node(i.hir_id), i);
self.record("Item", Id::Node(i.hir_id()), i);
hir_visit::walk_item(self, i)
}

View file

@ -30,7 +30,7 @@ struct LanguageItemCollector<'tcx> {
impl ItemLikeVisitor<'v> for LanguageItemCollector<'tcx> {
fn visit_item(&mut self, item: &hir::Item<'_>) {
self.check_for_lang(Target::from_item(item), item.hir_id, item.attrs);
self.check_for_lang(Target::from_item(item), item.hir_id(), item.attrs);
if let hir::ItemKind::Enum(def, ..) = &item.kind {
for variant in def.variants {

View file

@ -21,16 +21,14 @@ struct LayoutTest<'tcx> {
impl ItemLikeVisitor<'tcx> for LayoutTest<'tcx> {
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
let item_def_id = self.tcx.hir().local_def_id(item.hir_id);
match item.kind {
ItemKind::TyAlias(..)
| ItemKind::Enum(..)
| ItemKind::Struct(..)
| ItemKind::Union(..) => {
for attr in self.tcx.get_attrs(item_def_id.to_def_id()).iter() {
for attr in self.tcx.get_attrs(item.def_id.to_def_id()).iter() {
if self.tcx.sess.check_name(attr, sym::rustc_layout) {
self.dump_layout_of(item_def_id, item, attr);
self.dump_layout_of(item.def_id, item, attr);
}
}
}

View file

@ -31,7 +31,7 @@ fn item_might_be_inlined(tcx: TyCtxt<'tcx>, item: &hir::Item<'_>, attrs: &Codege
match item.kind {
hir::ItemKind::Fn(ref sig, ..) if sig.header.is_const() => true,
hir::ItemKind::Impl { .. } | hir::ItemKind::Fn(..) => {
let generics = tcx.generics_of(tcx.hir().local_def_id(item.hir_id));
let generics = tcx.generics_of(item.def_id);
generics.requires_monomorphization(tcx)
}
_ => false,
@ -218,8 +218,7 @@ impl<'tcx> ReachableContext<'tcx> {
} else {
false
};
let def_id = self.tcx.hir().local_def_id(item.hir_id);
let codegen_attrs = self.tcx.codegen_fn_attrs(def_id);
let codegen_attrs = self.tcx.codegen_fn_attrs(item.def_id);
let is_extern = codegen_attrs.contains_extern_indicator();
let std_internal =
codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL);
@ -239,9 +238,11 @@ impl<'tcx> ReachableContext<'tcx> {
Node::Item(item) => {
match item.kind {
hir::ItemKind::Fn(.., body) => {
let def_id = self.tcx.hir().local_def_id(item.hir_id);
if item_might_be_inlined(self.tcx, &item, self.tcx.codegen_fn_attrs(def_id))
{
if item_might_be_inlined(
self.tcx,
&item,
self.tcx.codegen_fn_attrs(item.def_id),
) {
self.visit_nested_body(body);
}
}
@ -341,19 +342,18 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx
// Anything which has custom linkage gets thrown on the worklist no
// matter where it is in the crate, along with "special std symbols"
// which are currently akin to allocator symbols.
let def_id = self.tcx.hir().local_def_id(item.hir_id);
let codegen_attrs = self.tcx.codegen_fn_attrs(def_id);
let codegen_attrs = self.tcx.codegen_fn_attrs(item.def_id);
if codegen_attrs.contains_extern_indicator()
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL)
{
self.worklist.push(def_id);
self.worklist.push(item.def_id);
}
// We need only trait impls here, not inherent impls, and only non-exported ones
if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(ref trait_ref), ref items, .. }) =
item.kind
{
if !self.access_levels.is_reachable(item.hir_id) {
if !self.access_levels.is_reachable(item.hir_id()) {
// FIXME(#53488) remove `let`
let tcx = self.tcx;
self.worklist

View file

@ -376,7 +376,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
}
self.annotate(
i.hir_id,
i.hir_id(),
&i.attrs,
i.span,
kind,
@ -556,7 +556,7 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
hir::ItemKind::Impl(hir::Impl { of_trait: None, .. })
| hir::ItemKind::ForeignMod { .. }
) {
self.check_missing_stability(i.hir_id, i.span);
self.check_missing_stability(i.hir_id(), i.span);
}
// Ensure `const fn` that are `stable` have one of `rustc_const_unstable` or
@ -564,7 +564,7 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
if self.tcx.features().staged_api
&& matches!(&i.kind, hir::ItemKind::Fn(sig, ..) if sig.header.is_const())
{
self.check_missing_const_stability(i.hir_id, i.span);
self.check_missing_const_stability(i.hir_id(), i.span);
}
intravisit::walk_item(self, i)
@ -712,13 +712,12 @@ impl Visitor<'tcx> for Checker<'tcx> {
return;
}
let def_id = self.tcx.hir().local_def_id(item.hir_id);
let cnum = match self.tcx.extern_mod_stmt_cnum(def_id) {
let cnum = match self.tcx.extern_mod_stmt_cnum(item.def_id) {
Some(cnum) => cnum,
None => return,
};
let def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX };
self.tcx.check_stability(def_id, Some(item.hir_id), item.span);
self.tcx.check_stability(def_id, Some(item.hir_id()), item.span);
}
// For implementations of traits, check the stability of each item
@ -744,7 +743,7 @@ impl Visitor<'tcx> for Checker<'tcx> {
.map_or(item.span, |a| a.span);
self.tcx.struct_span_lint_hir(
INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
item.hir_id,
item.hir_id(),
span,
|lint| lint
.build("an `#[unstable]` annotation here has no effect")
@ -775,15 +774,14 @@ impl Visitor<'tcx> for Checker<'tcx> {
// There's no good place to insert stability check for non-Copy unions,
// so semi-randomly perform it here in stability.rs
hir::ItemKind::Union(..) if !self.tcx.features().untagged_unions => {
let def_id = self.tcx.hir().local_def_id(item.hir_id);
let ty = self.tcx.type_of(def_id);
let ty = self.tcx.type_of(item.def_id);
let (adt_def, substs) = match ty.kind() {
ty::Adt(adt_def, substs) => (adt_def, substs),
_ => bug!(),
};
// Non-`Copy` fields are unstable, except for `ManuallyDrop`.
let param_env = self.tcx.param_env(def_id);
let param_env = self.tcx.param_env(item.def_id);
for field in &adt_def.non_enum_variant().fields {
let field_ty = field.ty(self.tcx, substs);
if !field_ty.ty_adt_def().map_or(false, |adt_def| adt_def.is_manually_drop())