@@ -5100,11 +5100,14 @@ fn point_at_assoc_type_restriction(
5100
5100
return ;
5101
5101
} ;
5102
5102
let name = tcx. item_name ( proj. projection_ty . def_id ) ;
5103
- for pred in generics. predicates {
5103
+ let mut predicates = generics. predicates . iter ( ) . peekable ( ) ;
5104
+ let mut prev: Option < & hir:: WhereBoundPredicate < ' _ > > = None ;
5105
+ while let Some ( pred) = predicates. next ( ) {
5104
5106
let hir:: WherePredicate :: BoundPredicate ( pred) = pred else {
5105
5107
continue ;
5106
5108
} ;
5107
- for bound in pred. bounds {
5109
+ let mut bounds = pred. bounds . iter ( ) . peekable ( ) ;
5110
+ while let Some ( bound) = bounds. next ( ) {
5108
5111
let Some ( trait_ref) = bound. trait_ref ( ) else {
5109
5112
continue ;
5110
5113
} ;
@@ -5118,8 +5121,27 @@ fn point_at_assoc_type_restriction(
5118
5121
&& let hir:: QPath :: Resolved ( None , inner_path) = inner_path
5119
5122
&& let Res :: SelfTyAlias { .. } = inner_path. res
5120
5123
{
5124
+ // The following block is to determine the right span to delete for this bound
5125
+ // that will leave valid code after the suggestion is applied.
5126
+ let span = if let Some ( hir:: WherePredicate :: BoundPredicate ( next) ) =
5127
+ predicates. peek ( )
5128
+ && pred. origin == next. origin
5129
+ {
5130
+ // There's another bound, include the comma for the current one.
5131
+ pred. span . until ( next. span )
5132
+ } else if let Some ( prev) = prev
5133
+ && pred. origin == prev. origin
5134
+ {
5135
+ // Last bound, try to remove the previous comma.
5136
+ prev. span . shrink_to_hi ( ) . to ( pred. span )
5137
+ } else if pred. origin == hir:: PredicateOrigin :: WhereClause {
5138
+ pred. span . with_hi ( generics. where_clause_span . hi ( ) )
5139
+ } else {
5140
+ pred. span
5141
+ } ;
5142
+
5121
5143
err. span_suggestion_verbose (
5122
- pred . span , // FIXME: include the trailing comma.
5144
+ span,
5123
5145
"associated type for the current `impl` cannot be restricted in `where` \
5124
5146
clauses, remove this bound",
5125
5147
"" ,
@@ -5168,6 +5190,7 @@ fn point_at_assoc_type_restriction(
5168
5190
) ;
5169
5191
}
5170
5192
}
5193
+ prev = Some ( pred) ;
5171
5194
}
5172
5195
}
5173
5196
0 commit comments