Skip to content

Commit 5a90737

Browse files
authored
Add multiple-inherent-impl tests (#15886)
Add tests for #8714 and #13040. changelog:none
2 parents 7c86faa + 1e1c1f3 commit 5a90737

File tree

5 files changed

+281
-0
lines changed

5 files changed

+281
-0
lines changed

tests/ui/impl.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,26 @@ impl OneExpected {}
8484
impl OneExpected {}
8585
//~^ multiple_inherent_impl
8686

87+
// issue #8714
88+
struct Lifetime<'s> {
89+
s: &'s str,
90+
}
91+
92+
impl Lifetime<'_> {}
93+
impl Lifetime<'_> {} // false negative
94+
95+
impl<'a> Lifetime<'a> {}
96+
impl<'a> Lifetime<'a> {} // false negative
97+
98+
impl<'b> Lifetime<'b> {} // false negative?
99+
100+
impl Lifetime<'static> {}
101+
102+
struct Generic<G> {
103+
g: Vec<G>,
104+
}
105+
106+
impl<G> Generic<G> {}
107+
impl<G> Generic<G> {} // false negative
108+
87109
fn main() {}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error: multiple implementations of this structure
2+
--> tests/ui/multiple_inherent_impl_cfg.rs:11:1
3+
|
4+
LL | impl A {}
5+
| ^^^^^^^^^
6+
|
7+
note: first implementation here
8+
--> tests/ui/multiple_inherent_impl_cfg.rs:10:1
9+
|
10+
LL | impl A {}
11+
| ^^^^^^^^^
12+
note: the lint level is defined here
13+
--> tests/ui/multiple_inherent_impl_cfg.rs:3:9
14+
|
15+
LL | #![deny(clippy::multiple_inherent_impl)]
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
18+
error: multiple implementations of this structure
19+
--> tests/ui/multiple_inherent_impl_cfg.rs:25:1
20+
|
21+
LL | impl B {}
22+
| ^^^^^^^^^
23+
|
24+
note: first implementation here
25+
--> tests/ui/multiple_inherent_impl_cfg.rs:21:1
26+
|
27+
LL | impl B {}
28+
| ^^^^^^^^^
29+
30+
error: aborting due to 2 previous errors
31+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//@compile-flags: --cfg test
2+
#![deny(clippy::multiple_inherent_impl)]
3+
4+
// issue #13040
5+
6+
fn main() {}
7+
8+
struct A;
9+
10+
impl A {}
11+
12+
impl A {}
13+
//~^ multiple_inherent_impl
14+
15+
#[cfg(test)]
16+
impl A {} // false positive
17+
//~^ multiple_inherent_impl
18+
19+
#[cfg(test)]
20+
impl A {}
21+
//~^ multiple_inherent_impl
22+
23+
struct B;
24+
25+
impl B {}
26+
27+
#[cfg(test)]
28+
impl B {} // false positive
29+
//~^ multiple_inherent_impl
30+
31+
impl B {}
32+
//~^ multiple_inherent_impl
33+
34+
#[cfg(test)]
35+
impl B {}
36+
//~^ multiple_inherent_impl
37+
38+
#[cfg(test)]
39+
struct C;
40+
41+
#[cfg(test)]
42+
impl C {}
43+
44+
#[cfg(test)]
45+
impl C {}
46+
//~^ multiple_inherent_impl
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
error: multiple implementations of this structure
2+
--> tests/ui/multiple_inherent_impl_cfg.rs:12:1
3+
|
4+
LL | impl A {}
5+
| ^^^^^^^^^
6+
|
7+
note: first implementation here
8+
--> tests/ui/multiple_inherent_impl_cfg.rs:10:1
9+
|
10+
LL | impl A {}
11+
| ^^^^^^^^^
12+
note: the lint level is defined here
13+
--> tests/ui/multiple_inherent_impl_cfg.rs:2:9
14+
|
15+
LL | #![deny(clippy::multiple_inherent_impl)]
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
18+
error: multiple implementations of this structure
19+
--> tests/ui/multiple_inherent_impl_cfg.rs:16:1
20+
|
21+
LL | impl A {} // false positive
22+
| ^^^^^^^^^
23+
|
24+
note: first implementation here
25+
--> tests/ui/multiple_inherent_impl_cfg.rs:10:1
26+
|
27+
LL | impl A {}
28+
| ^^^^^^^^^
29+
30+
error: multiple implementations of this structure
31+
--> tests/ui/multiple_inherent_impl_cfg.rs:20:1
32+
|
33+
LL | impl A {}
34+
| ^^^^^^^^^
35+
|
36+
note: first implementation here
37+
--> tests/ui/multiple_inherent_impl_cfg.rs:10:1
38+
|
39+
LL | impl A {}
40+
| ^^^^^^^^^
41+
42+
error: multiple implementations of this structure
43+
--> tests/ui/multiple_inherent_impl_cfg.rs:28:1
44+
|
45+
LL | impl B {} // false positive
46+
| ^^^^^^^^^
47+
|
48+
note: first implementation here
49+
--> tests/ui/multiple_inherent_impl_cfg.rs:25:1
50+
|
51+
LL | impl B {}
52+
| ^^^^^^^^^
53+
54+
error: multiple implementations of this structure
55+
--> tests/ui/multiple_inherent_impl_cfg.rs:31:1
56+
|
57+
LL | impl B {}
58+
| ^^^^^^^^^
59+
|
60+
note: first implementation here
61+
--> tests/ui/multiple_inherent_impl_cfg.rs:25:1
62+
|
63+
LL | impl B {}
64+
| ^^^^^^^^^
65+
66+
error: multiple implementations of this structure
67+
--> tests/ui/multiple_inherent_impl_cfg.rs:35:1
68+
|
69+
LL | impl B {}
70+
| ^^^^^^^^^
71+
|
72+
note: first implementation here
73+
--> tests/ui/multiple_inherent_impl_cfg.rs:25:1
74+
|
75+
LL | impl B {}
76+
| ^^^^^^^^^
77+
78+
error: multiple implementations of this structure
79+
--> tests/ui/multiple_inherent_impl_cfg.rs:45:1
80+
|
81+
LL | impl C {}
82+
| ^^^^^^^^^
83+
|
84+
note: first implementation here
85+
--> tests/ui/multiple_inherent_impl_cfg.rs:42:1
86+
|
87+
LL | impl C {}
88+
| ^^^^^^^^^
89+
90+
error: aborting due to 7 previous errors
91+
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
error: multiple implementations of this structure
2+
--> tests/ui/multiple_inherent_impl_cfg.rs:11:1
3+
|
4+
LL | impl A {}
5+
| ^^^^^^^^^
6+
|
7+
note: first implementation here
8+
--> tests/ui/multiple_inherent_impl_cfg.rs:10:1
9+
|
10+
LL | impl A {}
11+
| ^^^^^^^^^
12+
note: the lint level is defined here
13+
--> tests/ui/multiple_inherent_impl_cfg.rs:3:9
14+
|
15+
LL | #![deny(clippy::multiple_inherent_impl)]
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
18+
error: multiple implementations of this structure
19+
--> tests/ui/multiple_inherent_impl_cfg.rs:14:1
20+
|
21+
LL | impl A {}
22+
| ^^^^^^^^^
23+
|
24+
note: first implementation here
25+
--> tests/ui/multiple_inherent_impl_cfg.rs:10:1
26+
|
27+
LL | impl A {}
28+
| ^^^^^^^^^
29+
30+
error: multiple implementations of this structure
31+
--> tests/ui/multiple_inherent_impl_cfg.rs:17:1
32+
|
33+
LL | impl A {}
34+
| ^^^^^^^^^
35+
|
36+
note: first implementation here
37+
--> tests/ui/multiple_inherent_impl_cfg.rs:10:1
38+
|
39+
LL | impl A {}
40+
| ^^^^^^^^^
41+
42+
error: multiple implementations of this structure
43+
--> tests/ui/multiple_inherent_impl_cfg.rs:23:1
44+
|
45+
LL | impl B {}
46+
| ^^^^^^^^^
47+
|
48+
note: first implementation here
49+
--> tests/ui/multiple_inherent_impl_cfg.rs:21:1
50+
|
51+
LL | impl B {}
52+
| ^^^^^^^^^
53+
54+
error: multiple implementations of this structure
55+
--> tests/ui/multiple_inherent_impl_cfg.rs:25:1
56+
|
57+
LL | impl B {}
58+
| ^^^^^^^^^
59+
|
60+
note: first implementation here
61+
--> tests/ui/multiple_inherent_impl_cfg.rs:21:1
62+
|
63+
LL | impl B {}
64+
| ^^^^^^^^^
65+
66+
error: multiple implementations of this structure
67+
--> tests/ui/multiple_inherent_impl_cfg.rs:28:1
68+
|
69+
LL | impl B {}
70+
| ^^^^^^^^^
71+
|
72+
note: first implementation here
73+
--> tests/ui/multiple_inherent_impl_cfg.rs:21:1
74+
|
75+
LL | impl B {}
76+
| ^^^^^^^^^
77+
78+
error: multiple implementations of this structure
79+
--> tests/ui/multiple_inherent_impl_cfg.rs:36:1
80+
|
81+
LL | impl C {}
82+
| ^^^^^^^^^
83+
|
84+
note: first implementation here
85+
--> tests/ui/multiple_inherent_impl_cfg.rs:34:1
86+
|
87+
LL | impl C {}
88+
| ^^^^^^^^^
89+
90+
error: aborting due to 7 previous errors
91+

0 commit comments

Comments
 (0)