Skip to content

Commit cc25cbd

Browse files
committed
Auto merge of rust-lang#95655 - kckeiks:create-hir-crate-items-query, r=cjgillot
Refactor HIR item-like traversal (part 1) Issue rust-lang#95004 - Create hir_crate_items query which traverses tcx.hir_crate(()).owners to return a hir::ModuleItems - use tcx.hir_crate_items in tcx.hir().items() to return an iterator of hir::ItemId - use tcx.hir_crate_items to introduce a tcx.hir().par_items(impl Fn(hir::ItemId)) to traverse all items in parallel; Signed-off-by: Miguel Guarniz <[email protected]> cc `@cjgillot`
2 parents 5cf2920 + 3363a62 commit cc25cbd

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

clippy_lints/src/same_name_method.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod {
5050
fn check_crate_post(&mut self, cx: &LateContext<'tcx>) {
5151
let mut map = FxHashMap::<Res, ExistingName>::default();
5252

53-
for item in cx.tcx.hir().items() {
53+
for id in cx.tcx.hir().items() {
54+
if !matches!(cx.tcx.hir().def_kind(id.def_id), DefKind::Impl) {
55+
continue;
56+
}
57+
58+
let item = cx.tcx.hir().item(id);
5459
if let ItemKind::Impl(Impl {
5560
items,
5661
of_trait,

tests/ui/same_name_method.stderr

+13-13
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ note: existing `foo` defined here
1111
LL | fn foo() {}
1212
| ^^^^^^^^^^^
1313

14+
error: method's name is the same as an existing method in a trait
15+
--> $DIR/same_name_method.rs:34:13
16+
|
17+
LL | fn clone() {}
18+
| ^^^^^^^^^^^^^
19+
|
20+
note: existing `clone` defined here
21+
--> $DIR/same_name_method.rs:30:18
22+
|
23+
LL | #[derive(Clone)]
24+
| ^^^^^
25+
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
26+
1427
error: method's name is the same as an existing method in a trait
1528
--> $DIR/same_name_method.rs:44:13
1629
|
@@ -47,18 +60,5 @@ note: existing `foo` defined here
4760
LL | impl T1 for S {}
4861
| ^^^^^^^^^^^^^^^^
4962

50-
error: method's name is the same as an existing method in a trait
51-
--> $DIR/same_name_method.rs:34:13
52-
|
53-
LL | fn clone() {}
54-
| ^^^^^^^^^^^^^
55-
|
56-
note: existing `clone` defined here
57-
--> $DIR/same_name_method.rs:30:18
58-
|
59-
LL | #[derive(Clone)]
60-
| ^^^^^
61-
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
62-
6363
error: aborting due to 5 previous errors
6464

0 commit comments

Comments
 (0)