-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle
None
-delimited groups when parsing macro_rules!
macro
When a `macro_rules!` macro expands to another `macro_rules!` macro, we may see `None`-delimited groups in odd places when another crate deserializes the 'inner' macro. This commit 'unwraps' an outer `None`-delimited group to avoid breaking existing code. See #73569 (comment) for more details. The proper fix is to handle `None`-delimited groups systematically throughout the parser, but that will require significant work. In the meantime, this hack lets us fix important hygiene bugs in macros
- Loading branch information
Showing
3 changed files
with
87 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
macro_rules! produce_it { | ||
($dollar_one:tt $foo:ident $my_name:ident) => { | ||
#[macro_export] | ||
macro_rules! meta_delim { | ||
($dollar_one ($dollar_one $my_name:ident)*) => { | ||
stringify!($dollar_one ($dollar_one $my_name)*) | ||
} | ||
} | ||
} | ||
} | ||
|
||
produce_it!($my_name name); |
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,12 @@ | ||
// aux-build:meta-delim.rs | ||
// edition:2018 | ||
// run-pass | ||
|
||
// Tests that we can properly deserialize a macro with strange delimiters | ||
// See https://github.com/rust-lang/rust/pull/73569#issuecomment-650860457 | ||
|
||
extern crate meta_delim; | ||
|
||
fn main() { | ||
assert_eq!("a bunch of idents", meta_delim::meta_delim!(a bunch of idents)); | ||
} |