forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#64035 - petrochenkov:stabmacgen, r=eddyb
Stabilize proc macros generating `macro_rules` items Fn-like and attribute proc macros can now generate `macro_rules` items. cc rust-lang#54727
- Loading branch information
Showing
11 changed files
with
84 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/test/ui/proc-macro/auxiliary/gen-macro-rules-hygiene.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.