@@ -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_predicates_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 . 1 . 0 {
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 . 0 . 1 ;
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
- right : ty_alias. where_clauses . 1 . 1 . shrink_to_hi ( ) ,
171
- } ,
172
- } )
170
+ right : ty_alias. where_clauses . after . span . shrink_to_hi ( ) ,
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 ) ) {
@@ -457,8 +461,7 @@ impl<'a> AstValidator<'a> {
457
461
fn check_foreign_ty_genericless (
458
462
& self ,
459
463
generics : & Generics ,
460
- before_where_clause : & TyAliasWhereClause ,
461
- after_where_clause : & TyAliasWhereClause ,
464
+ where_clauses : & TyAliasWhereClauses ,
462
465
) {
463
466
let cannot_have = |span, descr, remove_descr| {
464
467
self . dcx ( ) . emit_err ( errors:: ExternTypesCannotHave {
@@ -473,14 +476,14 @@ impl<'a> AstValidator<'a> {
473
476
cannot_have ( generics. span , "generic parameters" , "generic parameters" ) ;
474
477
}
475
478
476
- let check_where_clause = |where_clause : & TyAliasWhereClause | {
477
- if let TyAliasWhereClause ( true , where_clause_span ) = where_clause {
478
- cannot_have ( * where_clause_span , "`where` clauses" , "`where` clause" ) ;
479
+ let check_where_clause = |where_clause : TyAliasWhereClause | {
480
+ if where_clause. has_where_token {
481
+ cannot_have ( where_clause . span , "`where` clauses" , "`where` clause" ) ;
479
482
}
480
483
} ;
481
484
482
- check_where_clause ( before_where_clause ) ;
483
- check_where_clause ( after_where_clause ) ;
485
+ check_where_clause ( where_clauses . before ) ;
486
+ check_where_clause ( where_clauses . after ) ;
484
487
}
485
488
486
489
fn check_foreign_kind_bodyless ( & self , ident : Ident , kind : & str , body : Option < Span > ) {
@@ -1122,9 +1125,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1122
1125
if let Err ( err) = self . check_type_alias_where_clause_location ( ty_alias) {
1123
1126
self . dcx ( ) . emit_err ( err) ;
1124
1127
}
1125
- } else if where_clauses. 1 . 0 {
1128
+ } else if where_clauses. after . has_where_token {
1126
1129
self . dcx ( ) . emit_err ( errors:: WhereClauseAfterTypeAlias {
1127
- span : where_clauses. 1 . 1 ,
1130
+ span : where_clauses. after . span ,
1128
1131
help : self . session . is_nightly_build ( ) . then_some ( ( ) ) ,
1129
1132
} ) ;
1130
1133
}
@@ -1154,7 +1157,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1154
1157
self . check_defaultness ( fi. span , * defaultness) ;
1155
1158
self . check_foreign_kind_bodyless ( fi. ident , "type" , ty. as_ref ( ) . map ( |b| b. span ) ) ;
1156
1159
self . check_type_no_bounds ( bounds, "`extern` blocks" ) ;
1157
- self . check_foreign_ty_genericless ( generics, & where_clauses. 0 , & where_clauses . 1 ) ;
1160
+ self . check_foreign_ty_genericless ( generics, where_clauses) ;
1158
1161
self . check_foreign_item_ascii_only ( fi. ident ) ;
1159
1162
}
1160
1163
ForeignItemKind :: Static ( _, _, body) => {
@@ -1477,15 +1480,18 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1477
1480
if let AssocItemKind :: Type ( ty_alias) = & item. kind
1478
1481
&& let Err ( err) = self . check_type_alias_where_clause_location ( ty_alias)
1479
1482
{
1483
+ let sugg = match err. sugg {
1484
+ errors:: WhereClauseBeforeTypeAliasSugg :: Remove { .. } => None ,
1485
+ errors:: WhereClauseBeforeTypeAliasSugg :: Move { snippet, right, .. } => {
1486
+ Some ( ( right, snippet) )
1487
+ }
1488
+ } ;
1480
1489
self . lint_buffer . buffer_lint_with_diagnostic (
1481
1490
DEPRECATED_WHERE_CLAUSE_LOCATION ,
1482
1491
item. id ,
1483
1492
err. span ,
1484
1493
fluent:: ast_passes_deprecated_where_clause_location,
1485
- BuiltinLintDiagnostics :: DeprecatedWhereclauseLocation (
1486
- err. sugg . right ,
1487
- err. sugg . snippet ,
1488
- ) ,
1494
+ BuiltinLintDiagnostics :: DeprecatedWhereclauseLocation ( sugg) ,
1489
1495
) ;
1490
1496
}
1491
1497
0 commit comments