-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make macro metavars respect (non-)hygiene
- Loading branch information
1 parent
c20d7ee
commit 2f145f6
Showing
7 changed files
with
111 additions
and
24 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
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,29 @@ | ||
// Ensure macro metavariables are compared with legacy hygiene | ||
|
||
#![feature(rustc_attrs)] | ||
|
||
// run-pass | ||
|
||
macro_rules! make_mac { | ||
( $($dollar:tt $arg:ident),+ ) => { | ||
macro_rules! mac { | ||
( $($dollar $arg : ident),+ ) => { | ||
$( $dollar $arg )-+ | ||
} | ||
} | ||
} | ||
} | ||
|
||
macro_rules! show_hygiene { | ||
( $dollar:tt $arg:ident ) => { | ||
make_mac!($dollar $arg, $dollar arg); | ||
} | ||
} | ||
|
||
show_hygiene!( $arg ); | ||
|
||
fn main() { | ||
let x = 5; | ||
let y = 3; | ||
assert_eq!(2, mac!(x, y)); | ||
} |
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,24 @@ | ||
// Ensure macro metavariables are not compared without removing transparent | ||
// marks. | ||
|
||
#![feature(rustc_attrs)] | ||
|
||
// run-pass | ||
|
||
#[rustc_macro_transparency = "transparent"] | ||
macro_rules! k { | ||
($($s:tt)*) => { | ||
macro_rules! m { | ||
($y:tt) => { | ||
$($s)* | ||
} | ||
} | ||
} | ||
} | ||
|
||
k!(1 + $y); | ||
|
||
fn main() { | ||
let x = 2; | ||
assert_eq!(3, m!(x)); | ||
} |