@@ -138,38 +138,41 @@ impl<'a> AstValidator<'a> {
138138 & mut self ,
139139 ty_alias : & TyAlias ,
140140 ) -> 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 {
145142 return Ok ( ( ) ) ;
146143 }
147144
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 ( ) {
150+ let mut state = State :: new ( ) ;
151+
152+ if !ty_alias. where_clauses . after . has_where_token {
153+ state. space ( ) ;
154+ state. word_space ( "where" ) ;
159155 }
160- first = false ;
161- state. print_where_predicate ( p) ;
162- }
163156
164- let span = ty_alias. where_clauses . before . span ;
165- Err ( errors:: WhereClauseBeforeTypeAlias {
166- span,
167- sugg : errors:: WhereClauseBeforeTypeAliasSugg {
157+ let mut first = after_predicates. is_empty ( ) ;
158+ for p in before_predicates {
159+ if !first {
160+ state. word_space ( "," ) ;
161+ }
162+ first = false ;
163+ state. print_where_predicate ( p) ;
164+ }
165+
166+ errors:: WhereClauseBeforeTypeAliasSugg :: Move {
168167 left : span,
169168 snippet : state. s . eof ( ) ,
170169 right : ty_alias. where_clauses . after . span . shrink_to_hi ( ) ,
171- } ,
172- } )
170+ }
171+ } else {
172+ errors:: WhereClauseBeforeTypeAliasSugg :: Remove { span }
173+ } ;
174+
175+ Err ( errors:: WhereClauseBeforeTypeAlias { span, sugg } )
173176 }
174177
175178 fn with_impl_trait ( & mut self , outer : Option < Span > , f : impl FnOnce ( & mut Self ) ) {
@@ -1475,15 +1478,18 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
14751478 if let AssocItemKind :: Type ( ty_alias) = & item. kind
14761479 && let Err ( err) = self . check_type_alias_where_clause_location ( ty_alias)
14771480 {
1481+ let sugg = match err. sugg {
1482+ errors:: WhereClauseBeforeTypeAliasSugg :: Remove { .. } => None ,
1483+ errors:: WhereClauseBeforeTypeAliasSugg :: Move { snippet, right, .. } => {
1484+ Some ( ( right, snippet) )
1485+ }
1486+ } ;
14781487 self . lint_buffer . buffer_lint_with_diagnostic (
14791488 DEPRECATED_WHERE_CLAUSE_LOCATION ,
14801489 item. id ,
14811490 err. span ,
14821491 fluent:: ast_passes_deprecated_where_clause_location,
1483- BuiltinLintDiagnostics :: DeprecatedWhereclauseLocation (
1484- err. sugg . right ,
1485- err. sugg . snippet ,
1486- ) ,
1492+ BuiltinLintDiagnostics :: DeprecatedWhereclauseLocation ( sugg) ,
14871493 ) ;
14881494 }
14891495
0 commit comments