8000 Rollup of 4 pull requests by Centril · Pull Request #65430 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Rollup of 4 pull requests #65430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Test basic hygiene for macro_rules produced by transparent macros
  • Loading branch information
petrochenkov committed Oct 15, 2019
commit d80be3b4ff49583d94dea89b1b9bd06a013f43d6
23 changes: 23 additions & 0 deletions src/test/ui/proc-macro/auxiliary/gen-macro-rules-hygiene.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 23 additions & 0 deletions src/test/ui/proc-macro/gen-macro-rules-hygiene.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 28 additions & 0 deletions src/test/ui/proc-macro/gen-macro-rules-hygiene.stderr
Original file line number Diff line number Diff line change
@@ -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`.
0