diff --git a/compiler/rustc_metadata/src/foreign_modules.rs b/compiler/rustc_metadata/src/foreign_modules.rs index 97fcbeb4ccc..70da96154b0 100644 --- a/compiler/rustc_metadata/src/foreign_modules.rs +++ b/compiler/rustc_metadata/src/foreign_modules.rs @@ -6,7 +6,7 @@ use rustc_session::cstore::ForeignModule; crate fn collect(tcx: TyCtxt<'_>) -> Vec { let mut modules = Vec::new(); for id in tcx.hir().items() { - if !matches!(tcx.hir().def_kind(id.def_id), DefKind::ForeignMod) { + if !matches!(tcx.def_kind(id.def_id), DefKind::ForeignMod) { continue; } let item = tcx.hir().item(id); diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs index 43b6ecee794..f468399930d 100644 --- a/compiler/rustc_metadata/src/native_libs.rs +++ b/compiler/rustc_metadata/src/native_libs.rs @@ -36,7 +36,7 @@ struct Collector<'tcx> { impl<'tcx> Collector<'tcx> { fn process_item(&mut self, id: rustc_hir::ItemId) { - if !matches!(self.tcx.hir().def_kind(id.def_id), DefKind::ForeignMod) { + if !matches!(self.tcx.def_kind(id.def_id), DefKind::ForeignMod) { return; } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index b2eafa035db..77d6ce1e766 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1813,7 +1813,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { FxHashMap::default(); for id in tcx.hir().items() { - if matches!(tcx.hir().def_kind(id.def_id), DefKind::Impl) { + if matches!(tcx.def_kind(id.def_id), DefKind::Impl) { if let Some(trait_ref) = tcx.impl_trait_ref(id.def_id.to_def_id()) { let simplified_self_ty = fast_reject::simplify_type( self.tcx, diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 1828aecb375..c557b7c359b 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -1167,7 +1167,7 @@ struct RootCollector<'a, 'tcx> { impl<'v> RootCollector<'_, 'v> { fn process_item(&mut self, id: hir::ItemId) { - match self.tcx.hir().def_kind(id.def_id) { + match self.tcx.def_kind(id.def_id) { DefKind::Enum | DefKind::Struct | DefKind::Union => { let item = self.tcx.hir().item(id); match item.kind { @@ -1228,7 +1228,7 @@ impl<'v> RootCollector<'_, 'v> { } fn process_impl_item(&mut self, id: hir::ImplItemId) { - if matches!(self.tcx.hir().def_kind(id.def_id), DefKind::AssocFn) { + if matches!(self.tcx.def_kind(id.def_id), DefKind::AssocFn) { self.push_if_root(id.def_id); } } diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index 18d9bdf8e17..79900a90aed 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -240,9 +240,9 @@ fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems { let crate_items = tcx.hir_crate_items(()); for id in crate_items.items() { - collector.check_for_lang(Target::from_def_kind(tcx.hir().def_kind(id.def_id)), id.hir_id()); + collector.check_for_lang(Target::from_def_kind(tcx.def_kind(id.def_id)), id.hir_id()); - if matches!(tcx.hir().def_kind(id.def_id), DefKind::Enum) { + if matches!(tcx.def_kind(id.def_id), DefKind::Enum) { let item = tcx.hir().item(id); if let hir::ItemKind::Enum(def, ..) = &item.kind { for variant in def.variants { diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index b2348511e6b..4627b58c9bc 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -719,7 +719,7 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) { tcx.def_path_str(id.def_id.to_def_id()) ); let _indenter = indenter(); - match tcx.hir().def_kind(id.def_id) { + match tcx.def_kind(id.def_id) { DefKind::Static(..) => { tcx.ensure().typeck(id.def_id); 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>( pub(super) fn check_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalDefId) { let module = tcx.hir_module_items(module_def_id); for id in module.items() { - // let item = tcx.hir().item(id); check_item_type(tcx, id); } } diff --git a/compiler/rustc_typeck/src/check_unused.rs b/compiler/rustc_typeck/src/check_unused.rs index d52886a09bd..1310467aeb9 100644 --- a/compiler/rustc_typeck/src/check_unused.rs +++ b/compiler/rustc_typeck/src/check_unused.rs @@ -17,7 +17,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) { } for id in tcx.hir().items() { - if matches!(tcx.hir().def_kind(id.def_id), DefKind::Use) { + if matches!(tcx.def_kind(id.def_id), DefKind::Use) { if tcx.visibility(id.def_id).is_public() { continue; } @@ -101,7 +101,7 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) { let mut crates_to_lint = vec![]; for id in tcx.hir().items() { - if matches!(tcx.hir().def_kind(id.def_id), DefKind::ExternCrate) { + if matches!(tcx.def_kind(id.def_id), DefKind::ExternCrate) { let item = tcx.hir().item(id); if let hir::ItemKind::ExternCrate(orig_name) = item.kind { crates_to_lint.push(ExternCrateToLint { diff --git a/compiler/rustc_typeck/src/coherence/inherent_impls.rs b/compiler/rustc_typeck/src/coherence/inherent_impls.rs index 19549038c9d..b9d4167dbff 100644 --- a/compiler/rustc_typeck/src/coherence/inherent_impls.rs +++ b/compiler/rustc_typeck/src/coherence/inherent_impls.rs @@ -177,7 +177,7 @@ impl<'tcx> InherentCollect<'tcx> { } fn check_item(&mut self, id: hir::ItemId) { - if !matches!(self.tcx.hir().def_kind(id.def_id), DefKind::Impl) { + if !matches!(self.tcx.def_kind(id.def_id), DefKind::Impl) { return; } diff --git a/compiler/rustc_typeck/src/coherence/inherent_impls_overlap.rs b/compiler/rustc_typeck/src/coherence/inherent_impls_overlap.rs index 6ddaecb91b2..db67c1f7c9e 100644 --- a/compiler/rustc_typeck/src/coherence/inherent_impls_overlap.rs +++ b/compiler/rustc_typeck/src/coherence/inherent_impls_overlap.rs @@ -126,7 +126,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> { } fn check_item(&mut self, id: hir::ItemId) { - let def_kind = self.tcx.hir().def_kind(id.def_id); + let def_kind = self.tcx.def_kind(id.def_id); if !matches!(def_kind, DefKind::Enum | DefKind::Struct | DefKind::Trait | DefKind::Union) { return; } diff --git a/compiler/rustc_typeck/src/coherence/unsafety.rs b/compiler/rustc_typeck/src/coherence/unsafety.rs index 619bae9b7ed..3cfc96ccbfd 100644 --- a/compiler/rustc_typeck/src/coherence/unsafety.rs +++ b/compiler/rustc_typeck/src/coherence/unsafety.rs @@ -9,7 +9,7 @@ use rustc_middle::ty::TyCtxt; pub fn check(tcx: TyCtxt<'_>) { for id in tcx.hir().items() { - if matches!(tcx.hir().def_kind(id.def_id), DefKind::Impl) { + if matches!(tcx.def_kind(id.def_id), DefKind::Impl) { let item = tcx.hir().item(id); if let hir::ItemKind::Impl(ref impl_) = item.kind { check_unsafety_coherence( @@ -83,74 +83,3 @@ fn check_unsafety_coherence<'tcx>( } } } - -// struct UnsafetyChecker<'tcx> { -// tcx: TyCtxt<'tcx>, -// } -// -// impl<'tcx> UnsafetyChecker<'tcx> { -// fn check_unsafety_coherence( -// &mut self, -// item: &hir::Item<'_>, -// impl_generics: Option<&hir::Generics<'_>>, -// unsafety: hir::Unsafety, -// polarity: hir::ImplPolarity, -// ) { -// if let Some(trait_ref) = self.tcx.impl_trait_ref(item.def_id) { -// let trait_def = self.tcx.trait_def(trait_ref.def_id); -// let unsafe_attr = impl_generics.and_then(|generics| { -// generics.params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle") -// }); -// match (trait_def.unsafety, unsafe_attr, unsafety, polarity) { -// (Unsafety::Normal, None, Unsafety::Unsafe, hir::ImplPolarity::Positive) => { -// struct_span_err!( -// self.tcx.sess, -// item.span, -// E0199, -// "implementing the trait `{}` is not unsafe", -// trait_ref.print_only_trait_path() -// ) -// .emit(); -// } -// -// (Unsafety::Unsafe, _, Unsafety::Normal, hir::ImplPolarity::Positive) => { -// struct_span_err!( -// self.tcx.sess, -// item.span, -// E0200, -// "the trait `{}` requires an `unsafe impl` declaration", -// trait_ref.print_only_trait_path() -// ) -// .emit(); -// } -// -// ( -// Unsafety::Normal, -// Some(attr_name), -// Unsafety::Normal, -// hir::ImplPolarity::Positive, -// ) => { -// struct_span_err!( -// self.tcx.sess, -// item.span, -// E0569, -// "requires an `unsafe impl` declaration due to `#[{}]` attribute", -// attr_name -// ) -// .emit(); -// } -// -// (_, _, Unsafety::Unsafe, hir::ImplPolarity::Negative(_)) => { -// // Reported in AST validation -// self.tcx.sess.delay_span_bug(item.span, "unsafe negative impl"); -// } -// (_, _, Unsafety::Normal, hir::ImplPolarity::Negative(_)) -// | (Unsafety::Unsafe, _, Unsafety::Unsafe, hir::ImplPolarity::Positive) -// | (Unsafety::Normal, Some(_), Unsafety::Unsafe, hir::ImplPolarity::Positive) -// | (Unsafety::Normal, None, Unsafety::Normal, _) => { -// // OK -// } -// } -// } -// } -// } diff --git a/compiler/rustc_typeck/src/impl_wf_check.rs b/compiler/rustc_typeck/src/impl_wf_check.rs index 9f665fe60a7..c089d25d222 100644 --- a/compiler/rustc_typeck/src/impl_wf_check.rs +++ b/compiler/rustc_typeck/src/impl_wf_check.rs @@ -65,7 +65,7 @@ fn check_mod_impl_wf(tcx: TyCtxt<'_>, module_def_id: LocalDefId) { let min_specialization = tcx.features().min_specialization; let module = tcx.hir_module_items(module_def_id); for id in module.items() { - if matches!(tcx.hir().def_kind(id.def_id), DefKind::Impl) { + if matches!(tcx.def_kind(id.def_id), DefKind::Impl) { let item = tcx.hir().item(id); if let hir::ItemKind::Impl(ref impl_) = item.kind { enforce_impl_params_are_constrained(tcx, item.def_id, impl_.items); diff --git a/compiler/rustc_typeck/src/outlives/implicit_infer.rs b/compiler/rustc_typeck/src/outlives/implicit_infer.rs index 6f842c6e71a..96dc83b259f 100644 --- a/compiler/rustc_typeck/src/outlives/implicit_infer.rs +++ b/compiler/rustc_typeck/src/outlives/implicit_infer.rs @@ -35,7 +35,7 @@ pub fn infer_predicates<'tcx>( debug!("InferVisitor::visit_item(item={:?})", item_did); let mut item_required_predicates = RequiredPredicates::default(); - match tcx.hir().def_kind(item_did) { + match tcx.def_kind(item_did) { DefKind::Union | DefKind::Enum | DefKind::Struct => { let adt_def = tcx.adt_def(item_did.to_def_id()); diff --git a/compiler/rustc_typeck/src/outlives/test.rs b/compiler/rustc_typeck/src/outlives/test.rs index b9236d4024e..eb0e1203405 100644 --- a/compiler/rustc_typeck/src/outlives/test.rs +++ b/compiler/rustc_typeck/src/outlives/test.rs @@ -10,7 +10,7 @@ pub fn test_inferred_outlives(tcx: TyCtxt<'_>) { let inferred_outlives_of = tcx.inferred_outlives_of(id.def_id); struct_span_err!( tcx.sess, - tcx.hir().span(id.hir_id()), + tcx.def_span(id.def_id), E0640, "{:?}", inferred_outlives_of diff --git a/compiler/rustc_typeck/src/variance/constraints.rs b/compiler/rustc_typeck/src/variance/constraints.rs index d9ba6b2581b..be8e825d990 100644 --- a/compiler/rustc_typeck/src/variance/constraints.rs +++ b/compiler/rustc_typeck/src/variance/constraints.rs @@ -69,19 +69,19 @@ pub fn add_constraints_from_crate<'a, 'tcx>( } for id in crate_items.trait_items() { - if let DefKind::AssocFn = tcx.hir().def_kind(id.def_id) { + if let DefKind::AssocFn = tcx.def_kind(id.def_id) { constraint_cx.check_node_helper(id.hir_id()); } } for id in crate_items.impl_items() { - if let DefKind::AssocFn = tcx.hir().def_kind(id.def_id) { + if let DefKind::AssocFn = tcx.def_kind(id.def_id) { constraint_cx.check_node_helper(id.hir_id()); } } for id in crate_items.foreign_items() { - if let DefKind::Fn = tcx.hir().def_kind(id.def_id) { + if let DefKind::Fn = tcx.def_kind(id.def_id) { constraint_cx.check_node_helper(id.hir_id()); } } @@ -91,7 +91,7 @@ pub fn add_constraints_from_crate<'a, 'tcx>( impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { fn check_item(&mut self, id: hir::ItemId) { - let def_kind = self.tcx().hir().def_kind(id.def_id); + let def_kind = self.tcx().def_kind(id.def_id); match def_kind { DefKind::Struct | DefKind::Union => { let item = self.tcx().hir().item(id); diff --git a/compiler/rustc_typeck/src/variance/terms.rs b/compiler/rustc_typeck/src/variance/terms.rs index f96c8b46b86..ab64befe5dc 100644 --- a/compiler/rustc_typeck/src/variance/terms.rs +++ b/compiler/rustc_typeck/src/variance/terms.rs @@ -86,19 +86,19 @@ pub fn determine_parameters_to_be_inferred<'a, 'tcx>( } for id in crate_items.trait_items() { - if let DefKind::AssocFn = tcx.hir().def_kind(id.def_id) { + if let DefKind::AssocFn = tcx.def_kind(id.def_id) { terms_cx.add_inferreds_for_item(id.hir_id()); } } for id in crate_items.impl_items() { - if let DefKind::AssocFn = tcx.hir().def_kind(id.def_id) { + if let DefKind::AssocFn = tcx.def_kind(id.def_id) { terms_cx.add_inferreds_for_item(id.hir_id()); } } for id in crate_items.foreign_items() { - if let DefKind::Fn = tcx.hir().def_kind(id.def_id) { + if let DefKind::Fn = tcx.def_kind(id.def_id) { terms_cx.add_inferreds_for_item(id.hir_id()); } } @@ -150,7 +150,7 @@ impl<'a, 'tcx> TermsContext<'a, 'tcx> { fn check_item(&mut self, id: hir::ItemId) { debug!("add_inferreds for item {}", self.tcx.hir().node_to_string(id.hir_id())); - let def_kind = self.tcx.hir().def_kind(id.def_id); + let def_kind = self.tcx.def_kind(id.def_id); match def_kind { DefKind::Struct | DefKind::Union => { let item = self.tcx.hir().item(id); diff --git a/compiler/rustc_typeck/src/variance/test.rs b/compiler/rustc_typeck/src/variance/test.rs index 5cd08306216..2ba87db880b 100644 --- a/compiler/rustc_typeck/src/variance/test.rs +++ b/compiler/rustc_typeck/src/variance/test.rs @@ -8,8 +8,7 @@ pub fn test_variance(tcx: TyCtxt<'_>) { for id in tcx.hir().items() { if tcx.has_attr(id.def_id.to_def_id(), sym::rustc_variance) { let variances_of = tcx.variances_of(id.def_id); - struct_span_err!(tcx.sess, tcx.hir().span(id.hir_id()), E0208, "{:?}", variances_of) - .emit(); + struct_span_err!(tcx.sess, tcx.def_span(id.def_id), E0208, "{:?}", variances_of).emit(); } } } diff --git a/src/tools/clippy/clippy_lints/src/same_name_method.rs b/src/tools/clippy/clippy_lints/src/same_name_method.rs index f63925a2f14..c5c174cc8f6 100644 --- a/src/tools/clippy/clippy_lints/src/same_name_method.rs +++ b/src/tools/clippy/clippy_lints/src/same_name_method.rs @@ -51,14 +51,14 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod { let mut map = FxHashMap::::default(); for id in cx.tcx.hir().items() { - if matches!(cx.tcx.hir().def_kind(id.def_id), DefKind::Impl) + if matches!(cx.tcx.def_kind(id.def_id), DefKind::Impl) && let item = cx.tcx.hir().item(id) && let ItemKind::Impl(Impl { - items, - of_trait, - self_ty, - .. - }) = &item.kind + items, + of_trait, + self_ty, + .. + }) = &item.kind && let TyKind::Path(QPath::Resolved(_, Path { res, .. })) = self_ty.kind { if !map.contains_key(res) {