Skip to content

Commit 18caf3b

Browse files
committed
Account for single where bound being removed
1 parent acee2c7 commit 18caf3b

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -5115,8 +5115,26 @@ fn point_at_assoc_type_restriction(
51155115
{
51165116
// The following block is to determine the right span to delete for this bound
51175117
// that will leave valid code after the suggestion is applied.
5118-
let span = if let Some(hir::WherePredicate::BoundPredicate(next)) =
5119-
predicates.peek()
5118+
let span = if pred.origin == hir::PredicateOrigin::WhereClause
5119+
&& generics
5120+
.predicates
5121+
.iter()
5122+
.filter(|p| {
5123+
if let hir::WherePredicate::BoundPredicate(p) = p
5124+
&& hir::PredicateOrigin::WhereClause == p.origin
5125+
{
5126+
true
5127+
} else {
5128+
false
5129+
}
5130+
})
5131+
.count()
5132+
== 1
5133+
{
5134+
// There's only one `where` bound, that needs to be removed. Remove the whole
5135+
// `where` clause.
5136+
generics.where_clause_span
5137+
} else if let Some(hir::WherePredicate::BoundPredicate(next)) = predicates.peek()
51205138
&& pred.origin == next.origin
51215139
{
51225140
// There's another bound, include the comma for the current one.

tests/ui/associated-types/impl-wf-cycle-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ LL | Self::A: Copy,
2020
| ---- unsatisfied trait bound introduced here
2121
help: associated type for the current `impl` cannot be restricted in `where` clauses, remove this bound
2222
|
23+
LL - where
2324
LL - Self::A: Copy,
24-
LL +
2525
|
2626

2727
error: aborting due to 1 previous error

tests/ui/associated-types/impl-wf-cycle-6.fixed

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ impl Grault for () {
1919

2020
impl<T: Grault> Grault for (T,)
2121
//~^ ERROR overflow evaluating the requirement `<(T,) as Grault>::A == _`
22-
where
23-
22+
2423
{
2524
type A = ();
2625
type B = bool;

tests/ui/associated-types/impl-wf-cycle-6.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ LL | Self::A: Baz,
2020
| --- unsatisfied trait bound introduced here
2121
help: associated type for the current `impl` cannot be restricted in `where` clauses, remove this bound
2222
|
23+
LL - where
2324
LL - Self::A: Baz,
24-
LL +
2525
|
2626

2727
error: aborting due to 1 previous error

0 commit comments

Comments
 (0)