Take generic args into account for bounded type

This commit is contained in:
ThibsG 2020-07-03 10:29:14 +02:00
parent 754bfb1dc8
commit d5a8f03a35
3 changed files with 28 additions and 8 deletions

View File

@ -703,6 +703,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
}
for segment in path.segments {
segment.ident.name.hash(&mut self.s);
self.hash_generic_args(segment.generic_args().args);
}
},
QPath::TypeRelative(ref ty, ref segment) => {
@ -711,13 +712,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
},
},
TyKind::OpaqueDef(_, arg_list) => {
for arg in *arg_list {
match arg {
GenericArg::Lifetime(ref l) => self.hash_lifetime(l),
GenericArg::Type(ref ty) => self.hash_ty(&ty),
GenericArg::Const(ref ca) => self.hash_body(ca.value.body),
}
}
self.hash_generic_args(arg_list);
},
TyKind::TraitObject(_, lifetime) => {
self.hash_lifetime(lifetime);
@ -735,4 +730,14 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
self.hash_expr(&self.cx.tcx.hir().body(body_id).value);
self.maybe_typeck_tables = old_maybe_typeck_tables;
}
fn hash_generic_args(&mut self, arg_list: &[GenericArg<'_>]) {
for arg in arg_list {
match arg {
GenericArg::Lifetime(ref l) => self.hash_lifetime(l),
GenericArg::Type(ref ty) => self.hash_ty(&ty),
GenericArg::Const(ref ca) => self.hash_body(ca.value.body),
}
}
}
}

View File

@ -18,6 +18,7 @@ where
unimplemented!();
}
// Threshold test (see #4380)
trait LintBounds
where
Self: Clone,
@ -35,4 +36,18 @@ where
{
}
// Generic distinction (see #4323)
pub struct Foo<A>(A);
pub struct Bar<A, B> {
a: Foo<A>,
b: Foo<B>,
}
impl<A, B> Unpin for Bar<A, B>
where
Foo<A>: Unpin,
Foo<B>: Unpin,
{
}
fn main() {}

View File

@ -12,7 +12,7 @@ LL | #![deny(clippy::type_repetition_in_bounds)]
= help: consider combining the bounds: `T: Copy + Clone`
error: this type has already been used as a bound predicate
--> $DIR/type_repetition_in_bounds.rs:24:5
--> $DIR/type_repetition_in_bounds.rs:25:5
|
LL | Self: Copy + Default + Ord,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^