@@ -136,40 +136,42 @@ impl<'a> AstValidator<'a> {
136
136
}
137
137
}
138
138
139
- fn check_gat_where (
139
+ fn check_type_alias_where_clause_location (
140
140
& mut self ,
141
- id : NodeId ,
142
- before_predicates : & [ WherePredicate ] ,
143
- where_clauses : ( ast:: TyAliasWhereClause , ast:: TyAliasWhereClause ) ,
144
- ) {
145
- if !before_predicates. is_empty ( ) {
146
- let mut state = State :: new ( ) ;
147
- if !where_clauses. 1 . 0 {
148
- state. space ( ) ;
149
- state. word_space ( "where" ) ;
150
- } else {
141
+ ty_alias : & TyAlias ,
142
+ ) -> Result < ( ) , errors:: WhereClauseBeforeTypeAlias > {
143
+ let before_predicates =
144
+ ty_alias. generics . where_clause . predicates . split_at ( ty_alias. where_predicates_split ) . 0 ;
145
+
146
+ if ty_alias. ty . is_none ( ) || before_predicates. is_empty ( ) {
147
+ return Ok ( ( ) ) ;
148
+ }
149
+
150
+ let mut state = State :: new ( ) ;
151
+ if !ty_alias. where_clauses . 1 . 0 {
152
+ state. space ( ) ;
153
+ state. word_space ( "where" ) ;
154
+ } else {
155
+ state. word_space ( "," ) ;
156
+ }
157
+ let mut first = true ;
158
+ for p in before_predicates {
159
+ if !first {
151
160
state. word_space ( "," ) ;
152
161
}
153
- let mut first = true ;
154
- for p in before_predicates. iter ( ) {
155
- if !first {
156
- state. word_space ( "," ) ;
157
- }
158
- first = false ;
159
- state. print_where_predicate ( p) ;
160
- }
161
- let suggestion = state. s . eof ( ) ;
162
- self . lint_buffer . buffer_lint_with_diagnostic (
163
- DEPRECATED_WHERE_CLAUSE_LOCATION ,
164
- id,
165
- where_clauses. 0 . 1 ,
166
- fluent:: ast_passes_deprecated_where_clause_location,
167
- BuiltinLintDiagnostics :: DeprecatedWhereclauseLocation (
168
- where_clauses. 1 . 1 . shrink_to_hi ( ) ,
169
- suggestion,
170
- ) ,
171
- ) ;
162
+ first = false ;
163
+ state. print_where_predicate ( p) ;
172
164
}
165
+
166
+ let span = ty_alias. where_clauses . 0 . 1 ;
167
+ Err ( errors:: WhereClauseBeforeTypeAlias {
168
+ span,
169
+ sugg : errors:: WhereClauseBeforeTypeAliasSugg {
170
+ left : span,
171
+ snippet : state. s . eof ( ) ,
172
+ right : ty_alias. where_clauses . 1 . 1 . shrink_to_hi ( ) ,
173
+ } ,
174
+ } )
173
175
}
174
176
175
177
fn with_impl_trait ( & mut self , outer : Option < Span > , f : impl FnOnce ( & mut Self ) ) {
@@ -1009,7 +1011,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1009
1011
replace_span : self . ending_semi_or_hi ( item. span ) ,
1010
1012
} ) ;
1011
1013
}
1012
- ItemKind :: TyAlias ( box TyAlias { defaultness, where_clauses, bounds, ty, .. } ) => {
1014
+ ItemKind :: TyAlias (
1015
+ ty_alias @ box TyAlias { defaultness, bounds, where_clauses, ty, .. } ,
1016
+ ) => {
1013
1017
self . check_defaultness ( item. span , * defaultness) ;
1014
1018
if ty. is_none ( ) {
1015
1019
self . session . emit_err ( errors:: TyAliasWithoutBody {
@@ -1018,9 +1022,16 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1018
1022
} ) ;
1019
1023
}
1020
1024
self . check_type_no_bounds ( bounds, "this context" ) ;
1021
- if where_clauses. 1 . 0 {
1022
- self . err_handler ( )
1023
- . emit_err ( errors:: WhereAfterTypeAlias { span : where_clauses. 1 . 1 } ) ;
1025
+
1026
+ if self . session . features_untracked ( ) . lazy_type_alias {
1027
+ if let Err ( err) = self . check_type_alias_where_clause_location ( ty_alias) {
1028
+ self . err_handler ( ) . emit_err ( err) ;
1029
+ }
1030
+ } else if where_clauses. 1 . 0 {
1031
+ self . err_handler ( ) . emit_err ( errors:: WhereClauseAfterTypeAlias {
1032
+ span : where_clauses. 1 . 1 ,
1033
+ help : self . session . is_nightly_build ( ) . then_some ( ( ) ) ,
1034
+ } ) ;
1024
1035
}
1025
1036
}
1026
1037
_ => { }
@@ -1313,18 +1324,18 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1313
1324
}
1314
1325
}
1315
1326
1316
- if let AssocItemKind :: Type ( box TyAlias {
1317
- generics,
1318
- where_clauses,
1319
- where_predicates_split,
1320
- ty : Some ( _) ,
1321
- ..
1322
- } ) = & item. kind
1327
+ if let AssocItemKind :: Type ( ty_alias) = & item. kind
1328
+ && let Err ( err) = self . check_type_alias_where_clause_location ( ty_alias)
1323
1329
{
1324
- self . check_gat_where (
1330
+ self . lint_buffer . buffer_lint_with_diagnostic (
1331
+ DEPRECATED_WHERE_CLAUSE_LOCATION ,
1325
1332
item. id ,
1326
- generics. where_clause . predicates . split_at ( * where_predicates_split) . 0 ,
1327
- * where_clauses,
1333
+ err. span ,
1334
+ fluent:: ast_passes_deprecated_where_clause_location,
1335
+ BuiltinLintDiagnostics :: DeprecatedWhereclauseLocation (
1336
+ err. sugg . right ,
1337
+ err. sugg . snippet ,
1338
+ ) ,
1328
1339
) ;
1329
1340
}
1330
1341
0 commit comments