Skip to content

Commit 9eb97ac

Browse files
committed
Retire hir::*ItemRef.
1 parent 884232a commit 9eb97ac

File tree

52 files changed

+246
-312
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+246
-312
lines changed

compiler/rustc_ast_lowering/src/index.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -381,20 +381,12 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
381381
})
382382
}
383383

384-
fn visit_trait_item_ref(&mut self, ii: &'hir TraitItemRef) {
385-
// Do not visit the duplicate information in TraitItemRef. We want to
386-
// map the actual nodes, not the duplicate ones in the *Ref.
387-
let TraitItemRef { id, ident: _, span: _ } = *ii;
388-
389-
self.visit_nested_trait_item(id);
384+
fn visit_trait_item_ref(&mut self, id: &'hir TraitItemId) {
385+
self.visit_nested_trait_item(*id);
390386
}
391387

392-
fn visit_impl_item_ref(&mut self, ii: &'hir ImplItemRef) {
393-
// Do not visit the duplicate information in ImplItemRef. We want to
394-
// map the actual nodes, not the duplicate ones in the *Ref.
395-
let ImplItemRef { id, ident: _, span: _ } = *ii;
396-
397-
self.visit_nested_impl_item(id);
388+
fn visit_impl_item_ref(&mut self, id: &'hir ImplItemId) {
389+
self.visit_nested_impl_item(*id);
398390
}
399391

400392
fn visit_foreign_item_ref(&mut self, id: &'hir ForeignItemId) {

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -964,13 +964,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
964964
self.arena.alloc(item)
965965
}
966966

967-
fn lower_trait_item_ref(&mut self, i: &AssocItem) -> hir::TraitItemRef {
968-
let id = hir::TraitItemId { owner_id: self.owner_id(i.id) };
969-
hir::TraitItemRef {
970-
id,
971-
ident: self.lower_ident(i.kind.ident().unwrap()),
972-
span: self.lower_span(i.span),
973-
}
967+
fn lower_trait_item_ref(&mut self, i: &AssocItem) -> hir::TraitItemId {
968+
hir::TraitItemId { owner_id: self.owner_id(i.id) }
974969
}
975970

976971
/// Construct `ExprKind::Err` for the given `span`.
@@ -1110,14 +1105,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
11101105
self.arena.alloc(item)
11111106
}
11121107

1113-
fn lower_impl_item_ref(&mut self, i: &AssocItem) -> hir::ImplItemRef {
1114-
hir::ImplItemRef {
1115-
id: hir::ImplItemId { owner_id: self.owner_id(i.id) },
1116-
// `unwrap` is safe because `AssocItemKind::{MacCall,DelegationMac}` are the only
1117-
// assoc item kinds without an identifier and they cannot reach here.
1118-
ident: self.lower_ident(i.kind.ident().unwrap()),
1119-
span: self.lower_span(i.span),
1120-
}
1108+
fn lower_impl_item_ref(&mut self, i: &AssocItem) -> hir::ImplItemId {
1109+
hir::ImplItemId { owner_id: self.owner_id(i.id) }
11211110
}
11221111

11231112
fn lower_defaultness(

compiler/rustc_hir/src/hir.rs

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4161,7 +4161,7 @@ impl<'hir> Item<'hir> {
41614161
Ident,
41624162
&'hir Generics<'hir>,
41634163
GenericBounds<'hir>,
4164-
&'hir [TraitItemRef]
4164+
&'hir [TraitItemId]
41654165
),
41664166
ItemKind::Trait(is_auto, safety, ident, generics, bounds, items),
41674167
(*is_auto, *safety, *ident, generics, bounds, items);
@@ -4334,7 +4334,7 @@ pub enum ItemKind<'hir> {
43344334
/// A union definition, e.g., `union Foo<A, B> {x: A, y: B}`.
43354335
Union(Ident, &'hir Generics<'hir>, VariantData<'hir>),
43364336
/// A trait definition.
4337-
Trait(IsAuto, Safety, Ident, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemRef]),
4337+
Trait(IsAuto, Safety, Ident, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemId]),
43384338
/// A trait alias.
43394339
TraitAlias(Ident, &'hir Generics<'hir>, GenericBounds<'hir>),
43404340

@@ -4361,7 +4361,7 @@ pub struct Impl<'hir> {
43614361
pub of_trait: Option<TraitRef<'hir>>,
43624362

43634363
pub self_ty: &'hir Ty<'hir>,
4364-
pub items: &'hir [ImplItemRef],
4364+
pub items: &'hir [ImplItemId],
43654365
}
43664366

43674367
impl ItemKind<'_> {
@@ -4404,32 +4404,6 @@ impl ItemKind<'_> {
44044404
}
44054405
}
44064406

4407-
/// A reference from an trait to one of its associated items. This
4408-
/// contains the item's id, naturally, but also the item's name and
4409-
/// some other high-level details (like whether it is an associated
4410-
/// type or method, and whether it is public). This allows other
4411-
/// passes to find the impl they want without loading the ID (which
4412-
/// means fewer edges in the incremental compilation graph).
4413-
#[derive(Debug, Clone, Copy, HashStable_Generic)]
4414-
pub struct TraitItemRef {
4415-
pub id: TraitItemId,
4416-
pub ident: Ident,
4417-
pub span: Span,
4418-
}
4419-
4420-
/// A reference from an impl to one of its associated items. This
4421-
/// contains the item's ID, naturally, but also the item's name and
4422-
/// some other high-level details (like whether it is an associated
4423-
/// type or method, and whether it is public). This allows other
4424-
/// passes to find the impl they want without loading the ID (which
4425-
/// means fewer edges in the incremental compilation graph).
4426-
#[derive(Debug, Clone, Copy, HashStable_Generic)]
4427-
pub struct ImplItemRef {
4428-
pub id: ImplItemId,
4429-
pub ident: Ident,
4430-
pub span: Span,
4431-
}
4432-
44334407
// The bodies for items are stored "out of line", in a separate
44344408
// hashmap in the `Crate`. Here we just record the hir-id of the item
44354409
// so it can fetched later.

compiler/rustc_hir/src/intravisit.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -435,17 +435,17 @@ pub trait Visitor<'v>: Sized {
435435
fn visit_trait_item(&mut self, ti: &'v TraitItem<'v>) -> Self::Result {
436436
walk_trait_item(self, ti)
437437
}
438-
fn visit_trait_item_ref(&mut self, ii: &'v TraitItemRef) -> Self::Result {
439-
walk_trait_item_ref(self, ii)
438+
fn visit_trait_item_ref(&mut self, ii: &'v TraitItemId) -> Self::Result {
439+
walk_trait_item_ref(self, *ii)
440440
}
441441
fn visit_impl_item(&mut self, ii: &'v ImplItem<'v>) -> Self::Result {
442442
walk_impl_item(self, ii)
443443
}
444444
fn visit_foreign_item_ref(&mut self, ii: &'v ForeignItemId) -> Self::Result {
445445
walk_foreign_item_ref(self, *ii)
446446
}
447-
fn visit_impl_item_ref(&mut self, ii: &'v ImplItemRef) -> Self::Result {
448-
walk_impl_item_ref(self, ii)
447+
fn visit_impl_item_ref(&mut self, ii: &'v ImplItemId) -> Self::Result {
448+
walk_impl_item_ref(self, *ii)
449449
}
450450
fn visit_trait_ref(&mut self, t: &'v TraitRef<'v>) -> Self::Result {
451451
walk_trait_ref(self, t)
@@ -1245,13 +1245,8 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(
12451245
V::Result::output()
12461246
}
12471247

1248-
pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(
1249-
visitor: &mut V,
1250-
trait_item_ref: &'v TraitItemRef,
1251-
) -> V::Result {
1252-
let TraitItemRef { id, ident, span: _ } = *trait_item_ref;
1253-
try_visit!(visitor.visit_nested_trait_item(id));
1254-
visitor.visit_ident(ident)
1248+
pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, id: TraitItemId) -> V::Result {
1249+
visitor.visit_nested_trait_item(id)
12551250
}
12561251

12571252
pub fn walk_impl_item<'v, V: Visitor<'v>>(
@@ -1294,13 +1289,8 @@ pub fn walk_foreign_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, id: ForeignIte
12941289
visitor.visit_nested_foreign_item(id)
12951290
}
12961291

1297-
pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(
1298-
visitor: &mut V,
1299-
impl_item_ref: &'v ImplItemRef,
1300-
) -> V::Result {
1301-
let ImplItemRef { id, ident, span: _ } = *impl_item_ref;
1302-
try_visit!(visitor.visit_nested_impl_item(id));
1303-
visitor.visit_ident(ident)
1292+
pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, id: ImplItemId) -> V::Result {
1293+
visitor.visit_nested_impl_item(id)
13041294
}
13051295

13061296
pub fn walk_trait_ref<'v, V: Visitor<'v>>(

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -844,11 +844,9 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AdtDef<'_> {
844844
fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
845845
let item = tcx.hir_expect_item(def_id);
846846

847-
let (is_alias, is_auto, safety, items) = match item.kind {
848-
hir::ItemKind::Trait(is_auto, safety, .., items) => {
849-
(false, is_auto == hir::IsAuto::Yes, safety, items)
850-
}
851-
hir::ItemKind::TraitAlias(..) => (true, false, hir::Safety::Safe, &[][..]),
847+
let (is_alias, is_auto, safety) = match item.kind {
848+
hir::ItemKind::Trait(is_auto, safety, ..) => (false, is_auto == hir::IsAuto::Yes, safety),
849+
hir::ItemKind::TraitAlias(..) => (true, false, hir::Safety::Safe),
852850
_ => span_bug!(item.span, "trait_def_of_item invoked on non-trait"),
853851
};
854852

@@ -909,13 +907,16 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
909907
// functions in the trait with default implementations
910908
.and_then(|(list, attr_span)| {
911909
let errors = list.iter().filter_map(|ident| {
912-
let item = items.iter().find(|item| item.ident == *ident);
910+
let item = tcx
911+
.associated_items(def_id)
912+
.filter_by_name_unhygienic(ident.name)
913+
.find(|item| item.ident(tcx) == *ident);
913914

914915
match item {
915-
Some(item) if matches!(tcx.def_kind(item.id.owner_id), DefKind::AssocFn) => {
916-
if !tcx.defaultness(item.id.owner_id).has_value() {
916+
Some(item) if matches!(item.kind, ty::AssocKind::Fn { .. }) => {
917+
if !item.defaultness(tcx).has_value() {
917918
tcx.dcx().emit_err(errors::FunctionNotHaveDefaultImplementation {
918-
span: item.span,
919+
span: tcx.def_span(item.def_id),
919920
note_span: attr_span,
920921
});
921922

@@ -926,7 +927,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
926927
}
927928
Some(item) => {
928929
tcx.dcx().emit_err(errors::MustImplementNotFunction {
929-
span: item.span,
930+
span: tcx.def_span(item.def_id),
930931
span_note: errors::MustImplementNotFunctionSpanNote { span: attr_span },
931932
note: errors::MustImplementNotFunctionNote {},
932933
});

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,8 @@ impl<'a> State<'a> {
730730

731731
self.space();
732732
self.bopen(ib);
733-
for impl_item in items {
734-
self.ann.nested(self, Nested::ImplItem(impl_item.id));
733+
for &impl_item in items {
734+
self.ann.nested(self, Nested::ImplItem(impl_item));
735735
}
736736
self.bclose(item.span, cb);
737737
}
@@ -746,8 +746,8 @@ impl<'a> State<'a> {
746746
self.print_where_clause(generics);
747747
self.word(" ");
748748
self.bopen(ib);
749-
for trait_item in trait_items {
750-
self.ann.nested(self, Nested::TraitItem(trait_item.id));
749+
for &trait_item in trait_items {
750+
self.ann.nested(self, Nested::TraitItem(trait_item));
751751
}
752752
self.bclose(item.span, cb);
753753
}

compiler/rustc_lint/src/deref_into_dyn_supertrait.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_hir::{self as hir, LangItem};
22
use rustc_middle::ty;
33
use rustc_session::{declare_lint, declare_lint_pass};
4-
use rustc_span::sym;
4+
use rustc_span::{Ident, sym};
55
use rustc_trait_selection::traits::supertraits;
66

77
use crate::lints::{SupertraitAsDerefTarget, SupertraitAsDerefTargetLabel};
@@ -79,11 +79,15 @@ impl<'tcx> LateLintPass<'tcx> for DerefIntoDynSupertrait {
7979
// erase regions in self type for better diagnostic presentation
8080
let (self_ty, target_principal, supertrait_principal) =
8181
tcx.erase_regions((self_ty, target_principal, supertrait_principal));
82-
let label2 = impl_
83-
.items
84-
.iter()
85-
.find_map(|i| (i.ident.name == sym::Target).then_some(i.span))
86-
.map(|label| SupertraitAsDerefTargetLabel { label });
82+
let label2 = tcx
83+
.associated_items(item.owner_id)
84+
.find_by_ident_and_kind(
85+
tcx,
86+
Ident::with_dummy_span(sym::Target),
87+
ty::AssocTag::Type,
88+
item.owner_id.to_def_id(),
89+
)
90+
.map(|label| SupertraitAsDerefTargetLabel { label: tcx.def_span(label.def_id) });
8791
let span = tcx.def_span(item.owner_id.def_id);
8892
cx.emit_span_lint(
8993
DEREF_INTO_DYN_SUPERTRAIT,

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
11201120
ItemKind::Trait(_, _, _, generics, _, items)
11211121
if generics.params.len() != 0
11221122
|| items.iter().any(|item| {
1123-
matches!(self.tcx.def_kind(item.id.owner_id), DefKind::AssocTy)
1123+
matches!(self.tcx.def_kind(item.owner_id), DefKind::AssocTy)
11241124
}) => {}
11251125
ItemKind::TyAlias(_, generics, _) if generics.params.len() != 0 => {}
11261126
_ => {

compiler/rustc_passes/src/dead.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,8 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
415415
hir::ItemKind::Trait(.., trait_item_refs) => {
416416
// mark assoc ty live if the trait is live
417417
for trait_item in trait_item_refs {
418-
if matches!(self.tcx.def_kind(trait_item.id.owner_id), DefKind::AssocTy) {
419-
self.check_def_id(trait_item.id.owner_id.to_def_id());
418+
if matches!(self.tcx.def_kind(trait_item.owner_id), DefKind::AssocTy) {
419+
self.check_def_id(trait_item.owner_id.to_def_id());
420420
}
421421
}
422422
intravisit::walk_item(self, item)

compiler/rustc_passes/src/input_stats.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,9 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
467467
hir_visit::walk_trait_item(self, ti)
468468
}
469469

470-
fn visit_trait_item_ref(&mut self, ti: &'v hir::TraitItemRef) {
471-
self.record("TraitItemRef", Some(ti.id.hir_id()), ti);
472-
hir_visit::walk_trait_item_ref(self, ti)
470+
fn visit_trait_item_ref(&mut self, ti: &'v hir::TraitItemId) {
471+
self.record("TraitItemId", Some(ti.hir_id()), ti);
472+
hir_visit::walk_trait_item_ref(self, *ti)
473473
}
474474

475475
fn visit_impl_item(&mut self, ii: &'v hir::ImplItem<'v>) {
@@ -485,9 +485,9 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
485485
hir_visit::walk_foreign_item_ref(self, *fi)
486486
}
487487

488-
fn visit_impl_item_ref(&mut self, ii: &'v hir::ImplItemRef) {
489-
self.record("ImplItemRef", Some(ii.id.hir_id()), ii);
490-
hir_visit::walk_impl_item_ref(self, ii)
488+
fn visit_impl_item_ref(&mut self, ii: &'v hir::ImplItemId) {
489+
self.record("ImplItemId", Some(ii.hir_id()), ii);
490+
hir_visit::walk_impl_item_ref(self, *ii)
491491
}
492492

493493
fn visit_param_bound(&mut self, b: &'v hir::GenericBound<'v>) {

0 commit comments

Comments
 (0)