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:
commit
1cf0194b46
13 changed files with 88 additions and 82 deletions
|
|
@ -1,7 +1,7 @@
|
|||
macro_rules! e {
|
||||
($inp:ident) => (
|
||||
$nonexistent
|
||||
//~^ ERROR unknown macro variable `nonexistent`
|
||||
//~^ ERROR expected expression, found `$`
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
macro_rules! g {
|
||||
($inp:ident) => (
|
||||
{ $inp $nonexistent }
|
||||
//~^ ERROR unknown macro variable `nonexistent`
|
||||
//~^ ERROR expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `$`
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
17
src/test/ui/proc-macro/auxiliary/generate-dollar-ident.rs
Normal file
17
src/test/ui/proc-macro/auxiliary/generate-dollar-ident.rs
Normal 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);
|
||||
}
|
||||
}
|
||||
18
src/test/ui/proc-macro/generate-dollar-ident.rs
Normal file
18
src/test/ui/proc-macro/generate-dollar-ident.rs
Normal 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() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue