diff options
| author | Timo <30553356+y21@users.noreply.github.com> | 2024-11-27 20:23:54 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-27 20:23:54 +0000 |
| commit | 67657da6719ad030fac4d308731d8d3687b3b6e0 (patch) | |
| tree | a5363007d7df7eda82603920bac58d7d5b8802e6 | |
| parent | 9b0597d78a7fdc7044ad9f3dff729f7ea2aadd7d (diff) | |
| parent | 2bf03f19e2722f5254555eaa8c96510de6d3ec66 (diff) | |
| download | rust-67657da6719ad030fac4d308731d8d3687b3b6e0.tar.gz rust-67657da6719ad030fac4d308731d8d3687b3b6e0.zip | |
Handle repetition of associated constant constraint as well (#13723)
changelog: [`trait_duplication_in_bounds`]: trigger on duplicate const associated constraint as well ~~The first commit is part of #13722 which must be merged first.~~
| -rw-r--r-- | clippy_utils/src/hir_utils.rs | 11 | ||||
| -rw-r--r-- | tests/ui/trait_duplication_in_bounds.fixed | 3 | ||||
| -rw-r--r-- | tests/ui/trait_duplication_in_bounds.rs | 1 | ||||
| -rw-r--r-- | tests/ui/trait_duplication_in_bounds.stderr | 8 |
4 files changed, 18 insertions, 5 deletions
diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 5c93a9948b8..5c5d84cb381 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -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 } @@ -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 { diff --git a/tests/ui/trait_duplication_in_bounds.fixed b/tests/ui/trait_duplication_in_bounds.fixed index e57c79553c3..708512793d5 100644 --- a/tests/ui/trait_duplication_in_bounds.fixed +++ b/tests/ui/trait_duplication_in_bounds.fixed @@ -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 { } diff --git a/tests/ui/trait_duplication_in_bounds.rs b/tests/ui/trait_duplication_in_bounds.rs index ee84d3c3011..12db6b65a7a 100644 --- a/tests/ui/trait_duplication_in_bounds.rs +++ b/tests/ui/trait_duplication_in_bounds.rs @@ -192,5 +192,6 @@ trait AssocConstTrait { fn assoc_const_args<T>() where T: AssocConstTrait<ASSOC = 0> + AssocConstTrait<ASSOC = 0>, + //~^ trait_duplication_in_bounds { } diff --git a/tests/ui/trait_duplication_in_bounds.stderr b/tests/ui/trait_duplication_in_bounds.stderr index 0dd508e4745..83c06eaccd4 100644 --- a/tests/ui/trait_duplication_in_bounds.stderr +++ b/tests/ui/trait_duplication_in_bounds.stderr @@ -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 |
