Skip to content

Commit 21fd82a

Browse files
committed
Retire hir::*ItemRef.
1 parent 5bd3841 commit 21fd82a

File tree

52 files changed

+244
-308
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

+244
-308
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
@@ -4162,7 +4162,7 @@ impl<'hir> Item<'hir> {
41624162
Ident,
41634163
&'hir Generics<'hir>,
41644164
GenericBounds<'hir>,
4165-
&'hir [TraitItemRef]
4165+
&'hir [TraitItemId]
41664166
),
41674167
ItemKind::Trait(is_auto, safety, ident, generics, bounds, items),
41684168
(*is_auto, *safety, *ident, generics, bounds, items);
@@ -4335,7 +4335,7 @@ pub enum ItemKind<'hir> {
43354335
/// A union definition, e.g., `union Foo<A, B> {x: A, y: B}`.
43364336
Union(Ident, &'hir Generics<'hir>, VariantData<'hir>),
43374337
/// A trait definition.
4338-
Trait(IsAuto, Safety, Ident, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemRef]),
4338+
Trait(IsAuto, Safety, Ident, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemId]),
43394339
/// A trait alias.
43404340
TraitAlias(Ident, &'hir Generics<'hir>, GenericBounds<'hir>),
43414341

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

43644364
pub self_ty: &'hir Ty<'hir>,
4365-
pub items: &'hir [ImplItemRef],
4365+
pub items: &'hir [ImplItemId],
43664366
}
43674367

43684368
impl ItemKind<'_> {
@@ -4405,32 +4405,6 @@ impl ItemKind<'_> {
44054405
}
44064406
}
44074407

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

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

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

@@ -928,7 +929,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
928929
}
929930
Some(item) => {
930931
tcx.dcx().emit_err(errors::MustImplementNotFunction {
931-
span: item.span,
932+
span: tcx.def_span(item.def_id),
932933
span_note: errors::MustImplementNotFunctionSpanNote { span: attr_span },
933934
note: errors::MustImplementNotFunctionNote {},
934935
});

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
@@ -1152,7 +1152,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
11521152
ItemKind::Trait(_, _, _, generics, _, items)
11531153
if generics.params.len() != 0
11541154
|| items.iter().any(|item| {
1155-
matches!(self.tcx.def_kind(item.id.owner_id), DefKind::AssocTy)
1155+
matches!(self.tcx.def_kind(item.owner_id), DefKind::AssocTy)
11561156
}) => {}
11571157
ItemKind::TyAlias(_, generics, _) if generics.params.len() != 0 => {}
11581158
_ => {

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)