Skip to content

Commit 1a64df5

Browse files
committed
refactor
1 parent 43b4a21 commit 1a64df5

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

clippy_lints/src/same_name_method.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_hir::def::{DefKind, Res};
44
use rustc_hir::{Crate, Impl, ItemKind, Node, Path, QPath, TraitRef, TyKind};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_middle::ty::AssocKind;
7-
use rustc_session::{declare_tool_lint, declare_lint_pass};
7+
use rustc_session::{declare_lint_pass, declare_tool_lint};
88
use rustc_span::symbol::SymbolStr;
99
use rustc_span::Span;
1010
use std::collections::{BTreeMap, BTreeSet};
@@ -98,9 +98,12 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod {
9898
cx,
9999
SAME_NAME_METHOD,
100100
*impl_span,
101-
"binding's name is same to an existing binding",
101+
"method's name is same to an existing method in a trait",
102102
|diag| {
103-
diag.span_note(trait_method_span, "existing binding defined here");
103+
diag.span_note(
104+
trait_method_span,
105+
&format!("existing `{}` defined here", method_name),
106+
);
104107
},
105108
);
106109
}
@@ -119,9 +122,8 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod {
119122
check_trait_method(method_name, impl_item_ref.span);
120123
}
121124

122-
let trait_span = item.span;
123125
for method_name in methods_in_trait {
124-
check_trait_method(method_name, trait_span);
126+
check_trait_method(method_name, item.span);
125127
}
126128
},
127129
None => {
@@ -135,11 +137,14 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod {
135137
cx,
136138
SAME_NAME_METHOD,
137139
impl_span,
138-
"binding's name is same to an existing binding",
140+
"method's name is same to an existing method in a trait",
139141
|diag| {
140142
// TODO should we `span_note` on every trait?
141143
// iterate on trait_spans?
142-
diag.span_note(trait_spans[0], "existing binding defined here");
144+
diag.span_note(
145+
trait_spans[0],
146+
&format!("existing `{}` defined here", method_name),
147+
);
143148
},
144149
);
145150
}

tests/ui/same_name_method.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
1-
error: binding's name is same to an existing binding
1+
error: method's name is same to an existing method in a trait
22
--> $DIR/same_name_method.rs:19:13
33
|
44
LL | fn foo() {}
55
| ^^^^^^^^^^^
66
|
77
= note: `-D clippy::same-name-method` implied by `-D warnings`
8-
note: existing binding defined here
8+
note: existing `foo` defined here
99
--> $DIR/same_name_method.rs:23:13
1010
|
1111
LL | fn foo() {}
1212
| ^^^^^^^^^^^
1313

14-
error: binding's name is same to an existing binding
14+
error: method's name is same to an existing method in a trait
1515
--> $DIR/same_name_method.rs:43:13
1616
|
1717
LL | fn foo() {}
1818
| ^^^^^^^^^^^
1919
|
20-
note: existing binding defined here
20+
note: existing `foo` defined here
2121
--> $DIR/same_name_method.rs:47:13
2222
|
2323
LL | fn foo() {}
2424
| ^^^^^^^^^^^
2525

26-
error: binding's name is same to an existing binding
26+
error: method's name is same to an existing method in a trait
2727
--> $DIR/same_name_method.rs:57:13
2828
|
2929
LL | fn foo() {}
3030
| ^^^^^^^^^^^
3131
|
32-
note: existing binding defined here
32+
note: existing `foo` defined here
3333
--> $DIR/same_name_method.rs:60:9
3434
|
3535
LL | impl T1 for S {}
3636
| ^^^^^^^^^^^^^^^^
3737

38-
error: binding's name is same to an existing binding
38+
error: method's name is same to an existing method in a trait
3939
--> $DIR/same_name_method.rs:69:13
4040
|
4141
LL | fn foo() {}
4242
| ^^^^^^^^^^^
4343
|
44-
note: existing binding defined here
44+
note: existing `foo` defined here
4545
--> $DIR/same_name_method.rs:72:9
4646
|
4747
LL | impl T1 for S {}
4848
| ^^^^^^^^^^^^^^^^
4949

50-
error: binding's name is same to an existing binding
50+
error: method's name is same to an existing method in a trait
5151
--> $DIR/same_name_method.rs:33:13
5252
|
5353
LL | fn clone() {}
5454
| ^^^^^^^^^^^^^
5555
|
56-
note: existing binding defined here
56+
note: existing `clone` defined here
5757
--> $DIR/same_name_method.rs:29:18
5858
|
5959
LL | #[derive(Clone)]

0 commit comments

Comments
 (0)