@@ -22,8 +22,8 @@ use tracing::debug;
2222use super :: diagnostics:: { ConsumeClosingDelim , dummy_arg} ;
2323use super :: ty:: { AllowPlus , RecoverQPath , RecoverReturnSign } ;
2424use super :: {
25- AttrWrapper , ConstBlockItemsAllowed , ExpKeywordPair , ExpTokenPair , FollowedByType ,
26- ForceCollect , Parser , PathStyle , Recovered , Trailing , UsePreAttrPos ,
25+ AllowConstBlockItems , AttrWrapper , ExpKeywordPair , ExpTokenPair , FollowedByType , ForceCollect ,
26+ Parser , PathStyle , Recovered , Trailing , UsePreAttrPos ,
2727} ;
2828use crate :: errors:: { self , FnPointerCannotBeAsync , FnPointerCannotBeConst , MacroExpandsToAdtField } ;
2929use crate :: { exp, fluent_generated as fluent} ;
@@ -69,7 +69,7 @@ impl<'a> Parser<'a> {
6969 // `parse_item` consumes the appropriate semicolons so any leftover is an error.
7070 loop {
7171 while self . maybe_consume_incorrect_semicolon ( items. last ( ) . map ( |x| & * * x) ) { } // Eat all bad semicolons
72- let Some ( item) = self . parse_item ( ForceCollect :: No , ConstBlockItemsAllowed :: Yes ) ? else {
72+ let Some ( item) = self . parse_item ( ForceCollect :: No , AllowConstBlockItems :: Yes ) ? else {
7373 break ;
7474 } ;
7575 items. push ( item) ;
@@ -121,19 +121,19 @@ impl<'a> Parser<'a> {
121121 pub fn parse_item (
122122 & mut self ,
123123 force_collect : ForceCollect ,
124- const_block_items_allowed : ConstBlockItemsAllowed ,
124+ allow_const_block_items : AllowConstBlockItems ,
125125 ) -> PResult < ' a , Option < Box < Item > > > {
126126 let fn_parse_mode =
127127 FnParseMode { req_name : |_, _| true , context : FnContext :: Free , req_body : true } ;
128- self . parse_item_ ( fn_parse_mode, force_collect, const_block_items_allowed )
128+ self . parse_item_ ( fn_parse_mode, force_collect, allow_const_block_items )
129129 . map ( |i| i. map ( Box :: new) )
130130 }
131131
132132 fn parse_item_ (
133133 & mut self ,
134134 fn_parse_mode : FnParseMode ,
135135 force_collect : ForceCollect ,
136- const_block_items_allowed : ConstBlockItemsAllowed ,
136+ const_block_items_allowed : AllowConstBlockItems ,
137137 ) -> PResult < ' a , Option < Item > > {
138138 self . recover_vcs_conflict_marker ( ) ;
139139 let attrs = self . parse_outer_attributes ( ) ?;
@@ -155,7 +155,7 @@ impl<'a> Parser<'a> {
155155 attrs_allowed : bool ,
156156 fn_parse_mode : FnParseMode ,
157157 force_collect : ForceCollect ,
158- const_block_items_allowed : ConstBlockItemsAllowed ,
158+ const_block_items_allowed : AllowConstBlockItems ,
159159 ) -> PResult < ' a , Option < Item > > {
160160 if let Some ( item) = self . eat_metavar_seq ( MetaVarKind :: Item , |this| {
161161 this. parse_item ( ForceCollect :: Yes , const_block_items_allowed)
@@ -219,7 +219,7 @@ impl<'a> Parser<'a> {
219219 & mut self ,
220220 attrs : & mut AttrVec ,
221221 macros_allowed : bool ,
222- const_block_items_allowed : ConstBlockItemsAllowed ,
222+ const_block_items_allowed : AllowConstBlockItems ,
223223 lo : Span ,
224224 vis : & Visibility ,
225225 def : & mut Defaultness ,
@@ -269,12 +269,16 @@ impl<'a> Parser<'a> {
269269 } else if self . check_impl_frontmatter ( ) {
270270 // IMPL ITEM
271271 self . parse_item_impl ( attrs, def_ ( ) ) ?
272- } else if let ConstBlockItemsAllowed :: Yes = const_block_items_allowed
272+ } else if let AllowConstBlockItems :: Yes | AllowConstBlockItems :: DoesNotMatter =
273+ const_block_items_allowed
273274 && self . token . is_keyword ( kw:: Const )
274275 && self . look_ahead ( 1 , |t| * t == token:: OpenBrace || t. is_metavar_block ( ) )
275276 {
276277 // CONST BLOCK ITEM
277278 self . psess . gated_spans . gate ( sym:: const_block_items, self . token . span ) ;
279+ if let AllowConstBlockItems :: DoesNotMatter = const_block_items_allowed {
280+ debug ! ( "Parsing a const block item that does not matter: {:?}" , self . token. span) ;
281+ } ;
278282 ItemKind :: ConstBlock ( ConstBlockItem { body : self . parse_expr ( ) ? } )
279283 } else if let Const :: Yes ( const_span) = self . parse_constness ( Case :: Sensitive ) {
280284 // CONST ITEM
@@ -1016,8 +1020,13 @@ impl<'a> Parser<'a> {
10161020 fn_parse_mode : FnParseMode ,
10171021 force_collect : ForceCollect ,
10181022 ) -> PResult < ' a , Option < Option < Box < AssocItem > > > > {
1019- Ok ( self . parse_item_ ( fn_parse_mode, force_collect, ConstBlockItemsAllowed :: No ) ?. map (
1020- |Item { attrs, id, span, vis, kind, tokens } | {
1023+ Ok ( self
1024+ . parse_item_ (
1025+ fn_parse_mode,
1026+ force_collect,
1027+ AllowConstBlockItems :: DoesNotMatter , // due to `AssocItemKind::try_from` below
1028+ ) ?
1029+ . map ( |Item { attrs, id, span, vis, kind, tokens } | {
10211030 let kind = match AssocItemKind :: try_from ( kind) {
10221031 Ok ( kind) => kind,
10231032 Err ( kind) => match kind {
@@ -1044,8 +1053,7 @@ impl<'a> Parser<'a> {
10441053 } ,
10451054 } ;
10461055 Some ( Box :: new ( Item { attrs, id, span, vis, kind, tokens } ) )
1047- } ,
1048- ) )
1056+ } ) )
10491057 }
10501058
10511059 /// Parses a `type` alias with the following grammar:
@@ -1268,8 +1276,13 @@ impl<'a> Parser<'a> {
12681276 context : FnContext :: Free ,
12691277 req_body : false ,
12701278 } ;
1271- Ok ( self . parse_item_ ( fn_parse_mode, force_collect, ConstBlockItemsAllowed :: No ) ?. map (
1272- |Item { attrs, id, span, vis, kind, tokens } | {
1279+ Ok ( self
1280+ . parse_item_ (
1281+ fn_parse_mode,
1282+ force_collect,
1283+ AllowConstBlockItems :: DoesNotMatter , // due to `ForeignItemKind::try_from` below
1284+ ) ?
1285+ . map ( |Item { attrs, id, span, vis, kind, tokens } | {
12731286 let kind = match ForeignItemKind :: try_from ( kind) {
12741287 Ok ( kind) => kind,
12751288 Err ( kind) => match kind {
@@ -1296,8 +1309,7 @@ impl<'a> Parser<'a> {
12961309 } ,
12971310 } ;
12981311 Some ( Box :: new ( Item { attrs, id, span, vis, kind, tokens } ) )
1299- } ,
1300- ) )
1312+ } ) )
13011313 }
13021314
13031315 fn error_bad_item_kind < T > ( & self , span : Span , kind : & ItemKind , ctx : & ' static str ) -> Option < T > {
@@ -2324,7 +2336,10 @@ impl<'a> Parser<'a> {
23242336 {
23252337 let kw_token = self . token ;
23262338 let kw_str = pprust:: token_to_string ( & kw_token) ;
2327- let item = self . parse_item ( ForceCollect :: No , ConstBlockItemsAllowed :: No ) ?;
2339+ let item = self . parse_item (
2340+ ForceCollect :: No ,
2341+ AllowConstBlockItems :: DoesNotMatter , // self.token != kw::Const
2342+ ) ?;
23282343 let mut item = item. unwrap ( ) . span ;
23292344 if self . token == token:: Comma {
23302345 item = item. to ( self . token . span ) ;
0 commit comments