diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 1a5a84da9f5bf..8b68b08ffb160 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -5070,8 +5070,26 @@ fn point_at_assoc_type_restriction( { // The following block is to determine the right span to delete for this bound // that will leave valid code after the suggestion is applied. - let span = if let Some(hir::WherePredicate::BoundPredicate(next)) = - predicates.peek() + let span = if pred.origin == hir::PredicateOrigin::WhereClause + && generics + .predicates + .iter() + .filter(|p| { + if let hir::WherePredicate::BoundPredicate(p) = p + && hir::PredicateOrigin::WhereClause == p.origin + { + true + } else { + false + } + }) + .count() + == 1 + { + // There's only one `where` bound, that needs to be removed. Remove the whole + // `where` clause. + generics.where_clause_span + } else if let Some(hir::WherePredicate::BoundPredicate(next)) = predicates.peek() && pred.origin == next.origin { // There's another bound, include the comma for the current one. diff --git a/tests/ui/associated-types/impl-wf-cycle-2.stderr b/tests/ui/associated-types/impl-wf-cycle-2.stderr index 15d3f7579ea5a..9454d1d669792 100644 --- a/tests/ui/associated-types/impl-wf-cycle-2.stderr +++ b/tests/ui/associated-types/impl-wf-cycle-2.stderr @@ -20,8 +20,8 @@ LL | Self::A: Copy, | ---- unsatisfied trait bound introduced here help: associated type for the current `impl` cannot be restricted in `where` clauses, remove this bound | +LL - where LL - Self::A: Copy, -LL + | error: aborting due to 1 previous error diff --git a/tests/ui/associated-types/impl-wf-cycle-6.fixed b/tests/ui/associated-types/impl-wf-cycle-6.fixed index f98ae8523efcc..73ed64f7ce381 100644 --- a/tests/ui/associated-types/impl-wf-cycle-6.fixed +++ b/tests/ui/associated-types/impl-wf-cycle-6.fixed @@ -19,8 +19,7 @@ impl Grault for () { impl Grault for (T,) //~^ ERROR overflow evaluating the requirement `<(T,) as Grault>::A == _` -where - + { type A = (); type B = bool; diff --git a/tests/ui/associated-types/impl-wf-cycle-6.stderr b/tests/ui/associated-types/impl-wf-cycle-6.stderr index 074671585ffec..c9b5d8060be68 100644 --- a/tests/ui/associated-types/impl-wf-cycle-6.stderr +++ b/tests/ui/associated-types/impl-wf-cycle-6.stderr @@ -20,8 +20,8 @@ LL | Self::A: Baz, | --- unsatisfied trait bound introduced here help: associated type for the current `impl` cannot be restricted in `where` clauses, remove this bound | +LL - where LL - Self::A: Baz, -LL + | error: aborting due to 1 previous error