Make macro metavars respect (non-)hygiene

This commit is contained in:
Matthew Jasper 2020-03-11 20:05:19 +00:00
parent 59f4ba9504
commit ec862703fd
7 changed files with 111 additions and 24 deletions

View 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));
}

View 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));
}