@@ -6,9 +6,7 @@ use rustc_ast::ast::*;
66use rustc_ast:: token:: { self , Delimiter , InvisibleOrigin , MetaVarKind , TokenKind } ;
77use rustc_ast:: tokenstream:: { DelimSpan , TokenStream , TokenTree } ;
88use rustc_ast:: util:: case:: Case ;
9- use rustc_ast:: {
10- attr, { self as ast} ,
11- } ;
9+ use rustc_ast:: { self as ast} ;
1210use rustc_ast_pretty:: pprust;
1311use rustc_errors:: codes:: * ;
1412use rustc_errors:: { Applicability , PResult , StashKey , inline_fluent, struct_span_code_err} ;
@@ -286,7 +284,7 @@ impl<'a> Parser<'a> {
286284 // CONST ITEM
287285 self . recover_const_mut ( const_span) ;
288286 self . recover_missing_kw_before_item ( ) ?;
289- let ( ident, generics, ty, rhs_kind) = self . parse_const_item ( false ) ?;
287+ let ( ident, generics, ty, rhs_kind) = self . parse_const_item ( false , const_span ) ?;
290288 ItemKind :: Const ( Box :: new ( ConstItem {
291289 defaultness : def_ ( ) ,
292290 ident,
@@ -307,7 +305,7 @@ impl<'a> Parser<'a> {
307305 // TYPE CONST (mgca)
308306 self . recover_const_mut ( const_span) ;
309307 self . recover_missing_kw_before_item ( ) ?;
310- let ( ident, generics, ty, rhs_kind) = self . parse_const_item ( true ) ?;
308+ let ( ident, generics, ty, rhs_kind) = self . parse_const_item ( true , const_span ) ?;
311309 // Make sure this is only allowed if the feature gate is enabled.
312310 // #![feature(mgca_type_const_syntax)]
313311 self . psess . gated_spans . gate ( sym:: mgca_type_const_syntax, lo. to ( const_span) ) ;
@@ -1545,6 +1543,7 @@ impl<'a> Parser<'a> {
15451543 fn parse_const_item (
15461544 & mut self ,
15471545 const_arg : bool ,
1546+ const_span : Span ,
15481547 ) -> PResult < ' a , ( Ident , Generics , Box < Ty > , ConstItemRhsKind ) > {
15491548 let ident = self . parse_ident_or_underscore ( ) ?;
15501549
@@ -1636,8 +1635,8 @@ impl<'a> Parser<'a> {
16361635
16371636 generics. where_clause = where_clause;
16381637
1639- if let Some ( recovered_rhs ) = self . try_recover_const_missing_semi ( & rhs) {
1640- return Ok ( ( ident, generics, ty, Some ( ConstItemRhs :: Body ( recovered_rhs ) ) ) ) ;
1638+ if let Some ( rhs ) = self . try_recover_const_missing_semi ( & rhs, const_span ) {
1639+ return Ok ( ( ident, generics, ty, ConstItemRhsKind :: Body { rhs : Some ( rhs ) } ) ) ;
16411640 }
16421641 self . expect_semi ( ) ?;
16431642
@@ -3499,17 +3498,23 @@ impl<'a> Parser<'a> {
34993498 /// (e.g., `foo() \n &bar` was parsed as `foo() & bar`).
35003499 ///
35013500 /// Returns a corrected expression if recovery is successful.
3502- fn try_recover_const_missing_semi ( & mut self , rhs : & Option < ConstItemRhs > ) -> Option < Box < Expr > > {
3501+ fn try_recover_const_missing_semi (
3502+ & mut self ,
3503+ rhs : & ConstItemRhsKind ,
3504+ const_span : Span ,
3505+ ) -> Option < Box < Expr > > {
35033506 if self . token == TokenKind :: Semi {
35043507 return None ;
35053508 }
3506- let Some ( ConstItemRhs :: Body ( rhs) ) = rhs else {
3509+ let ConstItemRhsKind :: Body { rhs : Some ( rhs) } = rhs else {
35073510 return None ;
35083511 } ;
35093512 if !self . in_fn_body || !self . may_recover ( ) || rhs. span . from_expansion ( ) {
35103513 return None ;
35113514 }
3512- if let Some ( ( span, guar) ) = self . missing_semi_from_binop ( "const" , rhs) {
3515+ if let Some ( ( span, guar) ) =
3516+ self . missing_semi_from_binop ( "const" , rhs, Some ( const_span. shrink_to_lo ( ) ) )
3517+ {
35133518 self . fn_body_missing_semi_guar = Some ( guar) ;
35143519 Some ( self . mk_expr ( span, ExprKind :: Err ( guar) ) )
35153520 } else {
0 commit comments