@@ -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,10 +155,10 @@ impl<'a> Parser<'a> {
155155 attrs_allowed : bool ,
156156 fn_parse_mode : FnParseMode ,
157157 force_collect : ForceCollect ,
158- const_block_items_allowed : ConstBlockItemsAllowed ,
158+ allow_const_block_items : AllowConstBlockItems ,
159159 ) -> PResult < ' a , Option < Item > > {
160160 if let Some ( item) = self . eat_metavar_seq ( MetaVarKind :: Item , |this| {
161- this. parse_item ( ForceCollect :: Yes , const_block_items_allowed )
161+ this. parse_item ( ForceCollect :: Yes , allow_const_block_items )
162162 } ) {
163163 let mut item = item. expect ( "an actual item" ) ;
164164 attrs. prepend_to_nt_inner ( & mut item. attrs ) ;
@@ -172,7 +172,7 @@ impl<'a> Parser<'a> {
172172 let kind = this. parse_item_kind (
173173 & mut attrs,
174174 mac_allowed,
175- const_block_items_allowed ,
175+ allow_const_block_items ,
176176 lo,
177177 & vis,
178178 & mut def,
@@ -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+ allow_const_block_items : AllowConstBlockItems ,
223223 lo : Span ,
224224 vis : & Visibility ,
225225 def : & mut Defaultness ,
@@ -267,12 +267,16 @@ impl<'a> Parser<'a> {
267267 } else if self . check_impl_frontmatter ( ) {
268268 // IMPL ITEM
269269 self . parse_item_impl ( attrs, def_ ( ) ) ?
270- } else if let ConstBlockItemsAllowed :: Yes = const_block_items_allowed
270+ } else if let AllowConstBlockItems :: Yes | AllowConstBlockItems :: DoesNotMatter =
271+ allow_const_block_items
271272 && self . token . is_keyword ( kw:: Const )
272273 && self . look_ahead ( 1 , |t| * t == token:: OpenBrace || t. is_metavar_block ( ) )
273274 {
274275 // CONST BLOCK ITEM
275276 self . psess . gated_spans . gate ( sym:: const_block_items, self . token . span ) ;
277+ if let AllowConstBlockItems :: DoesNotMatter = allow_const_block_items {
278+ debug ! ( "Parsing a const block item that does not matter: {:?}" , self . token. span) ;
279+ } ;
276280 ItemKind :: ConstBlock ( ConstBlockItem { body : self . parse_expr ( ) ? } )
277281 } else if let Const :: Yes ( const_span) = self . parse_constness ( case) {
278282 // CONST ITEM
@@ -333,7 +337,7 @@ impl<'a> Parser<'a> {
333337 return self . parse_item_kind (
334338 attrs,
335339 macros_allowed,
336- const_block_items_allowed ,
340+ allow_const_block_items ,
337341 lo,
338342 vis,
339343 def,
@@ -1014,8 +1018,13 @@ impl<'a> Parser<'a> {
10141018 fn_parse_mode : FnParseMode ,
10151019 force_collect : ForceCollect ,
10161020 ) -> PResult < ' a , Option < Option < Box < AssocItem > > > > {
1017- Ok ( self . parse_item_ ( fn_parse_mode, force_collect, ConstBlockItemsAllowed :: No ) ?. map (
1018- |Item { attrs, id, span, vis, kind, tokens } | {
1021+ Ok ( self
1022+ . parse_item_ (
1023+ fn_parse_mode,
1024+ force_collect,
1025+ AllowConstBlockItems :: DoesNotMatter , // due to `AssocItemKind::try_from` below
1026+ ) ?
1027+ . map ( |Item { attrs, id, span, vis, kind, tokens } | {
10191028 let kind = match AssocItemKind :: try_from ( kind) {
10201029 Ok ( kind) => kind,
10211030 Err ( kind) => match kind {
@@ -1042,8 +1051,7 @@ impl<'a> Parser<'a> {
10421051 } ,
10431052 } ;
10441053 Some ( Box :: new ( Item { attrs, id, span, vis, kind, tokens } ) )
1045- } ,
1046- ) )
1054+ } ) )
10471055 }
10481056
10491057 /// Parses a `type` alias with the following grammar:
@@ -1266,8 +1274,13 @@ impl<'a> Parser<'a> {
12661274 context : FnContext :: Free ,
12671275 req_body : false ,
12681276 } ;
1269- Ok ( self . parse_item_ ( fn_parse_mode, force_collect, ConstBlockItemsAllowed :: No ) ?. map (
1270- |Item { attrs, id, span, vis, kind, tokens } | {
1277+ Ok ( self
1278+ . parse_item_ (
1279+ fn_parse_mode,
1280+ force_collect,
1281+ AllowConstBlockItems :: DoesNotMatter , // due to `ForeignItemKind::try_from` below
1282+ ) ?
1283+ . map ( |Item { attrs, id, span, vis, kind, tokens } | {
12711284 let kind = match ForeignItemKind :: try_from ( kind) {
12721285 Ok ( kind) => kind,
12731286 Err ( kind) => match kind {
@@ -1294,8 +1307,7 @@ impl<'a> Parser<'a> {
12941307 } ,
12951308 } ;
12961309 Some ( Box :: new ( Item { attrs, id, span, vis, kind, tokens } ) )
1297- } ,
1298- ) )
1310+ } ) )
12991311 }
13001312
13011313 fn error_bad_item_kind < T > ( & self , span : Span , kind : & ItemKind , ctx : & ' static str ) -> Option < T > {
@@ -2331,7 +2343,10 @@ impl<'a> Parser<'a> {
23312343 {
23322344 let kw_token = self . token ;
23332345 let kw_str = pprust:: token_to_string ( & kw_token) ;
2334- let item = self . parse_item ( ForceCollect :: No , ConstBlockItemsAllowed :: No ) ?;
2346+ let item = self . parse_item (
2347+ ForceCollect :: No ,
2348+ AllowConstBlockItems :: DoesNotMatter , // self.token != kw::Const
2349+ ) ?;
23352350 let mut item = item. unwrap ( ) . span ;
23362351 if self . token == token:: Comma {
23372352 item = item. to ( self . token . span ) ;
0 commit comments