Skip to content

Commit f395f2e

Browse files
committed
Use less HirId when referring to items.
1 parent c4e7427 commit f395f2e

File tree

3 files changed

+27
-28
lines changed

3 files changed

+27
-28
lines changed

Diff for: compiler/rustc_incremental/src/persist/dirty_clean.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_ast::{self as ast, Attribute, NestedMetaItem};
1717
use rustc_data_structures::fingerprint::Fingerprint;
1818
use rustc_data_structures::fx::FxHashSet;
1919
use rustc_hir as hir;
20-
use rustc_hir::def_id::DefId;
20+
use rustc_hir::def_id::{DefId, LocalDefId};
2121
use rustc_hir::intravisit;
2222
use rustc_hir::itemlikevisit::ItemLikeVisitor;
2323
use rustc_hir::Node as HirNode;
@@ -179,7 +179,7 @@ pub struct DirtyCleanVisitor<'tcx> {
179179

180180
impl DirtyCleanVisitor<'tcx> {
181181
/// Possibly "deserialize" the attribute into a clean/dirty assertion
182-
fn assertion_maybe(&mut self, item_id: hir::HirId, attr: &Attribute) -> Option<Assertion> {
182+
fn assertion_maybe(&mut self, item_id: LocalDefId, attr: &Attribute) -> Option<Assertion> {
183183
let is_clean = if self.tcx.sess.check_name(attr, sym::rustc_dirty) {
184184
false
185185
} else if self.tcx.sess.check_name(attr, sym::rustc_clean) {
@@ -207,7 +207,7 @@ impl DirtyCleanVisitor<'tcx> {
207207
/// Gets the "auto" assertion on pre-validated attr, along with the `except` labels.
208208
fn assertion_auto(
209209
&mut self,
210-
item_id: hir::HirId,
210+
item_id: LocalDefId,
211211
attr: &Attribute,
212212
is_clean: bool,
213213
) -> Assertion {
@@ -253,8 +253,9 @@ impl DirtyCleanVisitor<'tcx> {
253253

254254
/// Return all DepNode labels that should be asserted for this item.
255255
/// index=0 is the "name" used for error messages
256-
fn auto_labels(&mut self, item_id: hir::HirId, attr: &Attribute) -> (&'static str, Labels) {
257-
let node = self.tcx.hir().get(item_id);
256+
fn auto_labels(&mut self, item_id: LocalDefId, attr: &Attribute) -> (&'static str, Labels) {
257+
let hir_id = self.tcx.hir().local_def_id_to_hir_id(item_id);
258+
let node = self.tcx.hir().get(hir_id);
258259
let (name, labels) = match node {
259260
HirNode::Item(item) => {
260261
match item.kind {
@@ -430,18 +431,17 @@ impl DirtyCleanVisitor<'tcx> {
430431
}
431432
}
432433

433-
fn check_item(&mut self, item_id: hir::HirId, item_span: Span) {
434-
let def_id = self.tcx.hir().local_def_id(item_id);
435-
for attr in self.tcx.get_attrs(def_id.to_def_id()).iter() {
434+
fn check_item(&mut self, item_id: LocalDefId, item_span: Span) {
435+
for attr in self.tcx.get_attrs(item_id.to_def_id()).iter() {
436436
let assertion = match self.assertion_maybe(item_id, attr) {
437437
Some(a) => a,
438438
None => continue,
439439
};
440440
self.checked_attrs.insert(attr.id);
441-
for dep_node in self.dep_nodes(&assertion.clean, def_id.to_def_id()) {
441+
for dep_node in self.dep_nodes(&assertion.clean, item_id.to_def_id()) {
442442
self.assert_clean(item_span, dep_node);
443443
}
444-
for dep_node in self.dep_nodes(&assertion.dirty, def_id.to_def_id()) {
444+
for dep_node in self.dep_nodes(&assertion.dirty, item_id.to_def_id()) {
445445
self.assert_dirty(item_span, dep_node);
446446
}
447447
}
@@ -450,19 +450,19 @@ impl DirtyCleanVisitor<'tcx> {
450450

451451
impl ItemLikeVisitor<'tcx> for DirtyCleanVisitor<'tcx> {
452452
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
453-
self.check_item(item.hir_id(), item.span);
453+
self.check_item(item.def_id, item.span);
454454
}
455455

456456
fn visit_trait_item(&mut self, item: &hir::TraitItem<'_>) {
457-
self.check_item(item.hir_id(), item.span);
457+
self.check_item(item.def_id, item.span);
458458
}
459459

460460
fn visit_impl_item(&mut self, item: &hir::ImplItem<'_>) {
461-
self.check_item(item.hir_id(), item.span);
461+
self.check_item(item.def_id, item.span);
462462
}
463463

464464
fn visit_foreign_item(&mut self, item: &hir::ForeignItem<'_>) {
465-
self.check_item(item.hir_id(), item.span);
465+
self.check_item(item.def_id, item.span);
466466
}
467467
}
468468

Diff for: compiler/rustc_passes/src/diagnostic_items.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_hir::itemlikevisit::ItemLikeVisitor;
1616
use rustc_middle::ty::query::Providers;
1717
use rustc_middle::ty::TyCtxt;
1818
use rustc_session::Session;
19-
use rustc_span::def_id::{DefId, LOCAL_CRATE};
19+
use rustc_span::def_id::{DefId, LocalDefId, LOCAL_CRATE};
2020
use rustc_span::symbol::{sym, Symbol};
2121

2222
struct DiagnosticItemCollector<'tcx> {
@@ -27,19 +27,19 @@ struct DiagnosticItemCollector<'tcx> {
2727

2828
impl<'v, 'tcx> ItemLikeVisitor<'v> for DiagnosticItemCollector<'tcx> {
2929
fn visit_item(&mut self, item: &hir::Item<'_>) {
30-
self.observe_item(&item.attrs, item.hir_id());
30+
self.observe_item(&item.attrs, item.def_id);
3131
}
3232

3333
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) {
34-
self.observe_item(&trait_item.attrs, trait_item.hir_id());
34+
self.observe_item(&trait_item.attrs, trait_item.def_id);
3535
}
3636

3737
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) {
38-
self.observe_item(&impl_item.attrs, impl_item.hir_id());
38+
self.observe_item(&impl_item.attrs, impl_item.def_id);
3939
}
4040

4141
fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) {
42-
self.observe_item(foreign_item.attrs, foreign_item.hir_id());
42+
self.observe_item(foreign_item.attrs, foreign_item.def_id);
4343
}
4444
}
4545

@@ -48,9 +48,8 @@ impl<'tcx> DiagnosticItemCollector<'tcx> {
4848
DiagnosticItemCollector { tcx, items: Default::default() }
4949
}
5050

51-
fn observe_item(&mut self, attrs: &[ast::Attribute], hir_id: hir::HirId) {
51+
fn observe_item(&mut self, attrs: &[ast::Attribute], def_id: LocalDefId) {
5252
if let Some(name) = extract(&self.tcx.sess, attrs) {
53-
let def_id = self.tcx.hir().local_def_id(hir_id);
5453
// insert into our table
5554
collect_item(self.tcx, &mut self.items, name, def_id.to_def_id());
5655
}
@@ -106,7 +105,7 @@ fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> FxHashMap<Symbol, DefId> {
106105
tcx.hir().krate().visit_all_item_likes(&mut collector);
107106

108107
for m in tcx.hir().krate().exported_macros {
109-
collector.observe_item(m.attrs, m.hir_id());
108+
collector.observe_item(m.attrs, m.def_id);
110109
}
111110

112111
collector.items

Diff for: compiler/rustc_symbol_mangling/src/test.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! paths etc in all kinds of annoying scenarios.
66
77
use rustc_hir as hir;
8+
use rustc_hir::def_id::LocalDefId;
89
use rustc_middle::ty::print::with_no_trimmed_paths;
910
use rustc_middle::ty::{subst::InternalSubsts, Instance, TyCtxt};
1011
use rustc_span::symbol::{sym, Symbol};
@@ -31,9 +32,8 @@ struct SymbolNamesTest<'tcx> {
3132
}
3233

3334
impl SymbolNamesTest<'tcx> {
34-
fn process_attrs(&mut self, hir_id: hir::HirId) {
35+
fn process_attrs(&mut self, def_id: LocalDefId) {
3536
let tcx = self.tcx;
36-
let def_id = tcx.hir().local_def_id(hir_id);
3737
for attr in tcx.get_attrs(def_id.to_def_id()).iter() {
3838
if tcx.sess.check_name(attr, SYMBOL_NAME) {
3939
let def_id = def_id.to_def_id();
@@ -61,18 +61,18 @@ impl SymbolNamesTest<'tcx> {
6161

6262
impl hir::itemlikevisit::ItemLikeVisitor<'tcx> for SymbolNamesTest<'tcx> {
6363
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
64-
self.process_attrs(item.hir_id());
64+
self.process_attrs(item.def_id);
6565
}
6666

6767
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
68-
self.process_attrs(trait_item.hir_id());
68+
self.process_attrs(trait_item.def_id);
6969
}
7070

7171
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
72-
self.process_attrs(impl_item.hir_id());
72+
self.process_attrs(impl_item.def_id);
7373
}
7474

7575
fn visit_foreign_item(&mut self, foreign_item: &'tcx hir::ForeignItem<'tcx>) {
76-
self.process_attrs(foreign_item.hir_id());
76+
self.process_attrs(foreign_item.def_id);
7777
}
7878
}

0 commit comments

Comments
 (0)