This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +44
-11
lines changed
compiler/rustc_parse/src/parser
tests/ui/parser/attribute Expand file tree Collapse file tree 3 files changed +44
-11
lines changed Original file line number Diff line number Diff line change @@ -362,22 +362,18 @@ impl<'a> Parser<'a> {
362362 /// meta_item_inner : (meta_item | UNSUFFIXED_LIT) (',' meta_item_inner)? ;
363363 /// ```
364364 pub fn parse_meta_item ( & mut self ) -> PResult < ' a , ast:: MetaItem > {
365- let nt_meta = match & self . token . kind {
366- token:: Interpolated ( nt) => match & nt. 0 {
367- token:: NtMeta ( e) => Some ( e. clone ( ) ) ,
368- _ => None ,
369- } ,
370- _ => None ,
371- } ;
372-
373- if let Some ( item) = nt_meta {
374- match item. meta ( item. path . span ) {
365+ // We can't use `maybe_whole` here because it would bump in the `None`
366+ // case, which we don't want.
367+ if let token:: Interpolated ( nt) = & self . token . kind
368+ && let token:: NtMeta ( attr_item) = & nt. 0
369+ {
370+ match attr_item. meta ( attr_item. path . span ) {
375371 Some ( meta) => {
376372 self . bump ( ) ;
377373 return Ok ( meta) ;
378374 }
379375 None => self . unexpected ( ) ?,
380- } ;
376+ }
381377 }
382378
383379 let lo = self . token . span ;
Original file line number Diff line number Diff line change 1+ macro_rules! mac {
2+ ( $attr_item: meta) => {
3+ #[ cfg( $attr_item) ]
4+ //~^ ERROR expected unsuffixed literal or identifier, found `an(arbitrary token stream)`
5+ //~| ERROR expected unsuffixed literal or identifier, found `an(arbitrary token stream)`
6+ struct S ;
7+ }
8+ }
9+
10+ mac ! ( an( arbitrary token stream) ) ;
11+
12+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error: expected unsuffixed literal or identifier, found `an(arbitrary token stream)`
2+ --> $DIR/attr-bad-meta-4.rs:3:15
3+ |
4+ LL | #[cfg($attr_item)]
5+ | ^^^^^^^^^^
6+ ...
7+ LL | mac!(an(arbitrary token stream));
8+ | -------------------------------- in this macro invocation
9+ |
10+ = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
11+
12+ error: expected unsuffixed literal or identifier, found `an(arbitrary token stream)`
13+ --> $DIR/attr-bad-meta-4.rs:3:15
14+ |
15+ LL | #[cfg($attr_item)]
16+ | ^^^^^^^^^^
17+ ...
18+ LL | mac!(an(arbitrary token stream));
19+ | -------------------------------- in this macro invocation
20+ |
21+ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
22+ = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
23+
24+ error: aborting due to 2 previous errors
25+
You can’t perform that action at this time.
0 commit comments