Skip to content

Commit 3afc5ea

Browse files
committed
use def_span and def_kind queries instead of calling tcx.hir() methods
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
1 parent ef1d112 commit 3afc5ea

File tree

17 files changed

+31
-104
lines changed

17 files changed

+31
-104
lines changed

compiler/rustc_metadata/src/foreign_modules.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_session::cstore::ForeignModule;
66
crate fn collect(tcx: TyCtxt<'_>) -> Vec<ForeignModule> {
77
let mut modules = Vec::new();
88
for id in tcx.hir().items() {
9-
if !matches!(tcx.hir().def_kind(id.def_id), DefKind::ForeignMod) {
9+
if !matches!(tcx.def_kind(id.def_id), DefKind::ForeignMod) {
1010
continue;
1111
}
1212
let item = tcx.hir().item(id);

compiler/rustc_metadata/src/native_libs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct Collector<'tcx> {
3636

3737
impl<'tcx> Collector<'tcx> {
3838
fn process_item(&mut self, id: rustc_hir::ItemId) {
39-
if !matches!(self.tcx.hir().def_kind(id.def_id), DefKind::ForeignMod) {
39+
if !matches!(self.tcx.def_kind(id.def_id), DefKind::ForeignMod) {
4040
return;
4141
}
4242

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1813,7 +1813,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
18131813
FxHashMap::default();
18141814

18151815
for id in tcx.hir().items() {
1816-
if matches!(tcx.hir().def_kind(id.def_id), DefKind::Impl) {
1816+
if matches!(tcx.def_kind(id.def_id), DefKind::Impl) {
18171817
if let Some(trait_ref) = tcx.impl_trait_ref(id.def_id.to_def_id()) {
18181818
let simplified_self_ty = fast_reject::simplify_type(
18191819
self.tcx,

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ struct RootCollector<'a, 'tcx> {
11671167

11681168
impl<'v> RootCollector<'_, 'v> {
11691169
fn process_item(&mut self, id: hir::ItemId) {
1170-
match self.tcx.hir().def_kind(id.def_id) {
1170+
match self.tcx.def_kind(id.def_id) {
11711171
DefKind::Enum | DefKind::Struct | DefKind::Union => {
11721172
let item = self.tcx.hir().item(id);
11731173
match item.kind {
@@ -1228,7 +1228,7 @@ impl<'v> RootCollector<'_, 'v> {
12281228
}
12291229

12301230
fn process_impl_item(&mut self, id: hir::ImplItemId) {
1231-
if matches!(self.tcx.hir().def_kind(id.def_id), DefKind::AssocFn) {
1231+
if matches!(self.tcx.def_kind(id.def_id), DefKind::AssocFn) {
12321232
self.push_if_root(id.def_id);
12331233
}
12341234
}

compiler/rustc_passes/src/lang_items.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems {
240240
let crate_items = tcx.hir_crate_items(());
241241

242242
for id in crate_items.items() {
243-
collector.check_for_lang(Target::from_def_kind(tcx.hir().def_kind(id.def_id)), id.hir_id());
243+
collector.check_for_lang(Target::from_def_kind(tcx.def_kind(id.def_id)), id.hir_id());
244244

245-
if matches!(tcx.hir().def_kind(id.def_id), DefKind::Enum) {
245+
if matches!(tcx.def_kind(id.def_id), DefKind::Enum) {
246246
let item = tcx.hir().item(id);
247247
if let hir::ItemKind::Enum(def, ..) = &item.kind {
248248
for variant in def.variants {

compiler/rustc_typeck/src/check/check.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
719719
tcx.def_path_str(id.def_id.to_def_id())
720720
);
721721
let _indenter = indenter();
722-
match tcx.hir().def_kind(id.def_id) {
722+
match tcx.def_kind(id.def_id) {
723723
DefKind::Static(..) => {
724724
tcx.ensure().typeck(id.def_id);
725725
maybe_check_static_with_link_section(tcx, id.def_id, tcx.def_span(id.def_id));
@@ -1473,7 +1473,6 @@ pub(super) fn check_type_params_are_used<'tcx>(
14731473
pub(super) fn check_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
14741474
let module = tcx.hir_module_items(module_def_id);
14751475
for id in module.items() {
1476-
// let item = tcx.hir().item(id);
14771476
check_item_type(tcx, id);
14781477
}
14791478
}

compiler/rustc_typeck/src/check_unused.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
1717
}
1818

1919
for id in tcx.hir().items() {
20-
if matches!(tcx.hir().def_kind(id.def_id), DefKind::Use) {
20+
if matches!(tcx.def_kind(id.def_id), DefKind::Use) {
2121
if tcx.visibility(id.def_id).is_public() {
2222
continue;
2323
}
@@ -101,7 +101,7 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
101101
let mut crates_to_lint = vec![];
102102

103103
for id in tcx.hir().items() {
104-
if matches!(tcx.hir().def_kind(id.def_id), DefKind::ExternCrate) {
104+
if matches!(tcx.def_kind(id.def_id), DefKind::ExternCrate) {
105105
let item = tcx.hir().item(id);
106106
if let hir::ItemKind::ExternCrate(orig_name) = item.kind {
107107
crates_to_lint.push(ExternCrateToLint {

compiler/rustc_typeck/src/coherence/inherent_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl<'tcx> InherentCollect<'tcx> {
177177
}
178178

179179
fn check_item(&mut self, id: hir::ItemId) {
180-
if !matches!(self.tcx.hir().def_kind(id.def_id), DefKind::Impl) {
180+
if !matches!(self.tcx.def_kind(id.def_id), DefKind::Impl) {
181181
return;
182182
}
183183

compiler/rustc_typeck/src/coherence/inherent_impls_overlap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
126126
}
127127

128128
fn check_item(&mut self, id: hir::ItemId) {
129-
let def_kind = self.tcx.hir().def_kind(id.def_id);
129+
let def_kind = self.tcx.def_kind(id.def_id);
130130
if !matches!(def_kind, DefKind::Enum | DefKind::Struct | DefKind::Trait | DefKind::Union) {
131131
return;
132132
}

compiler/rustc_typeck/src/coherence/unsafety.rs

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_middle::ty::TyCtxt;
99

1010
pub fn check(tcx: TyCtxt<'_>) {
1111
for id in tcx.hir().items() {
12-
if matches!(tcx.hir().def_kind(id.def_id), DefKind::Impl) {
12+
if matches!(tcx.def_kind(id.def_id), DefKind::Impl) {
1313
let item = tcx.hir().item(id);
1414
if let hir::ItemKind::Impl(ref impl_) = item.kind {
1515
check_unsafety_coherence(
@@ -83,74 +83,3 @@ fn check_unsafety_coherence<'tcx>(
8383
}
8484
}
8585
}
86-
87-
// struct UnsafetyChecker<'tcx> {
88-
// tcx: TyCtxt<'tcx>,
89-
// }
90-
//
91-
// impl<'tcx> UnsafetyChecker<'tcx> {
92-
// fn check_unsafety_coherence(
93-
// &mut self,
94-
// item: &hir::Item<'_>,
95-
// impl_generics: Option<&hir::Generics<'_>>,
96-
// unsafety: hir::Unsafety,
97-
// polarity: hir::ImplPolarity,
98-
// ) {
99-
// if let Some(trait_ref) = self.tcx.impl_trait_ref(item.def_id) {
100-
// let trait_def = self.tcx.trait_def(trait_ref.def_id);
101-
// let unsafe_attr = impl_generics.and_then(|generics| {
102-
// generics.params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle")
103-
// });
104-
// match (trait_def.unsafety, unsafe_attr, unsafety, polarity) {
105-
// (Unsafety::Normal, None, Unsafety::Unsafe, hir::ImplPolarity::Positive) => {
106-
// struct_span_err!(
107-
// self.tcx.sess,
108-
// item.span,
109-
// E0199,
110-
// "implementing the trait `{}` is not unsafe",
111-
// trait_ref.print_only_trait_path()
112-
// )
113-
// .emit();
114-
// }
115-
//
116-
// (Unsafety::Unsafe, _, Unsafety::Normal, hir::ImplPolarity::Positive) => {
117-
// struct_span_err!(
118-
// self.tcx.sess,
119-
// item.span,
120-
// E0200,
121-
// "the trait `{}` requires an `unsafe impl` declaration",
122-
// trait_ref.print_only_trait_path()
123-
// )
124-
// .emit();
125-
// }
126-
//
127-
// (
128-
// Unsafety::Normal,
129-
// Some(attr_name),
130-
// Unsafety::Normal,
131-
// hir::ImplPolarity::Positive,
132-
// ) => {
133-
// struct_span_err!(
134-
// self.tcx.sess,
135-
// item.span,
136-
// E0569,
137-
// "requires an `unsafe impl` declaration due to `#[{}]` attribute",
138-
// attr_name
139-
// )
140-
// .emit();
141-
// }
142-
//
143-
// (_, _, Unsafety::Unsafe, hir::ImplPolarity::Negative(_)) => {
144-
// // Reported in AST validation
145-
// self.tcx.sess.delay_span_bug(item.span, "unsafe negative impl");
146-
// }
147-
// (_, _, Unsafety::Normal, hir::ImplPolarity::Negative(_))
148-
// | (Unsafety::Unsafe, _, Unsafety::Unsafe, hir::ImplPolarity::Positive)
149-
// | (Unsafety::Normal, Some(_), Unsafety::Unsafe, hir::ImplPolarity::Positive)
150-
// | (Unsafety::Normal, None, Unsafety::Normal, _) => {
151-
// // OK
152-
// }
153-
// }
154-
// }
155-
// }
156-
// }

0 commit comments

Comments
 (0)