Skip to content

Commit f4dc348

Browse files
committed
trait_duplication_in_bounds Update description and add test
1 parent f690978 commit f4dc348

File tree

3 files changed

+40
-21
lines changed

3 files changed

+40
-21
lines changed

clippy_lints/src/trait_bounds.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,14 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
121121
.filter_map(get_trait_res_span_from_bound)
122122
.for_each(|(trait_item_res, span)| {
123123
if self_bounds_set.get(&trait_item_res).is_some() {
124-
emit_lint(cx, span);
124+
span_lint_and_help(
125+
cx,
126+
TRAIT_DUPLICATION_IN_BOUNDS,
127+
span,
128+
"this trait bound is already specified in trait declaration",
129+
None,
130+
"consider removing this trait bound",
131+
);
125132
}
126133
});
127134
}
@@ -242,21 +249,17 @@ fn check_trait_bound_duplication(cx: &LateContext<'_>, gen: &'_ Generics<'_>) {
242249
if let Some((_, span_direct)) = trait_resolutions_direct
243250
.iter()
244251
.find(|(res_direct, _)| *res_direct == res_where) {
245-
emit_lint(cx, *span_direct);
252+
span_lint_and_help(
253+
cx,
254+
TRAIT_DUPLICATION_IN_BOUNDS,
255+
*span_direct,
256+
"this trait bound is already specified in the where clause",
257+
None,
258+
"consider removing this trait bound",
259+
);
246260
}
247261
}
248262
}
249263
}
250264
}
251265
}
252-
253-
fn emit_lint(cx: &LateContext<'_>, span: Span) {
254-
span_lint_and_help(
255-
cx,
256-
TRAIT_DUPLICATION_IN_BOUNDS,
257-
span,
258-
"this trait bound is already specified in the where clause",
259-
None,
260-
"consider removing this trait bound",
261-
);
262-
}

tests/ui/trait_duplication_in_bounds.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ trait U: Default {
4141
}
4242

4343
trait ZZ: Default {
44+
fn g();
45+
fn h();
4446
fn f()
4547
where
4648
Self: Default + Clone;
@@ -50,6 +52,12 @@ trait BadTrait: Default + Clone {
5052
fn f()
5153
where
5254
Self: Default + Clone;
55+
fn g()
56+
where
57+
Self: Default;
58+
fn h()
59+
where
60+
Self: Copy;
5361
}
5462

5563
#[derive(Default, Clone)]

tests/ui/trait_duplication_in_bounds.stderr

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,45 @@ LL | fn bad_foo<T: Clone + Default, Z: Copy>(arg0: T, arg1: Z)
1919
|
2020
= help: consider removing this trait bound
2121

22-
error: this trait bound is already specified in the where clause
22+
error: this trait bound is already specified in trait declaration
2323
--> $DIR/trait_duplication_in_bounds.rs:34:15
2424
|
2525
LL | Self: Default;
2626
| ^^^^^^^
2727
|
2828
= help: consider removing this trait bound
2929

30-
error: this trait bound is already specified in the where clause
31-
--> $DIR/trait_duplication_in_bounds.rs:46:15
30+
error: this trait bound is already specified in trait declaration
31+
--> $DIR/trait_duplication_in_bounds.rs:48:15
3232
|
3333
LL | Self: Default + Clone;
3434
| ^^^^^^^
3535
|
3636
= help: consider removing this trait bound
3737

38-
error: this trait bound is already specified in the where clause
39-
--> $DIR/trait_duplication_in_bounds.rs:52:15
38+
error: this trait bound is already specified in trait declaration
39+
--> $DIR/trait_duplication_in_bounds.rs:54:15
4040
|
4141
LL | Self: Default + Clone;
4242
| ^^^^^^^
4343
|
4444
= help: consider removing this trait bound
4545

46-
error: this trait bound is already specified in the where clause
47-
--> $DIR/trait_duplication_in_bounds.rs:52:25
46+
error: this trait bound is already specified in trait declaration
47+
--> $DIR/trait_duplication_in_bounds.rs:54:25
4848
|
4949
LL | Self: Default + Clone;
5050
| ^^^^^
5151
|
5252
= help: consider removing this trait bound
5353

54-
error: aborting due to 6 previous errors
54+
error: this trait bound is already specified in trait declaration
55+
--> $DIR/trait_duplication_in_bounds.rs:57:15
56+
|
57+
LL | Self: Default;
58+
| ^^^^^^^
59+
|
60+
= help: consider removing this trait bound
61+
62+
error: aborting due to 7 previous errors
5563

0 commit comments

Comments
 (0)