Skip to content

Commit d5a8f03

Browse files
committed
Take generic args into account for bounded type
1 parent 754bfb1 commit d5a8f03

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

clippy_lints/src/utils/hir_utils.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
703703
}
704704
for segment in path.segments {
705705
segment.ident.name.hash(&mut self.s);
706+
self.hash_generic_args(segment.generic_args().args);
706707
}
707708
},
708709
QPath::TypeRelative(ref ty, ref segment) => {
@@ -711,13 +712,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
711712
},
712713
},
713714
TyKind::OpaqueDef(_, arg_list) => {
714-
for arg in *arg_list {
715-
match arg {
716-
GenericArg::Lifetime(ref l) => self.hash_lifetime(l),
717-
GenericArg::Type(ref ty) => self.hash_ty(&ty),
718-
GenericArg::Const(ref ca) => self.hash_body(ca.value.body),
719-
}
720-
}
715+
self.hash_generic_args(arg_list);
721716
},
722717
TyKind::TraitObject(_, lifetime) => {
723718
self.hash_lifetime(lifetime);
@@ -735,4 +730,14 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
735730
self.hash_expr(&self.cx.tcx.hir().body(body_id).value);
736731
self.maybe_typeck_tables = old_maybe_typeck_tables;
737732
}
733+
734+
fn hash_generic_args(&mut self, arg_list: &[GenericArg<'_>]) {
735+
for arg in arg_list {
736+
match arg {
737+
GenericArg::Lifetime(ref l) => self.hash_lifetime(l),
738+
GenericArg::Type(ref ty) => self.hash_ty(&ty),
739+
GenericArg::Const(ref ca) => self.hash_body(ca.value.body),
740+
}
741+
}
742+
}
738743
}

tests/ui/type_repetition_in_bounds.rs

+15
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

+1-1
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)