Skip to content

Commit 1eff408

Browse files
committed
WIP
1 parent 478555d commit 1eff408

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

clippy_lints/src/trait_bounds.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,14 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
195195
let already_seen = !seen_def_ids.insert(def_id);
196196

197197
if already_seen {
198-
span_lint_and_help(
198+
span_lint_and_sugg(
199199
cx,
200200
TRAIT_DUPLICATION_IN_BOUNDS,
201201
bound.span,
202202
"this trait bound is already specified in trait declaration",
203-
None,
204203
"consider removing this trait bound",
204+
"".to_string(),
205+
Applicability::MaybeIncorrect,
205206
);
206207
}
207208
}

tests/ui/trait_duplication_in_bounds.fixed

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#![deny(clippy::trait_duplication_in_bounds)]
33
#![allow(unused)]
44

5+
use std::any::Any;
6+
57
fn bad_foo<T: Clone + Copy, U: Clone + Copy>(arg0: T, argo1: U) {
68
unimplemented!();
79
}
@@ -109,4 +111,12 @@ fn qualified_path<T: std::clone::Clone + foo::Clone>(arg0: T) {
109111
unimplemented!();
110112
}
111113

114+
fn good_trait_object(arg0: &(dyn Any + Send)) {
115+
unimplemented!();
116+
}
117+
118+
fn bad_trait_object(arg0: &(dyn Any + Send)) {
119+
unimplemented!();
120+
}
121+
112122
fn main() {}

tests/ui/trait_duplication_in_bounds.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#![deny(clippy::trait_duplication_in_bounds)]
33
#![allow(unused)]
44

5+
use std::any::Any;
6+
57
fn bad_foo<T: Clone + Clone + Clone + Copy, U: Clone + Copy>(arg0: T, argo1: U) {
68
unimplemented!();
79
}
Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: these bounds contain repeated elements
2-
--> $DIR/trait_duplication_in_bounds.rs:5:15
2+
--> $DIR/trait_duplication_in_bounds.rs:7:15
33
|
44
LL | fn bad_foo<T: Clone + Clone + Clone + Copy, U: Clone + Copy>(arg0: T, argo1: U) {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy`
@@ -11,46 +11,53 @@ LL | #![deny(clippy::trait_duplication_in_bounds)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error: these where clauses contain repeated elements
14-
--> $DIR/trait_duplication_in_bounds.rs:11:8
14+
--> $DIR/trait_duplication_in_bounds.rs:13:8
1515
|
1616
LL | T: Clone + Clone + Clone + Copy,
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy`
1818

1919
error: these bounds contain repeated elements
20-
--> $DIR/trait_duplication_in_bounds.rs:39:26
20+
--> $DIR/trait_duplication_in_bounds.rs:41:26
2121
|
2222
LL | trait BadSelfTraitBound: Clone + Clone + Clone {
2323
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone`
2424

2525
error: these where clauses contain repeated elements
26-
--> $DIR/trait_duplication_in_bounds.rs:46:15
26+
--> $DIR/trait_duplication_in_bounds.rs:48:15
2727
|
2828
LL | Self: Clone + Clone + Clone;
2929
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone`
3030

3131
error: these bounds contain repeated elements
32-
--> $DIR/trait_duplication_in_bounds.rs:60:24
32+
--> $DIR/trait_duplication_in_bounds.rs:62:24
3333
|
3434
LL | trait BadTraitBound<T: Clone + Clone + Clone + Copy, U: Clone + Copy> {
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy`
3636

3737
error: these where clauses contain repeated elements
38-
--> $DIR/trait_duplication_in_bounds.rs:67:12
38+
--> $DIR/trait_duplication_in_bounds.rs:69:12
3939
|
4040
LL | T: Clone + Clone + Clone + Copy,
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy`
4242

4343
error: these bounds contain repeated elements
44-
--> $DIR/trait_duplication_in_bounds.rs:100:19
44+
--> $DIR/trait_duplication_in_bounds.rs:102:19
4545
|
4646
LL | fn bad_generic<T: GenericTrait<u64> + GenericTrait<u32> + GenericTrait<u64>>(arg0: T) {
4747
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `GenericTrait<u64> + GenericTrait<u32>`
4848

4949
error: these bounds contain repeated elements
50-
--> $DIR/trait_duplication_in_bounds.rs:108:22
50+
--> $DIR/trait_duplication_in_bounds.rs:110:22
5151
|
5252
LL | fn qualified_path<T: std::clone::Clone + Clone + foo::Clone>(arg0: T) {
5353
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::clone::Clone + foo::Clone`
5454

55-
error: aborting due to 8 previous errors
55+
error: this trait bound is already specified in trait declaration
56+
--> $DIR/trait_duplication_in_bounds.rs:118:46
57+
|
58+
LL | fn bad_trait_object(arg0: &(dyn Any + Send + Send)) {
59+
| ^^^^ help: consider removing this trait bound
60+
|
61+
62+
error: aborting due to 9 previous errors
5663

0 commit comments

Comments
 (0)