Rewrite parse_meta_item
.
It can't use `maybe_whole`, but it can match `maybe_whole` more closely. Also add a test for a case that wasn't previously covered.
This commit is contained in:
parent
d919dbe370
commit
8ac16c6193
3 changed files with 44 additions and 11 deletions
|
@ -362,22 +362,18 @@ impl<'a> Parser<'a> {
|
|||
/// meta_item_inner : (meta_item | UNSUFFIXED_LIT) (',' meta_item_inner)? ;
|
||||
/// ```
|
||||
pub fn parse_meta_item(&mut self) -> PResult<'a, ast::MetaItem> {
|
||||
let nt_meta = match &self.token.kind {
|
||||
token::Interpolated(nt) => match &nt.0 {
|
||||
token::NtMeta(e) => Some(e.clone()),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
|
||||
if let Some(item) = nt_meta {
|
||||
match item.meta(item.path.span) {
|
||||
// We can't use `maybe_whole` here because it would bump in the `None`
|
||||
// case, which we don't want.
|
||||
if let token::Interpolated(nt) = &self.token.kind
|
||||
&& let token::NtMeta(attr_item) = &nt.0
|
||||
{
|
||||
match attr_item.meta(attr_item.path.span) {
|
||||
Some(meta) => {
|
||||
self.bump();
|
||||
return Ok(meta);
|
||||
}
|
||||
None => self.unexpected()?,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
let lo = self.token.span;
|
||||
|
|
12
tests/ui/parser/attribute/attr-bad-meta-4.rs
Normal file
12
tests/ui/parser/attribute/attr-bad-meta-4.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
macro_rules! mac {
|
||||
($attr_item: meta) => {
|
||||
#[cfg($attr_item)]
|
||||
//~^ ERROR expected unsuffixed literal or identifier, found `an(arbitrary token stream)`
|
||||
//~| ERROR expected unsuffixed literal or identifier, found `an(arbitrary token stream)`
|
||||
struct S;
|
||||
}
|
||||
}
|
||||
|
||||
mac!(an(arbitrary token stream));
|
||||
|
||||
fn main() {}
|
25
tests/ui/parser/attribute/attr-bad-meta-4.stderr
Normal file
25
tests/ui/parser/attribute/attr-bad-meta-4.stderr
Normal file
|
@ -0,0 +1,25 @@
|
|||
error: expected unsuffixed literal or identifier, found `an(arbitrary token stream)`
|
||||
--> $DIR/attr-bad-meta-4.rs:3:15
|
||||
|
|
||||
LL | #[cfg($attr_item)]
|
||||
| ^^^^^^^^^^
|
||||
...
|
||||
LL | mac!(an(arbitrary token stream));
|
||||
| -------------------------------- in this macro invocation
|
||||
|
|
||||
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: expected unsuffixed literal or identifier, found `an(arbitrary token stream)`
|
||||
--> $DIR/attr-bad-meta-4.rs:3:15
|
||||
|
|
||||
LL | #[cfg($attr_item)]
|
||||
| ^^^^^^^^^^
|
||||
...
|
||||
LL | mac!(an(arbitrary token stream));
|
||||
| -------------------------------- in this macro invocation
|
||||
|
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue