Test basic hygiene for macro_rules produced by transparent macros

This commit is contained in:
Vadim Petrochenkov 2019-09-22 16:35:28 +03:00
parent b39e188dda
commit d80be3b4ff
3 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1,23 @@
// force-host
// no-prefer-dynamic
#![crate_type = "proc-macro"]
extern crate proc_macro;
use proc_macro::*;
#[proc_macro]
pub fn gen_macro_rules(_: TokenStream) -> TokenStream {
"
macro_rules! generated {() => {
struct ItemDef;
let local_def = 0;
ItemUse; // OK
local_use; // ERROR
break 'label_use; // ERROR
type DollarCrate = $crate::ItemUse; // OK
}}
".parse().unwrap()
}

View File

@ -0,0 +1,23 @@
// `macro_rules` items produced by transparent macros have correct hygiene in basic cases.
// Local variables and labels are hygienic, items are not hygienic.
// `$crate` refers to the crate that defines `macro_rules` and not the outer transparent macro.
// aux-build:gen-macro-rules-hygiene.rs
#[macro_use]
extern crate gen_macro_rules_hygiene;
struct ItemUse;
gen_macro_rules!();
//~^ ERROR use of undeclared label `'label_use`
//~| ERROR cannot find value `local_use` in this scope
fn main() {
'label_use: loop {
let local_use = 1;
generated!();
ItemDef; // OK
local_def; //~ ERROR cannot find value `local_def` in this scope
}
}

View File

@ -0,0 +1,28 @@
error[E0426]: use of undeclared label `'label_use`
--> $DIR/gen-macro-rules-hygiene.rs:12:1
|
LL | gen_macro_rules!();
| ^^^^^^^^^^^^^^^^^^^ undeclared label `'label_use`
...
LL | generated!();
| ------------- in this macro invocation
error[E0425]: cannot find value `local_use` in this scope
--> $DIR/gen-macro-rules-hygiene.rs:12:1
|
LL | gen_macro_rules!();
| ^^^^^^^^^^^^^^^^^^^ not found in this scope
...
LL | generated!();
| ------------- in this macro invocation
error[E0425]: cannot find value `local_def` in this scope
--> $DIR/gen-macro-rules-hygiene.rs:21:9
|
LL | local_def;
| ^^^^^^^^^ not found in this scope
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0425, E0426.
For more information about an error, try `rustc --explain E0425`.