Skip to content

Commit 89192b9

Browse files
author
Allen Hsu
committed
fixup! Support trait bounds with type parameters.
1 parent c9c31f3 commit 89192b9

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

clippy_lints/src/trait_bounds.rs

+19-21
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use rustc_data_structures::unhash::UnhashMap;
88
use rustc_errors::Applicability;
99
use rustc_hir::def::Res;
1010
use rustc_hir::{
11-
GenericArg, GenericBound, GenericBound, Generics, Item, ItemKind, Node, ParamName, Path, PathSegment, QPath,
12-
TraitItem, Ty, TyKind, WherePredicate,
11+
GenericArg, GenericBound, Generics, Item, ItemKind, Node, Path, PathSegment, QPath, TraitItem, Ty, TyKind,
12+
WherePredicate,
1313
};
1414
use rustc_lint::{LateContext, LateLintPass};
1515
use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -95,7 +95,7 @@ declare_clippy_lint! {
9595
/// ```
9696
#[clippy::version = "1.62.0"]
9797
pub REPEATED_WHERE_CLAUSE_OR_TRAIT_BOUND,
98-
pedantic,
98+
nursery,
9999
"Traits are repeated within trait bounds or where clause"
100100
}
101101

@@ -282,27 +282,25 @@ fn check_trait_bound_duplication(cx: &LateContext<'_>, gen: &'_ Generics<'_>) {
282282
}
283283

284284
#[derive(PartialEq, Eq, Hash, Debug)]
285-
struct ComparableBound(Res, Vec<Res>, Vec<ComparableBound>);
285+
struct ComparableBound(
286+
Res,
287+
Vec<Res>,
288+
// Vec<ComparableBound>
289+
);
286290

287291
fn check_bounds_or_where_duplication(cx: &LateContext<'_>, gen: &'_ Generics<'_>) {
288292
if gen.span.from_expansion() {
289293
return;
290294
}
291295

292-
for param in gen.params {
293-
if let ParamName::Plain(_) = param.name {
294-
// other alternatives are errors and elided which won't have duplicates
295-
rollup_traits(cx, param.bounds, "this trait bound contains repeated elements");
296-
}
297-
}
298-
299-
for predicate in gen.where_clause.predicates {
296+
for predicate in gen.predicates {
300297
if let WherePredicate::BoundPredicate(ref bound_predicate) = predicate {
301-
rollup_traits(
302-
cx,
303-
bound_predicate.bounds,
304-
"this where clause contains repeated elements",
305-
);
298+
let msg = if predicate.in_where_clause() {
299+
"these where clauses contain repeated elements"
300+
} else {
301+
"these bounds contain repeated elements"
302+
};
303+
rollup_traits(cx, bound_predicate.bounds, msg);
306304
}
307305
}
308306
}
@@ -336,10 +334,10 @@ fn try_into_comparable_bound(bound: &GenericBound<'_>) -> Option<ComparableBound
336334
})
337335
.flatten()
338336
.collect(),
339-
t.bound_generic_params
340-
.iter()
341-
.flat_map(|param| param.bounds.iter().filter_map(try_into_comparable_bound))
342-
.collect(),
337+
// t.bound_generic_params
338+
// .iter()
339+
// .flat_map(|param| param.bounds.iter().filter_map(try_into_comparable_bound))
340+
// .collect(),
343341
))
344342
} else {
345343
None

tests/ui/repeated_where_clause_or_trait_bound.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: this trait bound contains repeated elements
1+
error: these bounds contain repeated elements
22
--> $DIR/repeated_where_clause_or_trait_bound.rs:6:15
33
|
44
LL | fn bad_foo<T: Clone + Clone + Clone + Copy, U: Clone + Copy>(arg0: T, argo1: U) {
@@ -10,31 +10,31 @@ note: the lint level is defined here
1010
LL | #![deny(clippy::repeated_where_clause_or_trait_bound)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

13-
error: this where clause contains repeated elements
13+
error: these where clauses contain repeated elements
1414
--> $DIR/repeated_where_clause_or_trait_bound.rs:12:8
1515
|
1616
LL | T: Clone + Clone + Clone + Copy,
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy`
1818

19-
error: this where clause contains repeated elements
19+
error: these where clauses contain repeated elements
2020
--> $DIR/repeated_where_clause_or_trait_bound.rs:47:15
2121
|
2222
LL | Self: Clone + Clone + Clone;
2323
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone`
2424

25-
error: this trait bound contains repeated elements
25+
error: these bounds contain repeated elements
2626
--> $DIR/repeated_where_clause_or_trait_bound.rs:61:24
2727
|
2828
LL | trait BadTraitBound<T: Clone + Clone + Clone + Copy, U: Clone + Copy> {
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy`
3030

31-
error: this where clause contains repeated elements
31+
error: these where clauses contain repeated elements
3232
--> $DIR/repeated_where_clause_or_trait_bound.rs:68:12
3333
|
3434
LL | T: Clone + Clone + Clone + Copy,
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy`
3636

37-
error: this trait bound contains repeated elements
37+
error: these bounds contain repeated elements
3838
--> $DIR/repeated_where_clause_or_trait_bound.rs:101:19
3939
|
4040
LL | fn bad_generic<T: GenericTrait<u64> + GenericTrait<u32> + GenericTrait<u64>>(arg0: T) {

0 commit comments

Comments
 (0)