Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f6e5570

Browse files
committedMay 7, 2022
Auto merge of #96531 - kckeiks:remove-item-like-visitor-from-rustc-typeck, r=cjgillot
Remove ItemLikeVisitor impls from rustc_typeck Issue #95004 cc `@cjgillot`
2 parents 4799baa + 91ef3ba commit f6e5570

File tree

23 files changed

+504
-545
lines changed

23 files changed

+504
-545
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_middle/src/hir/map/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,6 @@ impl<'hir> Map<'hir> {
308308
Some(def_kind)
309309
}
310310

311-
pub fn def_kind(self, local_def_id: LocalDefId) -> DefKind {
312-
self.opt_def_kind(local_def_id)
313-
.unwrap_or_else(|| bug!("def_kind: unsupported node: {:?}", local_def_id))
314-
}
315-
316311
pub fn find_parent_node(self, id: HirId) -> Option<HirId> {
317312
if id.local_id == ItemLocalId::from_u32(0) {
318313
Some(self.tcx.hir_owner_parent(id.owner))

‎compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2676,7 +2676,7 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
26762676
// Iterate all local crate items no matter where they are defined.
26772677
let hir = tcx.hir();
26782678
for id in hir.items() {
2679-
if matches!(hir.def_kind(id.def_id), DefKind::Use) {
2679+
if matches!(tcx.def_kind(id.def_id), DefKind::Use) {
26802680
continue;
26812681
}
26822682

‎compiler/rustc_monomorphize/src/collector.rs

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

11651165
impl<'v> RootCollector<'_, 'v> {
11661166
fn process_item(&mut self, id: hir::ItemId) {
1167-
match self.tcx.hir().def_kind(id.def_id) {
1167+
match self.tcx.def_kind(id.def_id) {
11681168
DefKind::Enum | DefKind::Struct | DefKind::Union => {
11691169
let item = self.tcx.hir().item(id);
11701170
match item.kind {
@@ -1225,7 +1225,7 @@ impl<'v> RootCollector<'_, 'v> {
12251225
}
12261226

12271227
fn process_impl_item(&mut self, id: hir::ImplItemId) {
1228-
if matches!(self.tcx.hir().def_kind(id.def_id), DefKind::AssocFn) {
1228+
if matches!(self.tcx.def_kind(id.def_id), DefKind::AssocFn) {
12291229
self.push_if_root(id.def_id);
12301230
}
12311231
}

‎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: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use rustc_trait_selection::traits;
2727
use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _;
2828
use rustc_ty_utils::representability::{self, Representability};
2929

30+
use rustc_hir::def::DefKind;
3031
use std::iter;
3132
use std::ops::ControlFlow;
3233

@@ -711,28 +712,35 @@ fn check_opaque_meets_bounds<'tcx>(
711712
});
712713
}
713714

714-
pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
715+
pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
715716
debug!(
716717
"check_item_type(it.def_id={:?}, it.name={})",
717-
it.def_id,
718-
tcx.def_path_str(it.def_id.to_def_id())
718+
id.def_id,
719+
tcx.def_path_str(id.def_id.to_def_id())
719720
);
720721
let _indenter = indenter();
721-
match it.kind {
722-
// Consts can play a role in type-checking, so they are included here.
723-
hir::ItemKind::Static(..) => {
724-
tcx.ensure().typeck(it.def_id);
725-
maybe_check_static_with_link_section(tcx, it.def_id, it.span);
726-
check_static_inhabited(tcx, it.def_id, it.span);
722+
match tcx.def_kind(id.def_id) {
723+
DefKind::Static(..) => {
724+
tcx.ensure().typeck(id.def_id);
725+
maybe_check_static_with_link_section(tcx, id.def_id, tcx.def_span(id.def_id));
726+
check_static_inhabited(tcx, id.def_id, tcx.def_span(id.def_id));
727727
}
728-
hir::ItemKind::Const(..) => {
729-
tcx.ensure().typeck(it.def_id);
728+
DefKind::Const => {
729+
tcx.ensure().typeck(id.def_id);
730730
}
731-
hir::ItemKind::Enum(ref enum_definition, _) => {
732-
check_enum(tcx, it.span, &enum_definition.variants, it.def_id);
731+
DefKind::Enum => {
732+
let item = tcx.hir().item(id);
733+
let hir::ItemKind::Enum(ref enum_definition, _) = item.kind else {
734+
return;
735+
};
736+
check_enum(tcx, item.span, &enum_definition.variants, item.def_id);
733737
}
734-
hir::ItemKind::Fn(..) => {} // entirely within check_item_body
735-
hir::ItemKind::Impl(ref impl_) => {
738+
DefKind::Fn => {} // entirely within check_item_body
739+
DefKind::Impl => {
740+
let it = tcx.hir().item(id);
741+
let hir::ItemKind::Impl(ref impl_) = it.kind else {
742+
return;
743+
};
736744
debug!("ItemKind::Impl {} with id {:?}", it.ident, it.def_id);
737745
if let Some(impl_trait_ref) = tcx.impl_trait_ref(it.def_id) {
738746
check_impl_items_against_trait(
@@ -745,7 +753,11 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
745753
check_on_unimplemented(tcx, it);
746754
}
747755
}
748-
hir::ItemKind::Trait(_, _, _, _, ref items) => {
756+
DefKind::Trait => {
757+
let it = tcx.hir().item(id);
758+
let hir::ItemKind::Trait(_, _, _, _, ref items) = it.kind else {
759+
return;
760+
};
749761
check_on_unimplemented(tcx, it);
750762

751763
for item in items.iter() {
@@ -771,28 +783,36 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
771783
}
772784
}
773785
}
774-
hir::ItemKind::Struct(..) => {
775-
check_struct(tcx, it.def_id, it.span);
786+
DefKind::Struct => {
787+
check_struct(tcx, id.def_id, tcx.def_span(id.def_id));
776788
}
777-
hir::ItemKind::Union(..) => {
778-
check_union(tcx, it.def_id, it.span);
789+
DefKind::Union => {
790+
check_union(tcx, id.def_id, tcx.def_span(id.def_id));
779791
}
780-
hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => {
792+
DefKind::OpaqueTy => {
793+
let item = tcx.hir().item(id);
794+
let hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) = item.kind else {
795+
return;
796+
};
781797
// HACK(jynelson): trying to infer the type of `impl trait` breaks documenting
782798
// `async-std` (and `pub async fn` in general).
783799
// Since rustdoc doesn't care about the concrete type behind `impl Trait`, just don't look at it!
784800
// See https://github.com/rust-lang/rust/issues/75100
785801
if !tcx.sess.opts.actually_rustdoc {
786-
let substs = InternalSubsts::identity_for_item(tcx, it.def_id.to_def_id());
787-
check_opaque(tcx, it.def_id, substs, it.span, &origin);
802+
let substs = InternalSubsts::identity_for_item(tcx, item.def_id.to_def_id());
803+
check_opaque(tcx, item.def_id, substs, item.span, &origin);
788804
}
789805
}
790-
hir::ItemKind::TyAlias(..) => {
791-
let pty_ty = tcx.type_of(it.def_id);
792-
let generics = tcx.generics_of(it.def_id);
806+
DefKind::TyAlias => {
807+
let pty_ty = tcx.type_of(id.def_id);
808+
let generics = tcx.generics_of(id.def_id);
793809
check_type_params_are_used(tcx, &generics, pty_ty);
794810
}
795-
hir::ItemKind::ForeignMod { abi, items } => {
811+
DefKind::ForeignMod => {
812+
let it = tcx.hir().item(id);
813+
let hir::ItemKind::ForeignMod { abi, items } = it.kind else {
814+
return;
815+
};
796816
check_abi(tcx, it.hir_id(), it.span, abi);
797817

798818
if abi == Abi::RustIntrinsic {
@@ -851,7 +871,7 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
851871
}
852872
}
853873
}
854-
_ => { /* nothing to do */ }
874+
_ => {}
855875
}
856876
}
857877

@@ -1451,7 +1471,10 @@ pub(super) fn check_type_params_are_used<'tcx>(
14511471
}
14521472

14531473
pub(super) fn check_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
1454-
tcx.hir().visit_item_likes_in_module(module_def_id, &mut CheckItemTypesVisitor { tcx });
1474+
let module = tcx.hir_module_items(module_def_id);
1475+
for id in module.items() {
1476+
check_item_type(tcx, id);
1477+
}
14551478
}
14561479

14571480
pub(super) use wfcheck::check_item_well_formed;

‎compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
151151
}
152152
Some(Node::Ctor(hir::VariantData::Tuple(fields, _))) => {
153153
sugg_call = fields.iter().map(|_| "_").collect::<Vec<_>>().join(", ");
154-
match def_id.as_local().map(|def_id| hir.def_kind(def_id)) {
154+
match def_id.as_local().map(|def_id| self.tcx.def_kind(def_id)) {
155155
Some(DefKind::Ctor(hir::def::CtorOf::Variant, _)) => {
156156
msg = "instantiate this tuple variant";
157157
}

‎compiler/rustc_typeck/src/check/mod.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ use rustc_hir as hir;
111111
use rustc_hir::def::Res;
112112
use rustc_hir::def_id::{DefId, LocalDefId};
113113
use rustc_hir::intravisit::Visitor;
114-
use rustc_hir::itemlikevisit::ItemLikeVisitor;
115114
use rustc_hir::{HirIdMap, ImplicitSelfKind, Node};
116115
use rustc_index::bit_set::BitSet;
117116
use rustc_index::vec::Idx;
@@ -933,19 +932,6 @@ impl<'a, 'tcx> MaybeInProgressTables<'a, 'tcx> {
933932
}
934933
}
935934

936-
struct CheckItemTypesVisitor<'tcx> {
937-
tcx: TyCtxt<'tcx>,
938-
}
939-
940-
impl<'tcx> ItemLikeVisitor<'tcx> for CheckItemTypesVisitor<'tcx> {
941-
fn visit_item(&mut self, i: &'tcx hir::Item<'tcx>) {
942-
check_item_type(self.tcx, i);
943-
}
944-
fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem<'tcx>) {}
945-
fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem<'tcx>) {}
946-
fn visit_foreign_item(&mut self, _: &'tcx hir::ForeignItem<'tcx>) {}
947-
}
948-
949935
fn typeck_item_bodies(tcx: TyCtxt<'_>, (): ()) {
950936
tcx.hir().par_body_owners(|body_owner_def_id| tcx.ensure().typeck(body_owner_def_id));
951937
}

‎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: 74 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
1010
use rustc_errors::struct_span_err;
1111
use rustc_hir as hir;
12+
use rustc_hir::def::DefKind;
1213
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
13-
use rustc_hir::itemlikevisit::ItemLikeVisitor;
1414
use rustc_middle::ty::fast_reject::{simplify_type, SimplifiedType, TreatParams};
1515
use rustc_middle::ty::{self, CrateInherentImpls, Ty, TyCtxt};
1616
use rustc_span::symbol::sym;
@@ -19,7 +19,9 @@ use rustc_span::Span;
1919
/// On-demand query: yields a map containing all types mapped to their inherent impls.
2020
pub fn crate_inherent_impls(tcx: TyCtxt<'_>, (): ()) -> CrateInherentImpls {
2121
let mut collect = InherentCollect { tcx, impls_map: Default::default() };
22-
tcx.hir().visit_all_item_likes(&mut collect);
22+
for id in tcx.hir().items() {
23+
collect.check_item(id);
24+
}
2325
collect.impls_map
2426
}
2527

@@ -46,79 +48,6 @@ struct InherentCollect<'tcx> {
4648
impls_map: CrateInherentImpls,
4749
}
4850

49-
impl<'tcx> ItemLikeVisitor<'_> for InherentCollect<'tcx> {
50-
fn visit_item(&mut self, item: &hir::Item<'_>) {
51-
let hir::ItemKind::Impl(hir::Impl { of_trait: None, self_ty: ty, ref items, .. }) = item.kind else {
52-
return;
53-
};
54-
55-
let self_ty = self.tcx.type_of(item.def_id);
56-
match *self_ty.kind() {
57-
ty::Adt(def, _) => {
58-
self.check_def_id(item, self_ty, def.did());
59-
}
60-
ty::Foreign(did) => {
61-
self.check_def_id(item, self_ty, did);
62-
}
63-
ty::Dynamic(data, ..) if data.principal_def_id().is_some() => {
64-
self.check_def_id(item, self_ty, data.principal_def_id().unwrap());
65-
}
66-
ty::Dynamic(..) => {
67-
struct_span_err!(
68-
self.tcx.sess,
69-
ty.span,
70-
E0785,
71-
"cannot define inherent `impl` for a dyn auto trait"
72-
)
73-
.span_label(ty.span, "impl requires at least one non-auto trait")
74-
.note("define and implement a new trait or type instead")
75-
.emit();
76-
}
77-
ty::Bool
78-
| ty::Char
79-
| ty::Int(_)
80-
| ty::Uint(_)
81-
| ty::Float(_)
82-
| ty::Str
83-
| ty::Array(..)
84-
| ty::Slice(_)
85-
| ty::RawPtr(_)
86-
| ty::Ref(..)
87-
| ty::Never
88-
| ty::Tuple(..) => self.check_primitive_impl(item.def_id, self_ty, items, ty.span),
89-
ty::FnPtr(_) | ty::Projection(..) | ty::Opaque(..) | ty::Param(_) => {
90-
let mut err = struct_span_err!(
91-
self.tcx.sess,
92-
ty.span,
93-
E0118,
94-
"no nominal type found for inherent implementation"
95-
);
96-
97-
err.span_label(ty.span, "impl requires a nominal type")
98-
.note("either implement a trait on it or create a newtype to wrap it instead");
99-
100-
err.emit();
101-
}
102-
ty::FnDef(..)
103-
| ty::Closure(..)
104-
| ty::Generator(..)
105-
| ty::GeneratorWitness(..)
106-
| ty::Bound(..)
107-
| ty::Placeholder(_)
108-
| ty::Infer(_) => {
109-
bug!("unexpected impl self type of impl: {:?} {:?}", item.def_id, self_ty);
110-
}
111-
ty::Error(_) => {}
112-
}
113-
}
114-
115-
fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) {}
116-
117-
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) {}
118-
119-
fn visit_foreign_item(&mut self, _foreign_item: &hir::ForeignItem<'_>) {}
120-
}
121-
12251
const INTO_CORE: &str = "consider moving this inherent impl into `core` if possible";
12352
const INTO_DEFINING_CRATE: &str =
12453
"consider moving this inherent impl into the crate defining the type if possible";
@@ -246,4 +175,74 @@ impl<'tcx> InherentCollect<'tcx> {
246175
bug!("unexpected primitive type: {:?}", ty);
247176
}
248177
}
178+
179+
fn check_item(&mut self, id: hir::ItemId) {
180+
if !matches!(self.tcx.def_kind(id.def_id), DefKind::Impl) {
181+
return;
182+
}
183+
184+
let item = self.tcx.hir().item(id);
185+
let hir::ItemKind::Impl(hir::Impl { of_trait: None, self_ty: ty, ref items, .. }) = item.kind else {
186+
return;
187+
};
188+
189+
let self_ty = self.tcx.type_of(item.def_id);
190+
match *self_ty.kind() {
191+
ty::Adt(def, _) => {
192+
self.check_def_id(item, self_ty, def.did());
193+
}
194+
ty::Foreign(did) => {
195+
self.check_def_id(item, self_ty, did);
196+
}
197+
ty::Dynamic(data, ..) if data.principal_def_id().is_some() => {
198+
self.check_def_id(item, self_ty, data.principal_def_id().unwrap());
199+
}
200+
ty::Dynamic(..) => {
201+
struct_span_err!(
202+
self.tcx.sess,
203+
ty.span,
204+
E0785,
205+
"cannot define inherent `impl` for a dyn auto trait"
206+
)
207+
.span_label(ty.span, "impl requires at least one non-auto trait")
208+
.note("define and implement a new trait or type instead")
209+
.emit();
210+
}
211+
ty::Bool
212+
| ty::Char
213+
| ty::Int(_)
214+
| ty::Uint(_)
215+
| ty::Float(_)
216+
| ty::Str
217+
| ty::Array(..)
218+
| ty::Slice(_)
219+
| ty::RawPtr(_)
220+
| ty::Ref(..)
221+
| ty::Never
222+
| ty::Tuple(..) => self.check_primitive_impl(item.def_id, self_ty, items, ty.span),
223+
ty::FnPtr(_) | ty::Projection(..) | ty::Opaque(..) | ty::Param(_) => {
224+
let mut err = struct_span_err!(
225+
self.tcx.sess,
226+
ty.span,
227+
E0118,
228+
"no nominal type found for inherent implementation"
229+
);
230+
231+
err.span_label(ty.span, "impl requires a nominal type")
232+
.note("either implement a trait on it or create a newtype to wrap it instead");
233+
234+
err.emit();
235+
}
236+
ty::FnDef(..)
237+
| ty::Closure(..)
238+
| ty::Generator(..)
239+
| ty::GeneratorWitness(..)
240+
| ty::Bound(..)
241+
| ty::Placeholder(_)
242+
| ty::Infer(_) => {
243+
bug!("unexpected impl self type of impl: {:?} {:?}", item.def_id, self_ty);
244+
}
245+
ty::Error(_) => {}
246+
}
247+
}
249248
}

‎compiler/rustc_typeck/src/coherence/inherent_impls_overlap.rs

Lines changed: 163 additions & 176 deletions
Large diffs are not rendered by default.

‎compiler/rustc_typeck/src/coherence/unsafety.rs

Lines changed: 66 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -3,101 +3,83 @@
33
44
use rustc_errors::struct_span_err;
55
use rustc_hir as hir;
6-
use rustc_hir::itemlikevisit::ItemLikeVisitor;
6+
use rustc_hir::def::DefKind;
77
use rustc_hir::Unsafety;
88
use rustc_middle::ty::TyCtxt;
99

1010
pub fn check(tcx: TyCtxt<'_>) {
11-
let mut unsafety = UnsafetyChecker { tcx };
12-
tcx.hir().visit_all_item_likes(&mut unsafety);
11+
for id in tcx.hir().items() {
12+
if matches!(tcx.def_kind(id.def_id), DefKind::Impl) {
13+
let item = tcx.hir().item(id);
14+
if let hir::ItemKind::Impl(ref impl_) = item.kind {
15+
check_unsafety_coherence(
16+
tcx,
17+
item,
18+
Some(&impl_.generics),
19+
impl_.unsafety,
20+
impl_.polarity,
21+
);
22+
}
23+
}
24+
}
1325
}
1426

15-
struct UnsafetyChecker<'tcx> {
27+
fn check_unsafety_coherence<'tcx>(
1628
tcx: TyCtxt<'tcx>,
17-
}
18-
19-
impl<'tcx> UnsafetyChecker<'tcx> {
20-
fn check_unsafety_coherence(
21-
&mut self,
22-
item: &hir::Item<'_>,
23-
impl_generics: Option<&hir::Generics<'_>>,
24-
unsafety: hir::Unsafety,
25-
polarity: hir::ImplPolarity,
26-
) {
27-
if let Some(trait_ref) = self.tcx.impl_trait_ref(item.def_id) {
28-
let trait_def = self.tcx.trait_def(trait_ref.def_id);
29-
let unsafe_attr = impl_generics.and_then(|generics| {
30-
generics.params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle")
31-
});
32-
match (trait_def.unsafety, unsafe_attr, unsafety, polarity) {
33-
(Unsafety::Normal, None, Unsafety::Unsafe, hir::ImplPolarity::Positive) => {
34-
struct_span_err!(
35-
self.tcx.sess,
36-
item.span,
37-
E0199,
38-
"implementing the trait `{}` is not unsafe",
39-
trait_ref.print_only_trait_path()
40-
)
41-
.emit();
42-
}
43-
44-
(Unsafety::Unsafe, _, Unsafety::Normal, hir::ImplPolarity::Positive) => {
45-
struct_span_err!(
46-
self.tcx.sess,
47-
item.span,
48-
E0200,
49-
"the trait `{}` requires an `unsafe impl` declaration",
50-
trait_ref.print_only_trait_path()
51-
)
52-
.emit();
53-
}
29+
item: &hir::Item<'_>,
30+
impl_generics: Option<&hir::Generics<'_>>,
31+
unsafety: hir::Unsafety,
32+
polarity: hir::ImplPolarity,
33+
) {
34+
if let Some(trait_ref) = tcx.impl_trait_ref(item.def_id) {
35+
let trait_def = tcx.trait_def(trait_ref.def_id);
36+
let unsafe_attr = impl_generics.and_then(|generics| {
37+
generics.params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle")
38+
});
39+
match (trait_def.unsafety, unsafe_attr, unsafety, polarity) {
40+
(Unsafety::Normal, None, Unsafety::Unsafe, hir::ImplPolarity::Positive) => {
41+
struct_span_err!(
42+
tcx.sess,
43+
item.span,
44+
E0199,
45+
"implementing the trait `{}` is not unsafe",
46+
trait_ref.print_only_trait_path()
47+
)
48+
.emit();
49+
}
5450

55-
(
56-
Unsafety::Normal,
57-
Some(attr_name),
58-
Unsafety::Normal,
59-
hir::ImplPolarity::Positive,
60-
) => {
61-
struct_span_err!(
62-
self.tcx.sess,
63-
item.span,
64-
E0569,
65-
"requires an `unsafe impl` declaration due to `#[{}]` attribute",
66-
attr_name
67-
)
68-
.emit();
69-
}
51+
(Unsafety::Unsafe, _, Unsafety::Normal, hir::ImplPolarity::Positive) => {
52+
struct_span_err!(
53+
tcx.sess,
54+
item.span,
55+
E0200,
56+
"the trait `{}` requires an `unsafe impl` declaration",
57+
trait_ref.print_only_trait_path()
58+
)
59+
.emit();
60+
}
7061

71-
(_, _, Unsafety::Unsafe, hir::ImplPolarity::Negative(_)) => {
72-
// Reported in AST validation
73-
self.tcx.sess.delay_span_bug(item.span, "unsafe negative impl");
74-
}
75-
(_, _, Unsafety::Normal, hir::ImplPolarity::Negative(_))
76-
| (Unsafety::Unsafe, _, Unsafety::Unsafe, hir::ImplPolarity::Positive)
77-
| (Unsafety::Normal, Some(_), Unsafety::Unsafe, hir::ImplPolarity::Positive)
78-
| (Unsafety::Normal, None, Unsafety::Normal, _) => {
79-
// OK
80-
}
62+
(Unsafety::Normal, Some(attr_name), Unsafety::Normal, hir::ImplPolarity::Positive) => {
63+
struct_span_err!(
64+
tcx.sess,
65+
item.span,
66+
E0569,
67+
"requires an `unsafe impl` declaration due to `#[{}]` attribute",
68+
attr_name
69+
)
70+
.emit();
8171
}
82-
}
83-
}
84-
}
8572

86-
impl<'tcx> ItemLikeVisitor<'_> for UnsafetyChecker<'tcx> {
87-
fn visit_item(&mut self, item: &hir::Item<'_>) {
88-
if let hir::ItemKind::Impl(ref impl_) = item.kind {
89-
self.check_unsafety_coherence(
90-
item,
91-
Some(&impl_.generics),
92-
impl_.unsafety,
93-
impl_.polarity,
94-
);
73+
(_, _, Unsafety::Unsafe, hir::ImplPolarity::Negative(_)) => {
74+
// Reported in AST validation
75+
tcx.sess.delay_span_bug(item.span, "unsafe negative impl");
76+
}
77+
(_, _, Unsafety::Normal, hir::ImplPolarity::Negative(_))
78+
| (Unsafety::Unsafe, _, Unsafety::Unsafe, hir::ImplPolarity::Positive)
79+
| (Unsafety::Normal, Some(_), Unsafety::Unsafe, hir::ImplPolarity::Positive)
80+
| (Unsafety::Normal, None, Unsafety::Normal, _) => {
81+
// OK
82+
}
9583
}
9684
}
97-
98-
fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) {}
99-
100-
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) {}
101-
102-
fn visit_foreign_item(&mut self, _foreign_item: &hir::ForeignItem<'_>) {}
10385
}

‎compiler/rustc_typeck/src/impl_wf_check.rs

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use min_specialization::check_min_specialization;
1414
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1515
use rustc_errors::struct_span_err;
1616
use rustc_hir as hir;
17+
use rustc_hir::def::DefKind;
1718
use rustc_hir::def_id::LocalDefId;
18-
use rustc_hir::itemlikevisit::ItemLikeVisitor;
1919
use rustc_middle::ty::query::Providers;
2020
use rustc_middle::ty::{self, TyCtxt, TypeFoldable};
2121
use rustc_span::Span;
@@ -63,35 +63,23 @@ pub fn impl_wf_check(tcx: TyCtxt<'_>) {
6363

6464
fn check_mod_impl_wf(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
6565
let min_specialization = tcx.features().min_specialization;
66-
tcx.hir()
67-
.visit_item_likes_in_module(module_def_id, &mut ImplWfCheck { tcx, min_specialization });
68-
}
69-
70-
pub fn provide(providers: &mut Providers) {
71-
*providers = Providers { check_mod_impl_wf, ..*providers };
72-
}
73-
74-
struct ImplWfCheck<'tcx> {
75-
tcx: TyCtxt<'tcx>,
76-
min_specialization: bool,
77-
}
78-
79-
impl<'tcx> ItemLikeVisitor<'tcx> for ImplWfCheck<'tcx> {
80-
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
81-
if let hir::ItemKind::Impl(ref impl_) = item.kind {
82-
enforce_impl_params_are_constrained(self.tcx, item.def_id, impl_.items);
83-
enforce_impl_items_are_distinct(self.tcx, impl_.items);
84-
if self.min_specialization {
85-
check_min_specialization(self.tcx, item.def_id.to_def_id(), item.span);
66+
let module = tcx.hir_module_items(module_def_id);
67+
for id in module.items() {
68+
if matches!(tcx.def_kind(id.def_id), DefKind::Impl) {
69+
let item = tcx.hir().item(id);
70+
if let hir::ItemKind::Impl(ref impl_) = item.kind {
71+
enforce_impl_params_are_constrained(tcx, item.def_id, impl_.items);
72+
enforce_impl_items_are_distinct(tcx, impl_.items);
73+
if min_specialization {
74+
check_min_specialization(tcx, item.def_id.to_def_id(), item.span);
75+
}
8676
}
8777
}
8878
}
79+
}
8980

90-
fn visit_trait_item(&mut self, _trait_item: &'tcx hir::TraitItem<'tcx>) {}
91-
92-
fn visit_impl_item(&mut self, _impl_item: &'tcx hir::ImplItem<'tcx>) {}
93-
94-
fn visit_foreign_item(&mut self, _foreign_item: &'tcx hir::ForeignItem<'tcx>) {}
81+
pub fn provide(providers: &mut Providers) {
82+
*providers = Providers { check_mod_impl_wf, ..*providers };
9583
}
9684

9785
fn enforce_impl_params_are_constrained(

‎compiler/rustc_typeck/src/outlives/implicit_infer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn infer_predicates<'tcx>(
3535
debug!("InferVisitor::visit_item(item={:?})", item_did);
3636

3737
let mut item_required_predicates = RequiredPredicates::default();
38-
match tcx.hir().def_kind(item_did) {
38+
match tcx.def_kind(item_did) {
3939
DefKind::Union | DefKind::Enum | DefKind::Struct => {
4040
let adt_def = tcx.adt_def(item_did.to_def_id());
4141

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
use rustc_errors::struct_span_err;
2-
use rustc_hir as hir;
3-
use rustc_hir::itemlikevisit::ItemLikeVisitor;
42
use rustc_middle::ty::TyCtxt;
53
use rustc_span::symbol::sym;
64

75
pub fn test_inferred_outlives(tcx: TyCtxt<'_>) {
8-
tcx.hir().visit_all_item_likes(&mut OutlivesTest { tcx });
9-
}
10-
11-
struct OutlivesTest<'tcx> {
12-
tcx: TyCtxt<'tcx>,
13-
}
14-
15-
impl<'tcx> ItemLikeVisitor<'tcx> for OutlivesTest<'tcx> {
16-
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
6+
for id in tcx.hir().items() {
177
// For unit testing: check for a special "rustc_outlives"
188
// attribute and report an error with various results if found.
19-
if self.tcx.has_attr(item.def_id.to_def_id(), sym::rustc_outlives) {
20-
let inferred_outlives_of = self.tcx.inferred_outlives_of(item.def_id);
21-
struct_span_err!(self.tcx.sess, item.span, E0640, "{:?}", inferred_outlives_of).emit();
9+
if tcx.has_attr(id.def_id.to_def_id(), sym::rustc_outlives) {
10+
let inferred_outlives_of = tcx.inferred_outlives_of(id.def_id);
11+
struct_span_err!(
12+
tcx.sess,
13+
tcx.def_span(id.def_id),
14+
E0640,
15+
"{:?}",
16+
inferred_outlives_of
17+
)
18+
.emit();
2219
}
2320
}
24-
25-
fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem<'tcx>) {}
26-
fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem<'tcx>) {}
27-
fn visit_foreign_item(&mut self, _: &'tcx hir::ForeignItem<'tcx>) {}
2821
}

‎compiler/rustc_typeck/src/variance/constraints.rs

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use hir::def_id::{DefId, LocalDefId};
77
use rustc_hir as hir;
8-
use rustc_hir::itemlikevisit::ItemLikeVisitor;
8+
use rustc_hir::def::DefKind;
99
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
1010
use rustc_middle::ty::{self, Ty, TyCtxt};
1111

@@ -62,61 +62,71 @@ pub fn add_constraints_from_crate<'a, 'tcx>(
6262
constraints: Vec::new(),
6363
};
6464

65-
tcx.hir().visit_all_item_likes(&mut constraint_cx);
65+
let crate_items = tcx.hir_crate_items(());
66+
67+
for id in crate_items.items() {
68+
constraint_cx.check_item(id);
69+
}
70+
71+
for id in crate_items.trait_items() {
72+
if let DefKind::AssocFn = tcx.def_kind(id.def_id) {
73+
constraint_cx.check_node_helper(id.hir_id());
74+
}
75+
}
76+
77+
for id in crate_items.impl_items() {
78+
if let DefKind::AssocFn = tcx.def_kind(id.def_id) {
79+
constraint_cx.check_node_helper(id.hir_id());
80+
}
81+
}
82+
83+
for id in crate_items.foreign_items() {
84+
if let DefKind::Fn = tcx.def_kind(id.def_id) {
85+
constraint_cx.check_node_helper(id.hir_id());
86+
}
87+
}
6688

6789
constraint_cx
6890
}
6991

70-
impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> {
71-
fn visit_item(&mut self, item: &hir::Item<'_>) {
72-
match item.kind {
73-
hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => {
74-
self.visit_node_helper(item.hir_id());
75-
76-
if let hir::VariantData::Tuple(..) = *struct_def {
77-
self.visit_node_helper(struct_def.ctor_hir_id().unwrap());
92+
impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
93+
fn check_item(&mut self, id: hir::ItemId) {
94+
let def_kind = self.tcx().def_kind(id.def_id);
95+
match def_kind {
96+
DefKind::Struct | DefKind::Union => {
97+
let item = self.tcx().hir().item(id);
98+
99+
if let hir::ItemKind::Struct(ref struct_def, _)
100+
| hir::ItemKind::Union(ref struct_def, _) = item.kind
101+
{
102+
self.check_node_helper(item.hir_id());
103+
104+
if let hir::VariantData::Tuple(..) = *struct_def {
105+
self.check_node_helper(struct_def.ctor_hir_id().unwrap());
106+
}
78107
}
79108
}
109+
DefKind::Enum => {
110+
let item = self.tcx().hir().item(id);
80111

81-
hir::ItemKind::Enum(ref enum_def, _) => {
82-
self.visit_node_helper(item.hir_id());
112+
if let hir::ItemKind::Enum(ref enum_def, _) = item.kind {
113+
self.check_node_helper(item.hir_id());
83114

84-
for variant in enum_def.variants {
85-
if let hir::VariantData::Tuple(..) = variant.data {
86-
self.visit_node_helper(variant.data.ctor_hir_id().unwrap());
115+
for variant in enum_def.variants {
116+
if let hir::VariantData::Tuple(..) = variant.data {
117+
self.check_node_helper(variant.data.ctor_hir_id().unwrap());
118+
}
87119
}
88120
}
89121
}
90-
91-
hir::ItemKind::Fn(..) => {
92-
self.visit_node_helper(item.hir_id());
122+
DefKind::Fn => {
123+
self.check_node_helper(id.hir_id());
93124
}
94-
95125
_ => {}
96126
}
97127
}
98128

99-
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) {
100-
if let hir::TraitItemKind::Fn(..) = trait_item.kind {
101-
self.visit_node_helper(trait_item.hir_id());
102-
}
103-
}
104-
105-
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) {
106-
if let hir::ImplItemKind::Fn(..) = impl_item.kind {
107-
self.visit_node_helper(impl_item.hir_id());
108-
}
109-
}
110-
111-
fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) {
112-
if let hir::ForeignItemKind::Fn(..) = foreign_item.kind {
113-
self.visit_node_helper(foreign_item.hir_id());
114-
}
115-
}
116-
}
117-
118-
impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
119-
fn visit_node_helper(&mut self, id: hir::HirId) {
129+
fn check_node_helper(&mut self, id: hir::HirId) {
120130
let tcx = self.terms_cx.tcx;
121131
let def_id = tcx.hir().local_def_id(id);
122132
self.build_constraints_for_item(def_id);

‎compiler/rustc_typeck/src/variance/terms.rs

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
use rustc_arena::DroplessArena;
1313
use rustc_hir as hir;
14-
use rustc_hir::itemlikevisit::ItemLikeVisitor;
14+
use rustc_hir::def::DefKind;
1515
use rustc_hir::HirIdMap;
1616
use rustc_middle::ty::{self, TyCtxt};
1717
use std::fmt;
@@ -79,7 +79,29 @@ pub fn determine_parameters_to_be_inferred<'a, 'tcx>(
7979
//
8080
// - https://rustc-dev-guide.rust-lang.org/query.html
8181
// - https://rustc-dev-guide.rust-lang.org/variance.html
82-
tcx.hir().visit_all_item_likes(&mut terms_cx);
82+
let crate_items = tcx.hir_crate_items(());
83+
84+
for id in crate_items.items() {
85+
terms_cx.check_item(id);
86+
}
87+
88+
for id in crate_items.trait_items() {
89+
if let DefKind::AssocFn = tcx.def_kind(id.def_id) {
90+
terms_cx.add_inferreds_for_item(id.hir_id());
91+
}
92+
}
93+
94+
for id in crate_items.impl_items() {
95+
if let DefKind::AssocFn = tcx.def_kind(id.def_id) {
96+
terms_cx.add_inferreds_for_item(id.hir_id());
97+
}
98+
}
99+
100+
for id in crate_items.foreign_items() {
101+
if let DefKind::Fn = tcx.def_kind(id.def_id) {
102+
terms_cx.add_inferreds_for_item(id.hir_id());
103+
}
104+
}
83105

84106
terms_cx
85107
}
@@ -124,54 +146,42 @@ impl<'a, 'tcx> TermsContext<'a, 'tcx> {
124146
(start..(start + count)).map(|i| &*arena.alloc(InferredTerm(InferredIndex(i)))),
125147
);
126148
}
127-
}
128149

129-
impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> {
130-
fn visit_item(&mut self, item: &hir::Item<'_>) {
131-
debug!("add_inferreds for item {}", self.tcx.hir().node_to_string(item.hir_id()));
150+
fn check_item(&mut self, id: hir::ItemId) {
151+
debug!("add_inferreds for item {}", self.tcx.hir().node_to_string(id.hir_id()));
152+
153+
let def_kind = self.tcx.def_kind(id.def_id);
154+
match def_kind {
155+
DefKind::Struct | DefKind::Union => {
156+
let item = self.tcx.hir().item(id);
132157

133-
match item.kind {
134-
hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => {
135-
self.add_inferreds_for_item(item.hir_id());
158+
if let hir::ItemKind::Struct(ref struct_def, _)
159+
| hir::ItemKind::Union(ref struct_def, _) = item.kind
160+
{
161+
self.add_inferreds_for_item(item.hir_id());
136162

137-
if let hir::VariantData::Tuple(..) = *struct_def {
138-
self.add_inferreds_for_item(struct_def.ctor_hir_id().unwrap());
163+
if let hir::VariantData::Tuple(..) = *struct_def {
164+
self.add_inferreds_for_item(struct_def.ctor_hir_id().unwrap());
165+
}
139166
}
140167
}
168+
DefKind::Enum => {
169+
let item = self.tcx.hir().item(id);
141170

142-
hir::ItemKind::Enum(ref enum_def, _) => {
143-
self.add_inferreds_for_item(item.hir_id());
171+
if let hir::ItemKind::Enum(ref enum_def, _) = item.kind {
172+
self.add_inferreds_for_item(item.hir_id());
144173

145-
for variant in enum_def.variants {
146-
if let hir::VariantData::Tuple(..) = variant.data {
147-
self.add_inferreds_for_item(variant.data.ctor_hir_id().unwrap());
174+
for variant in enum_def.variants {
175+
if let hir::VariantData::Tuple(..) = variant.data {
176+
self.add_inferreds_for_item(variant.data.ctor_hir_id().unwrap());
177+
}
148178
}
149179
}
150180
}
151-
152-
hir::ItemKind::Fn(..) => {
153-
self.add_inferreds_for_item(item.hir_id());
181+
DefKind::Fn => {
182+
self.add_inferreds_for_item(id.hir_id());
154183
}
155-
156184
_ => {}
157185
}
158186
}
159-
160-
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) {
161-
if let hir::TraitItemKind::Fn(..) = trait_item.kind {
162-
self.add_inferreds_for_item(trait_item.hir_id());
163-
}
164-
}
165-
166-
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) {
167-
if let hir::ImplItemKind::Fn(..) = impl_item.kind {
168-
self.add_inferreds_for_item(impl_item.hir_id());
169-
}
170-
}
171-
172-
fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) {
173-
if let hir::ForeignItemKind::Fn(..) = foreign_item.kind {
174-
self.add_inferreds_for_item(foreign_item.hir_id());
175-
}
176-
}
177187
}
Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,14 @@
11
use rustc_errors::struct_span_err;
2-
use rustc_hir as hir;
3-
use rustc_hir::itemlikevisit::ItemLikeVisitor;
42
use rustc_middle::ty::TyCtxt;
53
use rustc_span::symbol::sym;
64

75
pub fn test_variance(tcx: TyCtxt<'_>) {
8-
tcx.hir().visit_all_item_likes(&mut VarianceTest { tcx });
9-
}
10-
11-
struct VarianceTest<'tcx> {
12-
tcx: TyCtxt<'tcx>,
13-
}
14-
15-
impl<'tcx> ItemLikeVisitor<'tcx> for VarianceTest<'tcx> {
16-
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
17-
// For unit testing: check for a special "rustc_variance"
18-
// attribute and report an error with various results if found.
19-
if self.tcx.has_attr(item.def_id.to_def_id(), sym::rustc_variance) {
20-
let variances_of = self.tcx.variances_of(item.def_id);
21-
struct_span_err!(self.tcx.sess, item.span, E0208, "{:?}", variances_of).emit();
6+
// For unit testing: check for a special "rustc_variance"
7+
// attribute and report an error with various results if found.
8+
for id in tcx.hir().items() {
9+
if tcx.has_attr(id.def_id.to_def_id(), sym::rustc_variance) {
10+
let variances_of = tcx.variances_of(id.def_id);
11+
struct_span_err!(tcx.sess, tcx.def_span(id.def_id), E0208, "{:?}", variances_of).emit();
2212
}
2313
}
24-
25-
fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem<'tcx>) {}
26-
fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem<'tcx>) {}
27-
fn visit_foreign_item(&mut self, _: &'tcx hir::ForeignItem<'tcx>) {}
2814
}

‎src/test/ui/dep-graph/dep-graph-trait-impl-two-traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ mod x {
2929
mod y {
3030
use {Foo, Bar};
3131

32-
#[rustc_then_this_would_need(typeck)] //~ ERROR no path
32+
#[rustc_then_this_would_need(typeck)] //~ ERROR OK
3333
pub fn call_bar() {
3434
char::bar('a');
3535
}

‎src/test/ui/dep-graph/dep-graph-trait-impl-two-traits.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: no path from `x::<impl Foo for char>` to `typeck`
1+
error: OK
22
--> $DIR/dep-graph-trait-impl-two-traits.rs:32:5
33
|
44
LL | #[rustc_then_this_would_need(typeck)]

‎src/tools/clippy/clippy_lints/src/same_name_method.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod {
5151
let mut map = FxHashMap::<Res, ExistingName>::default();
5252

5353
for id in cx.tcx.hir().items() {
54-
if matches!(cx.tcx.hir().def_kind(id.def_id), DefKind::Impl)
54+
if matches!(cx.tcx.def_kind(id.def_id), DefKind::Impl)
5555
&& let item = cx.tcx.hir().item(id)
5656
&& let ItemKind::Impl(Impl {
57-
items,
58-
of_trait,
59-
self_ty,
60-
..
61-
}) = &item.kind
57+
items,
58+
of_trait,
59+
self_ty,
60+
..
61+
}) = &item.kind
6262
&& let TyKind::Path(QPath::Resolved(_, Path { res, .. })) = self_ty.kind
6363
{
6464
if !map.contains_key(res) {

0 commit comments

Comments
 (0)
Please sign in to comment.