use def_span and def_kind queries instead of calling tcx.hir() methods
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
This commit is contained in:
parent
ef1d112095
commit
3afc5ea201
17 changed files with 31 additions and 104 deletions
|
@ -6,7 +6,7 @@ use rustc_session::cstore::ForeignModule;
|
||||||
crate fn collect(tcx: TyCtxt<'_>) -> Vec<ForeignModule> {
|
crate fn collect(tcx: TyCtxt<'_>) -> Vec<ForeignModule> {
|
||||||
let mut modules = Vec::new();
|
let mut modules = Vec::new();
|
||||||
for id in tcx.hir().items() {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
let item = tcx.hir().item(id);
|
let item = tcx.hir().item(id);
|
||||||
|
|
|
@ -36,7 +36,7 @@ struct Collector<'tcx> {
|
||||||
|
|
||||||
impl<'tcx> Collector<'tcx> {
|
impl<'tcx> Collector<'tcx> {
|
||||||
fn process_item(&mut self, id: rustc_hir::ItemId) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1813,7 +1813,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
FxHashMap::default();
|
FxHashMap::default();
|
||||||
|
|
||||||
for id in tcx.hir().items() {
|
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()) {
|
if let Some(trait_ref) = tcx.impl_trait_ref(id.def_id.to_def_id()) {
|
||||||
let simplified_self_ty = fast_reject::simplify_type(
|
let simplified_self_ty = fast_reject::simplify_type(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
|
|
|
@ -1167,7 +1167,7 @@ struct RootCollector<'a, 'tcx> {
|
||||||
|
|
||||||
impl<'v> RootCollector<'_, 'v> {
|
impl<'v> RootCollector<'_, 'v> {
|
||||||
fn process_item(&mut self, id: hir::ItemId) {
|
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 => {
|
DefKind::Enum | DefKind::Struct | DefKind::Union => {
|
||||||
let item = self.tcx.hir().item(id);
|
let item = self.tcx.hir().item(id);
|
||||||
match item.kind {
|
match item.kind {
|
||||||
|
@ -1228,7 +1228,7 @@ impl<'v> RootCollector<'_, 'v> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_impl_item(&mut self, id: hir::ImplItemId) {
|
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);
|
self.push_if_root(id.def_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,9 +240,9 @@ fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems {
|
||||||
let crate_items = tcx.hir_crate_items(());
|
let crate_items = tcx.hir_crate_items(());
|
||||||
|
|
||||||
for id in crate_items.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);
|
let item = tcx.hir().item(id);
|
||||||
if let hir::ItemKind::Enum(def, ..) = &item.kind {
|
if let hir::ItemKind::Enum(def, ..) = &item.kind {
|
||||||
for variant in def.variants {
|
for variant in def.variants {
|
||||||
|
|
|
@ -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())
|
tcx.def_path_str(id.def_id.to_def_id())
|
||||||
);
|
);
|
||||||
let _indenter = indenter();
|
let _indenter = indenter();
|
||||||
match tcx.hir().def_kind(id.def_id) {
|
match tcx.def_kind(id.def_id) {
|
||||||
DefKind::Static(..) => {
|
DefKind::Static(..) => {
|
||||||
tcx.ensure().typeck(id.def_id);
|
tcx.ensure().typeck(id.def_id);
|
||||||
maybe_check_static_with_link_section(tcx, id.def_id, tcx.def_span(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) {
|
pub(super) fn check_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
|
||||||
let module = tcx.hir_module_items(module_def_id);
|
let module = tcx.hir_module_items(module_def_id);
|
||||||
for id in module.items() {
|
for id in module.items() {
|
||||||
// let item = tcx.hir().item(id);
|
|
||||||
check_item_type(tcx, id);
|
check_item_type(tcx, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for id in tcx.hir().items() {
|
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() {
|
if tcx.visibility(id.def_id).is_public() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
|
||||||
let mut crates_to_lint = vec![];
|
let mut crates_to_lint = vec![];
|
||||||
|
|
||||||
for id in tcx.hir().items() {
|
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);
|
let item = tcx.hir().item(id);
|
||||||
if let hir::ItemKind::ExternCrate(orig_name) = item.kind {
|
if let hir::ItemKind::ExternCrate(orig_name) = item.kind {
|
||||||
crates_to_lint.push(ExternCrateToLint {
|
crates_to_lint.push(ExternCrateToLint {
|
||||||
|
|
|
@ -177,7 +177,7 @@ impl<'tcx> InherentCollect<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_item(&mut self, id: hir::ItemId) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_item(&mut self, id: hir::ItemId) {
|
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) {
|
if !matches!(def_kind, DefKind::Enum | DefKind::Struct | DefKind::Trait | DefKind::Union) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ use rustc_middle::ty::TyCtxt;
|
||||||
|
|
||||||
pub fn check(tcx: TyCtxt<'_>) {
|
pub fn check(tcx: TyCtxt<'_>) {
|
||||||
for id in tcx.hir().items() {
|
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);
|
let item = tcx.hir().item(id);
|
||||||
if let hir::ItemKind::Impl(ref impl_) = item.kind {
|
if let hir::ItemKind::Impl(ref impl_) = item.kind {
|
||||||
check_unsafety_coherence(
|
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
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ fn check_mod_impl_wf(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
|
||||||
let min_specialization = tcx.features().min_specialization;
|
let min_specialization = tcx.features().min_specialization;
|
||||||
let module = tcx.hir_module_items(module_def_id);
|
let module = tcx.hir_module_items(module_def_id);
|
||||||
for id in module.items() {
|
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);
|
let item = tcx.hir().item(id);
|
||||||
if let hir::ItemKind::Impl(ref impl_) = item.kind {
|
if let hir::ItemKind::Impl(ref impl_) = item.kind {
|
||||||
enforce_impl_params_are_constrained(tcx, item.def_id, impl_.items);
|
enforce_impl_params_are_constrained(tcx, item.def_id, impl_.items);
|
||||||
|
|
|
@ -35,7 +35,7 @@ pub fn infer_predicates<'tcx>(
|
||||||
debug!("InferVisitor::visit_item(item={:?})", item_did);
|
debug!("InferVisitor::visit_item(item={:?})", item_did);
|
||||||
|
|
||||||
let mut item_required_predicates = RequiredPredicates::default();
|
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 => {
|
DefKind::Union | DefKind::Enum | DefKind::Struct => {
|
||||||
let adt_def = tcx.adt_def(item_did.to_def_id());
|
let adt_def = tcx.adt_def(item_did.to_def_id());
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ pub fn test_inferred_outlives(tcx: TyCtxt<'_>) {
|
||||||
let inferred_outlives_of = tcx.inferred_outlives_of(id.def_id);
|
let inferred_outlives_of = tcx.inferred_outlives_of(id.def_id);
|
||||||
struct_span_err!(
|
struct_span_err!(
|
||||||
tcx.sess,
|
tcx.sess,
|
||||||
tcx.hir().span(id.hir_id()),
|
tcx.def_span(id.def_id),
|
||||||
E0640,
|
E0640,
|
||||||
"{:?}",
|
"{:?}",
|
||||||
inferred_outlives_of
|
inferred_outlives_of
|
||||||
|
|
|
@ -69,19 +69,19 @@ pub fn add_constraints_from_crate<'a, 'tcx>(
|
||||||
}
|
}
|
||||||
|
|
||||||
for id in crate_items.trait_items() {
|
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());
|
constraint_cx.check_node_helper(id.hir_id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for id in crate_items.impl_items() {
|
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());
|
constraint_cx.check_node_helper(id.hir_id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for id in crate_items.foreign_items() {
|
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());
|
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> {
|
impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
|
||||||
fn check_item(&mut self, id: hir::ItemId) {
|
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 {
|
match def_kind {
|
||||||
DefKind::Struct | DefKind::Union => {
|
DefKind::Struct | DefKind::Union => {
|
||||||
let item = self.tcx().hir().item(id);
|
let item = self.tcx().hir().item(id);
|
||||||
|
|
|
@ -86,19 +86,19 @@ pub fn determine_parameters_to_be_inferred<'a, 'tcx>(
|
||||||
}
|
}
|
||||||
|
|
||||||
for id in crate_items.trait_items() {
|
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());
|
terms_cx.add_inferreds_for_item(id.hir_id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for id in crate_items.impl_items() {
|
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());
|
terms_cx.add_inferreds_for_item(id.hir_id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for id in crate_items.foreign_items() {
|
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());
|
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) {
|
fn check_item(&mut self, id: hir::ItemId) {
|
||||||
debug!("add_inferreds for item {}", self.tcx.hir().node_to_string(id.hir_id()));
|
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 {
|
match def_kind {
|
||||||
DefKind::Struct | DefKind::Union => {
|
DefKind::Struct | DefKind::Union => {
|
||||||
let item = self.tcx.hir().item(id);
|
let item = self.tcx.hir().item(id);
|
||||||
|
|
|
@ -8,8 +8,7 @@ pub fn test_variance(tcx: TyCtxt<'_>) {
|
||||||
for id in tcx.hir().items() {
|
for id in tcx.hir().items() {
|
||||||
if tcx.has_attr(id.def_id.to_def_id(), sym::rustc_variance) {
|
if tcx.has_attr(id.def_id.to_def_id(), sym::rustc_variance) {
|
||||||
let variances_of = tcx.variances_of(id.def_id);
|
let variances_of = tcx.variances_of(id.def_id);
|
||||||
struct_span_err!(tcx.sess, tcx.hir().span(id.hir_id()), E0208, "{:?}", variances_of)
|
struct_span_err!(tcx.sess, tcx.def_span(id.def_id), E0208, "{:?}", variances_of).emit();
|
||||||
.emit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,14 +51,14 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod {
|
||||||
let mut map = FxHashMap::<Res, ExistingName>::default();
|
let mut map = FxHashMap::<Res, ExistingName>::default();
|
||||||
|
|
||||||
for id in cx.tcx.hir().items() {
|
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 item = cx.tcx.hir().item(id)
|
||||||
&& let ItemKind::Impl(Impl {
|
&& let ItemKind::Impl(Impl {
|
||||||
items,
|
items,
|
||||||
of_trait,
|
of_trait,
|
||||||
self_ty,
|
self_ty,
|
||||||
..
|
..
|
||||||
}) = &item.kind
|
}) = &item.kind
|
||||||
&& let TyKind::Path(QPath::Resolved(_, Path { res, .. })) = self_ty.kind
|
&& let TyKind::Path(QPath::Resolved(_, Path { res, .. })) = self_ty.kind
|
||||||
{
|
{
|
||||||
if !map.contains_key(res) {
|
if !map.contains_key(res) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue