Skip to content

Commit c3cb81b

Browse files
committed
Take generic args into account for bounded type
1 parent 7ca32d3 commit c3cb81b

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

clippy_lints/src/utils/hir_utils.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
700700
}
701701
for segment in path.segments {
702702
segment.ident.name.hash(&mut self.s);
703+
self.hash_generic_args(segment.generic_args().args);
703704
}
704705
},
705706
QPath::TypeRelative(ref ty, ref segment) => {
@@ -708,13 +709,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
708709
},
709710
},
710711
TyKind::OpaqueDef(_, arg_list) => {
711-
for arg in *arg_list {
712-
match arg {
713-
GenericArg::Lifetime(ref l) => self.hash_lifetime(l),
714-
GenericArg::Type(ref ty) => self.hash_ty(&ty),
715-
GenericArg::Const(ref ca) => self.hash_body(ca.value.body),
716-
}
717-
}
712+
self.hash_generic_args(arg_list);
718713
},
719714
TyKind::TraitObject(_, lifetime) => {
720715
self.hash_lifetime(lifetime);
@@ -733,4 +728,14 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
733728
self.hash_expr(&self.cx.tcx.hir().body(body_id).value);
734729
self.tables = old_tables;
735730
}
731+
732+
fn hash_generic_args(&mut self, arg_list: &[GenericArg<'_>]) {
733+
for arg in arg_list {
734+
match arg {
735+
GenericArg::Lifetime(ref l) => self.hash_lifetime(l),
736+
GenericArg::Type(ref ty) => self.hash_ty(&ty),
737+
GenericArg::Const(ref ca) => self.hash_body(ca.value.body),
738+
}
739+
}
740+
}
736741
}

tests/ui/type_repetition_in_bounds.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ where
1818
unimplemented!();
1919
}
2020

21+
// Threshold test (see #4380)
2122
trait LintBounds
2223
where
2324
Self: Clone,
@@ -35,4 +36,18 @@ where
3536
{
3637
}
3738

39+
// Generic distinction (see #4323)
40+
pub struct Foo<A>(A);
41+
pub struct Bar<A, B> {
42+
a: Foo<A>,
43+
b: Foo<B>,
44+
}
45+
46+
impl<A, B> Unpin for Bar<A, B>
47+
where
48+
Foo<A>: Unpin,
49+
Foo<B>: Unpin,
50+
{
51+
}
52+
3853
fn main() {}

tests/ui/type_repetition_in_bounds.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | #![deny(clippy::type_repetition_in_bounds)]
1212
= help: consider combining the bounds: `T: Copy + Clone`
1313

1414
error: this type has already been used as a bound predicate
15-
--> $DIR/type_repetition_in_bounds.rs:24:5
15+
--> $DIR/type_repetition_in_bounds.rs:25:5
1616
|
1717
LL | Self: Copy + Default + Ord,
1818
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)