Skip to content

Commit b96842d

Browse files
aldhsuAllen Hsu
authored and
Allen Hsu
committed
Split unfixable lints.
1 parent 171d082 commit b96842d

6 files changed

+370
-250
lines changed

tests/compile-test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ const RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS: &[&str] = &[
394394
"single_component_path_imports_nested_first.rs",
395395
"string_add.rs",
396396
"toplevel_ref_arg_non_rustfix.rs",
397-
"trait_duplication_in_bounds.rs",
398397
"unit_arg.rs",
399398
"unnecessary_clone.rs",
400399
"unnecessary_lazy_eval_unfixable.rs",
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// run-rustfix
2+
#![deny(clippy::trait_duplication_in_bounds)]
3+
#![allow(unused)]
4+
5+
fn bad_foo<T: Clone + Copy, U: Clone + Copy>(arg0: T, argo1: U) {
6+
unimplemented!();
7+
}
8+
9+
fn bad_bar<T, U>(arg0: T, arg1: U)
10+
where
11+
T: Clone + Copy,
12+
U: Clone + Copy,
13+
{
14+
unimplemented!();
15+
}
16+
17+
fn good_bar<T: Clone + Copy, U: Clone + Copy>(arg0: T, arg1: U) {
18+
unimplemented!();
19+
}
20+
21+
fn good_foo<T, U>(arg0: T, arg1: U)
22+
where
23+
T: Clone + Copy,
24+
U: Clone + Copy,
25+
{
26+
unimplemented!();
27+
}
28+
29+
trait GoodSelfTraitBound: Clone + Copy {
30+
fn f();
31+
}
32+
33+
trait GoodSelfWhereClause {
34+
fn f()
35+
where
36+
Self: Clone + Copy;
37+
}
38+
39+
trait BadSelfTraitBound: Clone {
40+
fn f();
41+
}
42+
43+
trait BadSelfWhereClause {
44+
fn f()
45+
where
46+
Self: Clone;
47+
}
48+
49+
trait GoodTraitBound<T: Clone + Copy, U: Clone + Copy> {
50+
fn f();
51+
}
52+
53+
trait GoodWhereClause<T, U> {
54+
fn f()
55+
where
56+
T: Clone + Copy,
57+
U: Clone + Copy;
58+
}
59+
60+
trait BadTraitBound<T: Clone + Copy, U: Clone + Copy> {
61+
fn f();
62+
}
63+
64+
trait BadWhereClause<T, U> {
65+
fn f()
66+
where
67+
T: Clone + Copy,
68+
U: Clone + Copy;
69+
}
70+
71+
struct GoodStructBound<T: Clone + Copy, U: Clone + Copy> {
72+
t: T,
73+
u: U,
74+
}
75+
76+
impl<T: Clone + Copy, U: Clone + Copy> GoodTraitBound<T, U> for GoodStructBound<T, U> {
77+
// this should not warn
78+
fn f() {}
79+
}
80+
81+
struct GoodStructWhereClause;
82+
83+
impl<T, U> GoodTraitBound<T, U> for GoodStructWhereClause
84+
where
85+
T: Clone + Copy,
86+
U: Clone + Copy,
87+
{
88+
// this should not warn
89+
fn f() {}
90+
}
91+
92+
fn no_error_separate_arg_bounds(program: impl AsRef<()>, dir: impl AsRef<()>, args: &[impl AsRef<()>]) {}
93+
94+
trait GenericTrait<T> {}
95+
96+
fn good_generic<T: GenericTrait<u64> + GenericTrait<u32>>(arg0: T) {
97+
unimplemented!();
98+
}
99+
100+
fn bad_generic<T: GenericTrait<u32> + GenericTrait<u64>>(arg0: T) {
101+
unimplemented!();
102+
}
103+
104+
mod foo {
105+
pub trait Clone {}
106+
}
107+
108+
fn qualified_path<T: Clone + foo::Clone>(arg0: T) {
109+
unimplemented!();
110+
}
111+
112+
fn main() {}
Lines changed: 59 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -1,212 +1,112 @@
1+
// run-rustfix
12
#![deny(clippy::trait_duplication_in_bounds)]
23
#![allow(unused)]
34

4-
use std::collections::BTreeMap;
5-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
5+
fn bad_foo<T: Clone + Clone + Clone + Copy, U: Clone + Copy>(arg0: T, argo1: U) {
6+
unimplemented!();
7+
}
68

7-
fn bad_foo<T: Clone + Default, Z: Copy>(arg0: T, arg1: Z)
9+
fn bad_bar<T, U>(arg0: T, arg1: U)
810
where
9-
T: Clone,
10-
T: Default,
11+
T: Clone + Clone + Clone + Copy,
12+
U: Clone + Copy,
1113
{
1214
unimplemented!();
1315
}
1416

15-
fn good_bar<T: Clone + Default>(arg: T) {
17+
fn good_bar<T: Clone + Copy, U: Clone + Copy>(arg0: T, arg1: U) {
1618
unimplemented!();
1719
}
1820

19-
fn good_foo<T>(arg: T)
21+
fn good_foo<T, U>(arg0: T, arg1: U)
2022
where
21-
T: Clone + Default,
23+
T: Clone + Copy,
24+
U: Clone + Copy,
2225
{
2326
unimplemented!();
2427
}
2528

26-
fn good_foobar<T: Default>(arg: T)
27-
where
28-
T: Clone,
29-
{
30-
unimplemented!();
29+
trait GoodSelfTraitBound: Clone + Copy {
30+
fn f();
3131
}
3232

33-
trait T: Default {
33+
trait GoodSelfWhereClause {
3434
fn f()
3535
where
36-
Self: Default;
36+
Self: Clone + Copy;
3737
}
3838

39-
trait U: Default {
39+
trait BadSelfTraitBound: Clone + Clone + Clone {
40+
fn f();
41+
}
42+
43+
trait BadSelfWhereClause {
4044
fn f()
4145
where
42-
Self: Clone;
46+
Self: Clone + Clone + Clone;
47+
}
48+
49+
trait GoodTraitBound<T: Clone + Copy, U: Clone + Copy> {
50+
fn f();
4351
}
4452

45-
trait ZZ: Default {
46-
fn g();
47-
fn h();
53+
trait GoodWhereClause<T, U> {
4854
fn f()
4955
where
50-
Self: Default + Clone;
56+
T: Clone + Copy,
57+
U: Clone + Copy;
5158
}
5259

53-
trait BadTrait: Default + Clone {
60+
trait BadTraitBound<T: Clone + Clone + Clone + Copy, U: Clone + Copy> {
61+
fn f();
62+
}
63+
64+
trait BadWhereClause<T, U> {
5465
fn f()
5566
where
56-
Self: Default + Clone;
57-
fn g()
58-
where
59-
Self: Default;
60-
fn h()
61-
where
62-
Self: Copy;
67+
T: Clone + Clone + Clone + Copy,
68+
U: Clone + Copy;
6369
}
6470

65-
#[derive(Default, Clone)]
66-
struct Life;
71+
struct GoodStructBound<T: Clone + Copy, U: Clone + Copy> {
72+
t: T,
73+
u: U,
74+
}
6775

68-
impl T for Life {
76+
impl<T: Clone + Copy, U: Clone + Copy> GoodTraitBound<T, U> for GoodStructBound<T, U> {
6977
// this should not warn
7078
fn f() {}
7179
}
7280

73-
impl U for Life {
81+
struct GoodStructWhereClause;
82+
83+
impl<T, U> GoodTraitBound<T, U> for GoodStructWhereClause
84+
where
85+
T: Clone + Copy,
86+
U: Clone + Copy,
87+
{
7488
// this should not warn
7589
fn f() {}
7690
}
7791

78-
// should not warn
79-
trait Iter: Iterator {
80-
fn into_group_btreemap<K, V>(self) -> BTreeMap<K, Vec<V>>
81-
where
82-
Self: Iterator<Item = (K, V)> + Sized,
83-
K: Ord + Eq,
84-
{
85-
unimplemented!();
86-
}
87-
}
92+
fn no_error_separate_arg_bounds(program: impl AsRef<()>, dir: impl AsRef<()>, args: &[impl AsRef<()>]) {}
8893

89-
struct Foo;
94+
trait GenericTrait<T> {}
9095

91-
trait FooIter: Iterator<Item = Foo> {
92-
fn bar()
93-
where
94-
Self: Iterator<Item = Foo>,
95-
{
96-
}
96+
fn good_generic<T: GenericTrait<u64> + GenericTrait<u32>>(arg0: T) {
97+
unimplemented!();
9798
}
9899

99-
// This should not lint
100-
fn impl_trait(_: impl AsRef<str>, _: impl AsRef<str>) {}
101-
102-
mod repeated_where_clauses_or_trait_bounds {
103-
fn bad_foo<T: Clone + Clone + Clone + Copy, U: Clone + Copy>(arg0: T, argo1: U) {
104-
unimplemented!();
105-
}
106-
107-
fn bad_bar<T, U>(arg0: T, arg1: U)
108-
where
109-
T: Clone + Clone + Clone + Copy,
110-
U: Clone + Copy,
111-
{
112-
unimplemented!();
113-
}
114-
115-
fn good_bar<T: Clone + Copy, U: Clone + Copy>(arg0: T, arg1: U) {
116-
unimplemented!();
117-
}
118-
119-
fn good_foo<T, U>(arg0: T, arg1: U)
120-
where
121-
T: Clone + Copy,
122-
U: Clone + Copy,
123-
{
124-
unimplemented!();
125-
}
126-
127-
trait GoodSelfTraitBound: Clone + Copy {
128-
fn f();
129-
}
130-
131-
trait GoodSelfWhereClause {
132-
fn f()
133-
where
134-
Self: Clone + Copy;
135-
}
136-
137-
trait BadSelfTraitBound: Clone + Clone + Clone {
138-
fn f();
139-
}
140-
141-
trait BadSelfWhereClause {
142-
fn f()
143-
where
144-
Self: Clone + Clone + Clone;
145-
}
146-
147-
trait GoodTraitBound<T: Clone + Copy, U: Clone + Copy> {
148-
fn f();
149-
}
150-
151-
trait GoodWhereClause<T, U> {
152-
fn f()
153-
where
154-
T: Clone + Copy,
155-
U: Clone + Copy;
156-
}
157-
158-
trait BadTraitBound<T: Clone + Clone + Clone + Copy, U: Clone + Copy> {
159-
fn f();
160-
}
161-
162-
trait BadWhereClause<T, U> {
163-
fn f()
164-
where
165-
T: Clone + Clone + Clone + Copy,
166-
U: Clone + Copy;
167-
}
168-
169-
struct GoodStructBound<T: Clone + Copy, U: Clone + Copy> {
170-
t: T,
171-
u: U,
172-
}
173-
174-
impl<T: Clone + Copy, U: Clone + Copy> GoodTraitBound<T, U> for GoodStructBound<T, U> {
175-
// this should not warn
176-
fn f() {}
177-
}
178-
179-
struct GoodStructWhereClause;
180-
181-
impl<T, U> GoodTraitBound<T, U> for GoodStructWhereClause
182-
where
183-
T: Clone + Copy,
184-
U: Clone + Copy,
185-
{
186-
// this should not warn
187-
fn f() {}
188-
}
189-
190-
fn no_error_separate_arg_bounds(program: impl AsRef<()>, dir: impl AsRef<()>, args: &[impl AsRef<()>]) {}
191-
192-
trait GenericTrait<T> {}
193-
194-
// This should not warn but currently does see #8757
195-
fn good_generic<T: GenericTrait<u64> + GenericTrait<u32>>(arg0: T) {
196-
unimplemented!();
197-
}
198-
199-
fn bad_generic<T: GenericTrait<u64> + GenericTrait<u32> + GenericTrait<u64>>(arg0: T) {
200-
unimplemented!();
201-
}
100+
fn bad_generic<T: GenericTrait<u64> + GenericTrait<u32> + GenericTrait<u64>>(arg0: T) {
101+
unimplemented!();
102+
}
202103

203-
mod foo {
204-
pub trait Clone {}
205-
}
104+
mod foo {
105+
pub trait Clone {}
106+
}
206107

207-
fn qualified_path<T: std::clone::Clone + Clone + foo::Clone>(arg0: T) {
208-
unimplemented!();
209-
}
108+
fn qualified_path<T: std::clone::Clone + Clone + foo::Clone>(arg0: T) {
109+
unimplemented!();
210110
}
211111

212112
fn main() {}

0 commit comments

Comments
 (0)