@@ -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) ;
@@ -126,19 +126,19 @@ impl<'a> Parser<'a> {
126126 pub fn parse_item (
127127 & mut self ,
128128 force_collect : ForceCollect ,
129- const_block_items_allowed : ConstBlockItemsAllowed ,
129+ allow_const_block_items : AllowConstBlockItems ,
130130 ) -> PResult < ' a , Option < Box < Item > > > {
131131 let fn_parse_mode =
132132 FnParseMode { req_name : |_, _| true , context : FnContext :: Free , req_body : true } ;
133- self . parse_item_ ( fn_parse_mode, force_collect, const_block_items_allowed )
133+ self . parse_item_ ( fn_parse_mode, force_collect, allow_const_block_items )
134134 . map ( |i| i. map ( Box :: new) )
135135 }
136136
137137 fn parse_item_ (
138138 & mut self ,
139139 fn_parse_mode : FnParseMode ,
140140 force_collect : ForceCollect ,
141- const_block_items_allowed : ConstBlockItemsAllowed ,
141+ const_block_items_allowed : AllowConstBlockItems ,
142142 ) -> PResult < ' a , Option < Item > > {
143143 self . recover_vcs_conflict_marker ( ) ;
144144 let attrs = self . parse_outer_attributes ( ) ?;
@@ -160,10 +160,10 @@ impl<'a> Parser<'a> {
160160 attrs_allowed : bool ,
161161 fn_parse_mode : FnParseMode ,
162162 force_collect : ForceCollect ,
163- const_block_items_allowed : ConstBlockItemsAllowed ,
163+ allow_const_block_items : AllowConstBlockItems ,
164164 ) -> PResult < ' a , Option < Item > > {
165165 if let Some ( item) = self . eat_metavar_seq ( MetaVarKind :: Item , |this| {
166- this. parse_item ( ForceCollect :: Yes , const_block_items_allowed )
166+ this. parse_item ( ForceCollect :: Yes , allow_const_block_items )
167167 } ) {
168168 let mut item = item. expect ( "an actual item" ) ;
169169 attrs. prepend_to_nt_inner ( & mut item. attrs ) ;
@@ -177,7 +177,7 @@ impl<'a> Parser<'a> {
177177 let kind = this. parse_item_kind (
178178 & mut attrs,
179179 mac_allowed,
180- const_block_items_allowed ,
180+ allow_const_block_items ,
181181 lo,
182182 & vis,
183183 & mut def,
@@ -224,7 +224,7 @@ impl<'a> Parser<'a> {
224224 & mut self ,
225225 attrs : & mut AttrVec ,
226226 macros_allowed : bool ,
227- const_block_items_allowed : ConstBlockItemsAllowed ,
227+ allow_const_block_items : AllowConstBlockItems ,
228228 lo : Span ,
229229 vis : & Visibility ,
230230 def : & mut Defaultness ,
@@ -273,12 +273,16 @@ impl<'a> Parser<'a> {
273273 } else if self . check_impl_frontmatter ( 0 ) {
274274 // IMPL ITEM
275275 self . parse_item_impl ( attrs, def_ ( ) , false ) ?
276- } else if let ConstBlockItemsAllowed :: Yes = const_block_items_allowed
276+ } else if let AllowConstBlockItems :: Yes | AllowConstBlockItems :: DoesNotMatter =
277+ allow_const_block_items
277278 && self . token . is_keyword ( kw:: Const )
278279 && self . look_ahead ( 1 , |t| * t == token:: OpenBrace || t. is_metavar_block ( ) )
279280 {
280281 // CONST BLOCK ITEM
281282 self . psess . gated_spans . gate ( sym:: const_block_items, self . token . span ) ;
283+ if let AllowConstBlockItems :: DoesNotMatter = allow_const_block_items {
284+ debug ! ( "Parsing a const block item that does not matter: {:?}" , self . token. span) ;
285+ } ;
282286 ItemKind :: ConstBlock ( ConstBlockItem { body : self . parse_expr ( ) ? } )
283287 } else if let Const :: Yes ( const_span) = self . parse_constness ( case) {
284288 // CONST ITEM
@@ -339,7 +343,7 @@ impl<'a> Parser<'a> {
339343 return self . parse_item_kind (
340344 attrs,
341345 macros_allowed,
342- const_block_items_allowed ,
346+ allow_const_block_items ,
343347 lo,
344348 vis,
345349 def,
@@ -1092,8 +1096,13 @@ impl<'a> Parser<'a> {
10921096 fn_parse_mode : FnParseMode ,
10931097 force_collect : ForceCollect ,
10941098 ) -> PResult < ' a , Option < Option < Box < AssocItem > > > > {
1095- Ok ( self . parse_item_ ( fn_parse_mode, force_collect, ConstBlockItemsAllowed :: No ) ?. map (
1096- |Item { attrs, id, span, vis, kind, tokens } | {
1099+ Ok ( self
1100+ . parse_item_ (
1101+ fn_parse_mode,
1102+ force_collect,
1103+ AllowConstBlockItems :: DoesNotMatter , // due to `AssocItemKind::try_from` below
1104+ ) ?
1105+ . map ( |Item { attrs, id, span, vis, kind, tokens } | {
10971106 let kind = match AssocItemKind :: try_from ( kind) {
10981107 Ok ( kind) => kind,
10991108 Err ( kind) => match kind {
@@ -1120,8 +1129,7 @@ impl<'a> Parser<'a> {
11201129 } ,
11211130 } ;
11221131 Some ( Box :: new ( Item { attrs, id, span, vis, kind, tokens } ) )
1123- } ,
1124- ) )
1132+ } ) )
11251133 }
11261134
11271135 /// Parses a `type` alias with the following grammar:
@@ -1344,8 +1352,13 @@ impl<'a> Parser<'a> {
13441352 context : FnContext :: Free ,
13451353 req_body : false ,
13461354 } ;
1347- Ok ( self . parse_item_ ( fn_parse_mode, force_collect, ConstBlockItemsAllowed :: No ) ?. map (
1348- |Item { attrs, id, span, vis, kind, tokens } | {
1355+ Ok ( self
1356+ . parse_item_ (
1357+ fn_parse_mode,
1358+ force_collect,
1359+ AllowConstBlockItems :: DoesNotMatter , // due to `ForeignItemKind::try_from` below
1360+ ) ?
1361+ . map ( |Item { attrs, id, span, vis, kind, tokens } | {
13491362 let kind = match ForeignItemKind :: try_from ( kind) {
13501363 Ok ( kind) => kind,
13511364 Err ( kind) => match kind {
@@ -1372,8 +1385,7 @@ impl<'a> Parser<'a> {
13721385 } ,
13731386 } ;
13741387 Some ( Box :: new ( Item { attrs, id, span, vis, kind, tokens } ) )
1375- } ,
1376- ) )
1388+ } ) )
13771389 }
13781390
13791391 fn error_bad_item_kind < T > ( & self , span : Span , kind : & ItemKind , ctx : & ' static str ) -> Option < T > {
@@ -2418,7 +2430,10 @@ impl<'a> Parser<'a> {
24182430 {
24192431 let kw_token = self . token ;
24202432 let kw_str = pprust:: token_to_string ( & kw_token) ;
2421- let item = self . parse_item ( ForceCollect :: No , ConstBlockItemsAllowed :: No ) ?;
2433+ let item = self . parse_item (
2434+ ForceCollect :: No ,
2435+ AllowConstBlockItems :: DoesNotMatter , // self.token != kw::Const
2436+ ) ?;
24222437 let mut item = item. unwrap ( ) . span ;
24232438 if self . token == token:: Comma {
24242439 item = item. to ( self . token . span ) ;
0 commit comments