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#68746 - matthewjasper:metahygiene, r=petroc…
…henkov Make macro metavars respect (non-)hygiene This makes them more consistent with other name resolution while not breaking any code on crater.
- Loading branch information
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)); | ||
} |