@@ -18,8 +18,9 @@ use rustc_ast::ptr::P;
1818use rustc_ast:: token:: { self , DelimToken , Token , TokenKind } ;
1919use rustc_ast:: tokenstream:: { self , DelimSpan , TokenStream , TokenTree , TreeAndSpacing } ;
2020use rustc_ast:: DUMMY_NODE_ID ;
21- use rustc_ast:: { self as ast, AttrStyle , AttrVec , Const , CrateSugar , Extern , Unsafe } ;
22- use rustc_ast:: { Async , MacArgs , MacDelimiter , Mutability , StrLit , Visibility , VisibilityKind } ;
21+ use rustc_ast:: { self as ast, AnonConst , AttrStyle , AttrVec , Const , CrateSugar , Extern , Unsafe } ;
22+ use rustc_ast:: { Async , Expr , ExprKind , MacArgs , MacDelimiter , Mutability , StrLit } ;
23+ use rustc_ast:: { Visibility , VisibilityKind } ;
2324use rustc_ast_pretty:: pprust;
2425use rustc_errors:: { struct_span_err, Applicability , DiagnosticBuilder , FatalError , PResult } ;
2526use rustc_session:: parse:: ParseSess ;
@@ -545,6 +546,11 @@ impl<'a> Parser<'a> {
545546 self . check_or_expected ( self . token . can_begin_const_arg ( ) , TokenType :: Const )
546547 }
547548
549+ fn check_inline_const ( & mut self ) -> bool {
550+ self . check_keyword ( kw:: Const )
551+ && self . look_ahead ( 1 , |t| t == & token:: OpenDelim ( DelimToken :: Brace ) )
552+ }
553+
548554 /// Checks to see if the next token is either `+` or `+=`.
549555 /// Otherwise returns `false`.
550556 fn check_plus ( & mut self ) -> bool {
@@ -864,13 +870,28 @@ impl<'a> Parser<'a> {
864870
865871 /// Parses constness: `const` or nothing.
866872 fn parse_constness ( & mut self ) -> Const {
867- if self . eat_keyword ( kw:: Const ) {
873+ // Avoid const blocks to be parsed as const items
874+ if self . look_ahead ( 1 , |t| t != & token:: OpenDelim ( DelimToken :: Brace ) )
875+ && self . eat_keyword ( kw:: Const )
876+ {
868877 Const :: Yes ( self . prev_token . uninterpolated_span ( ) )
869878 } else {
870879 Const :: No
871880 }
872881 }
873882
883+ /// Parses inline const expressions.
884+ fn parse_const_expr ( & mut self , span : Span ) -> PResult < ' a , P < Expr > > {
885+ self . sess . gated_spans . gate ( sym:: inline_const, span) ;
886+ self . eat_keyword ( kw:: Const ) ;
887+ let blk = self . parse_block ( ) ?;
888+ let anon_const = AnonConst {
889+ id : DUMMY_NODE_ID ,
890+ value : self . mk_expr ( blk. span , ExprKind :: Block ( blk, None ) , AttrVec :: new ( ) ) ,
891+ } ;
892+ Ok ( self . mk_expr ( span, ExprKind :: ConstBlock ( anon_const) , AttrVec :: new ( ) ) )
893+ }
894+
874895 /// Parses mutability (`mut` or nothing).
875896 fn parse_mutability ( & mut self ) -> Mutability {
876897 if self . eat_keyword ( kw:: Mut ) { Mutability :: Mut } else { Mutability :: Not }
0 commit comments