@@ -5047,11 +5047,14 @@ fn point_at_assoc_type_restriction(
5047
5047
return ;
5048
5048
} ;
5049
5049
let name = tcx. item_name ( proj. projection_ty . def_id ) ;
5050
- for pred in generics. predicates {
5050
+ let mut predicates = generics. predicates . iter ( ) . peekable ( ) ;
5051
+ let mut prev: Option < & hir:: WhereBoundPredicate < ' _ > > = None ;
5052
+ while let Some ( pred) = predicates. next ( ) {
5051
5053
let hir:: WherePredicate :: BoundPredicate ( pred) = pred else {
5052
5054
continue ;
5053
5055
} ;
5054
- for bound in pred. bounds {
5056
+ let mut bounds = pred. bounds . iter ( ) . peekable ( ) ;
5057
+ while let Some ( bound) = bounds. next ( ) {
5055
5058
let Some ( trait_ref) = bound. trait_ref ( ) else {
5056
5059
continue ;
5057
5060
} ;
@@ -5065,8 +5068,27 @@ fn point_at_assoc_type_restriction(
5065
5068
&& let hir:: QPath :: Resolved ( None , inner_path) = inner_path
5066
5069
&& let Res :: SelfTyAlias { .. } = inner_path. res
5067
5070
{
5071
+ // The following block is to determine the right span to delete for this bound
5072
+ // that will leave valid code after the suggestion is applied.
5073
+ let span = if let Some ( hir:: WherePredicate :: BoundPredicate ( next) ) =
5074
+ predicates. peek ( )
5075
+ && pred. origin == next. origin
5076
+ {
5077
+ // There's another bound, include the comma for the current one.
5078
+ pred. span . until ( next. span )
5079
+ } else if let Some ( prev) = prev
5080
+ && pred. origin == prev. origin
5081
+ {
5082
+ // Last bound, try to remove the previous comma.
5083
+ prev. span . shrink_to_hi ( ) . to ( pred. span )
5084
+ } else if pred. origin == hir:: PredicateOrigin :: WhereClause {
5085
+ pred. span . with_hi ( generics. where_clause_span . hi ( ) )
5086
+ } else {
5087
+ pred. span
5088
+ } ;
5089
+
5068
5090
err. span_suggestion_verbose (
5069
- pred . span , // FIXME: include the trailing comma.
5091
+ span,
5070
5092
"associated type for the current `impl` cannot be restricted in `where` \
5071
5093
clauses, remove this bound",
5072
5094
"" ,
@@ -5115,6 +5137,7 @@ fn point_at_assoc_type_restriction(
5115
5137
) ;
5116
5138
}
5117
5139
}
5140
+ prev = Some ( pred) ;
5118
5141
}
5119
5142
}
5120
5143
0 commit comments