mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 15:01:51 +00:00
Test basic hygiene for macro_rules
produced by transparent macros
This commit is contained in:
parent
b39e188dda
commit
d80be3b4ff
23
src/test/ui/proc-macro/auxiliary/gen-macro-rules-hygiene.rs
Normal file
23
src/test/ui/proc-macro/auxiliary/gen-macro-rules-hygiene.rs
Normal 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()
|
||||
}
|
23
src/test/ui/proc-macro/gen-macro-rules-hygiene.rs
Normal file
23
src/test/ui/proc-macro/gen-macro-rules-hygiene.rs
Normal 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
|
||||
}
|
||||
}
|
28
src/test/ui/proc-macro/gen-macro-rules-hygiene.stderr
Normal file
28
src/test/ui/proc-macro/gen-macro-rules-hygiene.stderr
Normal 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`.
|
Loading…
Reference in New Issue
Block a user