File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
compiler/rustc_parse/src/parser Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -1210,7 +1210,8 @@ impl<'a> Parser<'a> {
12101210 fn parse_constness_ ( & mut self , case : Case , is_closure : bool ) -> Const {
12111211 // Avoid const blocks and const closures to be parsed as const items
12121212 if ( self . check_const_closure ( ) == is_closure)
1213- && self . look_ahead ( 1 , |t| t != & token:: OpenDelim ( Delimiter :: Brace ) )
1213+ && !self
1214+ . look_ahead ( 1 , |t| * t == token:: OpenDelim ( Delimiter :: Brace ) || t. is_whole_block ( ) )
12141215 && self . eat_keyword_case ( kw:: Const , case)
12151216 {
12161217 Const :: Yes ( self . prev_token . uninterpolated_span ( ) )
Original file line number Diff line number Diff line change 1+ // check-pass
2+
3+ #![ feature( inline_const) ]
4+
5+ // This used to be unsupported since the parser first tries to check if we have
6+ // any nested items, and then checks for statements (and expressions). The heuristic
7+ // that we were using to detect the beginning of a const item was incorrect, so
8+ // this used to fail.
9+ macro_rules! m {
10+ ( $b: block) => {
11+ fn foo( ) {
12+ const $b
13+ }
14+ }
15+ }
16+
17+ // This has worked since inline-consts were implemented, since the position that
18+ // the const block is located at doesn't support nested items (e.g. because
19+ // `let x = const X: u32 = 1;` is invalid), so there's no ambiguity parsing the
20+ // inline const.
21+ macro_rules! m2 {
22+ ( $b: block) => {
23+ fn foo2( ) {
24+ let _ = const $b;
25+ }
26+ }
27+ }
28+
29+ m ! ( { } ) ;
30+ m2 ! ( { } ) ;
31+
32+ fn main ( ) { }
You can’t perform that action at this time.
0 commit comments