Make macro metavars respect (non-)hygiene
This commit is contained in:
parent
59f4ba9504
commit
ec862703fd
7 changed files with 111 additions and 24 deletions
29
src/test/ui/hygiene/macro-metavars-legacy.rs
Normal file
29
src/test/ui/hygiene/macro-metavars-legacy.rs
Normal file
|
|
@ -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));
|
||||
}
|
||||
24
src/test/ui/hygiene/macro-metavars-transparent.rs
Normal file
24
src/test/ui/hygiene/macro-metavars-transparent.rs
Normal file
|
|
@ -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));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue