Skip to content

Commit 43b4a21

Browse files
committed
refactor test
1 parent d8391e4 commit 43b4a21

File tree

2 files changed

+105
-93
lines changed

2 files changed

+105
-93
lines changed

tests/ui/same_name_method.rs

Lines changed: 75 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,109 @@
1-
#![allow(dead_code)]
1+
#![allow(dead_code, non_camel_case_types)]
22

3-
mod test_simple_case {
4-
trait T1 {
5-
fn foo() {}
6-
}
3+
trait T1 {
4+
fn foo() {}
5+
}
76

8-
struct S;
7+
trait T2 {
8+
fn foo() {}
9+
}
910

10-
impl S {
11-
fn foo() {}
12-
}
11+
mod should_lint {
1312

14-
impl T1 for S {
15-
fn foo() {}
16-
}
17-
}
13+
mod test_basic_case {
14+
use crate::T1;
1815

19-
mod test_derive {
20-
#[derive(Clone)]
21-
struct S;
16+
struct S;
2217

23-
impl S {
24-
fn clone() {}
25-
}
26-
}
18+
impl S {
19+
fn foo() {}
20+
}
2721

28-
mod with_generic {
29-
trait T1 {
30-
fn foo();
22+
impl T1 for S {
23+
fn foo() {}
24+
}
3125
}
3226

33-
struct S<U>(U);
27+
mod test_derive {
3428

35-
impl<U> S<U> {
36-
fn foo() {}
37-
}
29+
#[derive(Clone)]
30+
struct S;
3831

39-
impl<U: Copy> T1 for S<U> {
40-
fn foo() {}
32+
impl S {
33+
fn clone() {}
34+
}
4135
}
42-
}
4336

44-
mod default_method {
45-
trait T1 {
46-
fn foo() {}
47-
}
37+
mod with_generic {
38+
use crate::T1;
39+
40+
struct S<U>(U);
4841

49-
struct S;
42+
impl<U> S<U> {
43+
fn foo() {}
44+
}
5045

51-
impl S {
52-
fn foo() {}
46+
impl<U: Copy> T1 for S<U> {
47+
fn foo() {}
48+
}
5349
}
5450

55-
impl T1 for S {}
56-
}
51+
mod default_method {
52+
use crate::T1;
5753

58-
mod mulitply_conflicit_trait {
59-
trait T1 {
60-
fn foo() {}
61-
}
54+
struct S;
55+
56+
impl S {
57+
fn foo() {}
58+
}
6259

63-
trait T2 {
64-
fn foo() {}
60+
impl T1 for S {}
6561
}
6662

67-
struct S;
63+
mod mulitply_conflicit_trait {
64+
use crate::{T1, T2};
6865

69-
impl S {
70-
fn foo() {}
71-
}
66+
struct S;
7267

73-
impl T1 for S {}
68+
impl S {
69+
fn foo() {}
70+
}
7471

75-
impl T2 for S {}
76-
}
72+
impl T1 for S {}
7773

78-
mod not_lint_two_trait_method {
79-
trait T1 {
80-
fn foo();
74+
impl T2 for S {}
8175
}
76+
}
8277

83-
trait T2 {
84-
fn foo();
85-
}
78+
mod should_not_lint {
79+
80+
mod not_lint_two_trait_method {
81+
use crate::{T1, T2};
82+
83+
struct S;
8684

87-
struct S;
85+
impl T1 for S {
86+
fn foo() {}
87+
}
8888

89-
impl T1 for S {
90-
fn foo() {}
89+
impl T2 for S {
90+
fn foo() {}
91+
}
9192
}
9293

93-
impl T2 for S {
94-
fn foo() {}
94+
mod only_lint_on_method {
95+
trait T3 {
96+
type foo;
97+
}
98+
99+
struct S;
100+
101+
impl S {
102+
fn foo() {}
103+
}
104+
impl T3 for S {
105+
type foo = usize;
106+
}
95107
}
96108
}
97109

tests/ui/same_name_method.stderr

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
11
error: binding's name is same to an existing binding
2-
--> $DIR/same_name_method.rs:11:9
2+
--> $DIR/same_name_method.rs:19:13
33
|
4-
LL | fn foo() {}
5-
| ^^^^^^^^^^^
4+
LL | fn foo() {}
5+
| ^^^^^^^^^^^
66
|
77
= note: `-D clippy::same-name-method` implied by `-D warnings`
88
note: existing binding defined here
9-
--> $DIR/same_name_method.rs:15:9
9+
--> $DIR/same_name_method.rs:23:13
1010
|
11-
LL | fn foo() {}
12-
| ^^^^^^^^^^^
11+
LL | fn foo() {}
12+
| ^^^^^^^^^^^
1313

1414
error: binding's name is same to an existing binding
15-
--> $DIR/same_name_method.rs:36:9
15+
--> $DIR/same_name_method.rs:43:13
1616
|
17-
LL | fn foo() {}
18-
| ^^^^^^^^^^^
17+
LL | fn foo() {}
18+
| ^^^^^^^^^^^
1919
|
2020
note: existing binding defined here
21-
--> $DIR/same_name_method.rs:40:9
21+
--> $DIR/same_name_method.rs:47:13
2222
|
23-
LL | fn foo() {}
24-
| ^^^^^^^^^^^
23+
LL | fn foo() {}
24+
| ^^^^^^^^^^^
2525

2626
error: binding's name is same to an existing binding
27-
--> $DIR/same_name_method.rs:52:9
27+
--> $DIR/same_name_method.rs:57:13
2828
|
29-
LL | fn foo() {}
30-
| ^^^^^^^^^^^
29+
LL | fn foo() {}
30+
| ^^^^^^^^^^^
3131
|
3232
note: existing binding defined here
33-
--> $DIR/same_name_method.rs:55:5
33+
--> $DIR/same_name_method.rs:60:9
3434
|
35-
LL | impl T1 for S {}
36-
| ^^^^^^^^^^^^^^^^
35+
LL | impl T1 for S {}
36+
| ^^^^^^^^^^^^^^^^
3737

3838
error: binding's name is same to an existing binding
39-
--> $DIR/same_name_method.rs:70:9
39+
--> $DIR/same_name_method.rs:69:13
4040
|
41-
LL | fn foo() {}
42-
| ^^^^^^^^^^^
41+
LL | fn foo() {}
42+
| ^^^^^^^^^^^
4343
|
4444
note: existing binding defined here
45-
--> $DIR/same_name_method.rs:73:5
45+
--> $DIR/same_name_method.rs:72:9
4646
|
47-
LL | impl T1 for S {}
48-
| ^^^^^^^^^^^^^^^^
47+
LL | impl T1 for S {}
48+
| ^^^^^^^^^^^^^^^^
4949

5050
error: binding's name is same to an existing binding
51-
--> $DIR/same_name_method.rs:24:9
51+
--> $DIR/same_name_method.rs:33:13
5252
|
53-
LL | fn clone() {}
54-
| ^^^^^^^^^^^^^
53+
LL | fn clone() {}
54+
| ^^^^^^^^^^^^^
5555
|
5656
note: existing binding defined here
57-
--> $DIR/same_name_method.rs:20:14
57+
--> $DIR/same_name_method.rs:29:18
5858
|
59-
LL | #[derive(Clone)]
60-
| ^^^^^
59+
LL | #[derive(Clone)]
60+
| ^^^^^
6161
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
6262

6363
error: aborting due to 5 previous errors

0 commit comments

Comments
 (0)