Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions clippy_utils/src/hir_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ impl HirEqInterExpr<'_, '_, '_> {
fn eq_path_parameters(&mut self, left: &GenericArgs<'_>, right: &GenericArgs<'_>) -> bool {
if left.parenthesized == right.parenthesized {
over(left.args, right.args, |l, r| self.eq_generic_arg(l, r)) // FIXME(flip1995): may not work
&& over(left.constraints, right.constraints, |l, r| self.eq_assoc_type_binding(l, r))
&& over(left.constraints, right.constraints, |l, r| self.eq_assoc_eq_constraint(l, r))
} else {
false
}
Expand Down Expand Up @@ -602,8 +602,13 @@ impl HirEqInterExpr<'_, '_, '_> {
}
}

fn eq_assoc_type_binding(&mut self, left: &AssocItemConstraint<'_>, right: &AssocItemConstraint<'_>) -> bool {
left.ident.name == right.ident.name && both_some_and(left.ty(), right.ty(), |l, r| self.eq_ty(l, r))
/// Checks whether two constraints designate the same equality constraint (same name, and same
/// type or const).
fn eq_assoc_eq_constraint(&mut self, left: &AssocItemConstraint<'_>, right: &AssocItemConstraint<'_>) -> bool {
// TODO: this could be extended to check for identical associated item bound constraints
left.ident.name == right.ident.name
&& (both_some_and(left.ty(), right.ty(), |l, r| self.eq_ty(l, r))
|| both_some_and(left.ct(), right.ct(), |l, r| self.eq_const_arg(l, r)))
}

fn check_ctxt(&mut self, left: SyntaxContext, right: SyntaxContext) -> bool {
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/trait_duplication_in_bounds.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ trait AssocConstTrait {
}
fn assoc_const_args<T>()
where
T: AssocConstTrait<ASSOC = 0> + AssocConstTrait<ASSOC = 0>,
T: AssocConstTrait<ASSOC = 0>,
//~^ trait_duplication_in_bounds
{
}
1 change: 1 addition & 0 deletions tests/ui/trait_duplication_in_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,6 @@ trait AssocConstTrait {
fn assoc_const_args<T>()
where
T: AssocConstTrait<ASSOC = 0> + AssocConstTrait<ASSOC = 0>,
//~^ trait_duplication_in_bounds
{
}
8 changes: 7 additions & 1 deletion tests/ui/trait_duplication_in_bounds.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,11 @@ error: these where clauses contain repeated elements
LL | T: IntoIterator<Item = U::Owned> + IntoIterator<Item = U::Owned>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `IntoIterator<Item = U::Owned>`

error: aborting due to 11 previous errors
error: these where clauses contain repeated elements
--> tests/ui/trait_duplication_in_bounds.rs:194:8
|
LL | T: AssocConstTrait<ASSOC = 0> + AssocConstTrait<ASSOC = 0>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `AssocConstTrait<ASSOC = 0>`

error: aborting due to 12 previous errors