Skip to content

Commit be7148f

Browse files
committed
Account for single where bound being removed
1 parent 48bcad6 commit be7148f

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
@@ -5070,8 +5070,26 @@ fn point_at_assoc_type_restriction(
50705070
{
50715071
// The following block is to determine the right span to delete for this bound
50725072
// that will leave valid code after the suggestion is applied.
5073-
let span = if let Some(hir::WherePredicate::BoundPredicate(next)) =
5074-
predicates.peek()
5073+
let span = if pred.origin == hir::PredicateOrigin::WhereClause
5074+
&& generics
5075+
.predicates
5076+
.iter()
5077+
.filter(|p| {
5078+
if let hir::WherePredicate::BoundPredicate(p) = p
5079+
&& hir::PredicateOrigin::WhereClause == p.origin
5080+
{
5081+
true
5082+
} else {
5083+
false
5084+
}
5085+
})
5086+
.count()
5087+
== 1
5088+
{
5089+
// There's only one `where` bound, that needs to be removed. Remove the whole
5090+
// `where` clause.
5091+
generics.where_clause_span
5092+
} else if let Some(hir::WherePredicate::BoundPredicate(next)) = predicates.peek()
50755093
&& pred.origin == next.origin
50765094
{
50775095
// 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)