@@ -138,38 +138,42 @@ impl<'a> AstValidator<'a> {
138
138
& mut self ,
139
139
ty_alias : & TyAlias ,
140
140
) -> Result < ( ) , errors:: WhereClauseBeforeTypeAlias > {
141
- let before_predicates =
142
- ty_alias. generics . where_clause . predicates . split_at ( ty_alias. where_clauses . split ) . 0 ;
143
-
144
- if ty_alias. ty . is_none ( ) || before_predicates. is_empty ( ) {
141
+ if ty_alias. ty . is_none ( ) || !ty_alias. where_clauses . before . has_where_token {
145
142
return Ok ( ( ) ) ;
146
143
}
147
144
148
- let mut state = State :: new ( ) ;
149
- if ! ty_alias. where_clauses . after . has_where_token {
150
- state . space ( ) ;
151
- state . word_space ( "where" ) ;
152
- } else {
153
- state . word_space ( "," ) ;
154
- }
155
- let mut first = true ;
156
- for p in before_predicates {
157
- if !first {
158
- state. word_space ( ", " ) ;
145
+ let ( before_predicates , after_predicates ) =
146
+ ty_alias. generics . where_clause . predicates . split_at ( ty_alias . where_clauses . split ) ;
147
+ let span = ty_alias . where_clauses . before . span ;
148
+
149
+ let sugg = if !before_predicates . is_empty ( ) || !ty_alias . where_clauses . after . has_where_token
150
+ {
151
+ let mut state = State :: new ( ) ;
152
+
153
+ if !ty_alias . where_clauses . after . has_where_token {
154
+ state . space ( ) ;
155
+ state. word_space ( "where " ) ;
159
156
}
160
- first = false ;
161
- state. print_where_predicate ( p) ;
162
- }
163
157
164
- let span = ty_alias. where_clauses . before . span ;
165
- Err ( errors:: WhereClauseBeforeTypeAlias {
166
- span,
167
- sugg : errors:: WhereClauseBeforeTypeAliasSugg {
158
+ let mut first = after_predicates. is_empty ( ) ;
159
+ for p in before_predicates {
160
+ if !first {
161
+ state. word_space ( "," ) ;
162
+ }
163
+ first = false ;
164
+ state. print_where_predicate ( p) ;
165
+ }
166
+
167
+ errors:: WhereClauseBeforeTypeAliasSugg :: Move {
168
168
left : span,
169
169
snippet : state. s . eof ( ) ,
170
170
right : ty_alias. where_clauses . after . span . shrink_to_hi ( ) ,
171
- } ,
172
- } )
171
+ }
172
+ } else {
173
+ errors:: WhereClauseBeforeTypeAliasSugg :: Remove { span }
174
+ } ;
175
+
176
+ Err ( errors:: WhereClauseBeforeTypeAlias { span, sugg } )
173
177
}
174
178
175
179
fn with_impl_trait ( & mut self , outer : Option < Span > , f : impl FnOnce ( & mut Self ) ) {
@@ -1476,15 +1480,18 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1476
1480
if let AssocItemKind :: Type ( ty_alias) = & item. kind
1477
1481
&& let Err ( err) = self . check_type_alias_where_clause_location ( ty_alias)
1478
1482
{
1483
+ let sugg = match err. sugg {
1484
+ errors:: WhereClauseBeforeTypeAliasSugg :: Remove { .. } => None ,
1485
+ errors:: WhereClauseBeforeTypeAliasSugg :: Move { snippet, right, .. } => {
1486
+ Some ( ( right, snippet) )
1487
+ }
1488
+ } ;
1479
1489
self . lint_buffer . buffer_lint_with_diagnostic (
1480
1490
DEPRECATED_WHERE_CLAUSE_LOCATION ,
1481
1491
item. id ,
1482
1492
err. span ,
1483
1493
fluent:: ast_passes_deprecated_where_clause_location,
1484
- BuiltinLintDiagnostics :: DeprecatedWhereclauseLocation (
1485
- err. sugg . right ,
1486
- err. sugg . snippet ,
1487
- ) ,
1494
+ BuiltinLintDiagnostics :: DeprecatedWhereclauseLocation ( sugg) ,
1488
1495
) ;
1489
1496
}
1490
1497
0 commit comments