Rollup merge of #69211 - petrochenkov:prevtok, r=Centril

parser: Simplify treatment of macro variables in `Parser::bump`

Follow-up to https://github.com/rust-lang/rust/pull/69006.

Token normalization for `$ident` and `$lifetime` is merged directly into `bump`.
Special "unknown macro variable" diagnostic for unexpected `$`s is removed as preventing legal code from compiling (as a result `bump` also doesn't call itself recursively anymore and can't make `prev_token` inconsistent).

r? @Centril
This commit is contained in:
Mazdak Farrokhzad 2020-02-18 22:16:28 +01:00 committed by GitHub
commit 1cf0194b46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 88 additions and 82 deletions

View file

@ -1,7 +1,7 @@
macro_rules! e {
($inp:ident) => (
$nonexistent
//~^ ERROR unknown macro variable `nonexistent`
//~^ ERROR expected expression, found `$`
);
}

View file

@ -1,8 +1,8 @@
error: unknown macro variable `nonexistent`
error: expected expression, found `$`
--> $DIR/issue-6596-1.rs:3:9
|
LL | $nonexistent
| ^^^^^^^^^^^^ unknown macro variable
| ^^^^^^^^^^^^ expected expression
...
LL | e!(foo);
| -------- in this macro invocation

View file

@ -3,7 +3,7 @@
macro_rules! g {
($inp:ident) => (
{ $inp $nonexistent }
//~^ ERROR unknown macro variable `nonexistent`
//~^ ERROR expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `$`
);
}

View file

@ -1,8 +1,8 @@
error: unknown macro variable `nonexistent`
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `$`
--> $DIR/issue-6596-2.rs:5:16
|
LL | { $inp $nonexistent }
| ^^^^^^^^^^^^ unknown macro variable
| ^^^^^^^^^^^^ expected one of 8 possible tokens
...
LL | g!(foo);
| -------- in this macro invocation

View file

@ -0,0 +1,17 @@
// force-host
// no-prefer-dynamic
#![feature(proc_macro_hygiene)]
#![feature(proc_macro_quote)]
#![crate_type = "proc-macro"]
extern crate proc_macro;
use proc_macro::*;
#[proc_macro]
pub fn dollar_ident(input: TokenStream) -> TokenStream {
let black_hole = input.into_iter().next().unwrap();
quote! {
$black_hole!($$var);
}
}

View file

@ -0,0 +1,18 @@
// Proc macros can generate token sequence `$ IDENT`
// without it being recognized as an unknown macro variable.
// check-pass
// aux-build:generate-dollar-ident.rs
extern crate generate_dollar_ident;
use generate_dollar_ident::*;
macro_rules! black_hole {
($($tt:tt)*) => {};
}
black_hole!($var);
dollar_ident!(black_hole);
fn main() {}