-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Handle macro_rules!
tokens consistently across crates
#73569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+395
−56
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,25 @@ | ||
// check-pass | ||
// Tests that we properly handle a nested macro expansion | ||
// involving a `#[doc]` attribute | ||
#![deny(missing_docs)] | ||
//! Crate docs | ||
macro_rules! doc_comment { | ||
($x:expr, $($tt:tt)*) => { | ||
#[doc = $x] | ||
$($tt)* | ||
} | ||
} | ||
|
||
macro_rules! make_comment { | ||
() => { | ||
doc_comment!("Function docs", | ||
pub fn bar() {} | ||
); | ||
} | ||
} | ||
|
||
|
||
make_comment!(); | ||
|
||
fn main() {} |
This file contains hidden or 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)*) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😱 |
||
stringify!($dollar_one ($dollar_one $my_name)*) | ||
} | ||
} | ||
} | ||
} | ||
|
||
produce_it!($my_name name); |
This file contains hidden or 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,15 @@ | ||
pub struct FirstStruct; | ||
|
||
#[macro_export] | ||
macro_rules! outer_macro { | ||
($name:ident) => { | ||
#[macro_export] | ||
macro_rules! inner_macro { | ||
($wrapper:ident) => { | ||
$wrapper!($name) | ||
} | ||
} | ||
} | ||
} | ||
|
||
outer_macro!(FirstStruct); |
This file contains hidden or 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 hidden or 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 hidden or 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)); | ||
} |
This file contains hidden or 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,20 @@ | ||
// run-pass | ||
// aux-build:nested-macro-rules.rs | ||
// aux-build:test-macros.rs | ||
// compile-flags: -Z span-debug | ||
// edition:2018 | ||
|
||
extern crate nested_macro_rules; | ||
extern crate test_macros; | ||
|
||
use test_macros::print_bang; | ||
|
||
use nested_macro_rules::FirstStruct; | ||
struct SecondStruct; | ||
|
||
fn main() { | ||
nested_macro_rules::inner_macro!(print_bang); | ||
|
||
nested_macro_rules::outer_macro!(SecondStruct); | ||
inner_macro!(print_bang); | ||
} |
This file contains hidden or 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,26 @@ | ||
PRINT-BANG INPUT (DISPLAY): FirstStruct | ||
PRINT-BANG INPUT (DEBUG): TokenStream [ | ||
Group { | ||
delimiter: None, | ||
stream: TokenStream [ | ||
Ident { | ||
ident: "FirstStruct", | ||
span: $DIR/auxiliary/nested-macro-rules.rs:15:14: 15:25 (#3), | ||
}, | ||
], | ||
span: $DIR/auxiliary/nested-macro-rules.rs:9:27: 9:32 (#3), | ||
}, | ||
] | ||
PRINT-BANG INPUT (DISPLAY): SecondStruct | ||
PRINT-BANG INPUT (DEBUG): TokenStream [ | ||
Group { | ||
delimiter: None, | ||
stream: TokenStream [ | ||
Ident { | ||
ident: "SecondStruct", | ||
span: $DIR/nested-macro-rules.rs:18:38: 18:50 (#9), | ||
}, | ||
], | ||
span: $DIR/auxiliary/nested-macro-rules.rs:9:27: 9:32 (#8), | ||
}, | ||
] |
This file contains hidden or 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,19 @@ | ||
// run-pass | ||
// aux-build:test-macros.rs | ||
// compile-flags: -Z span-debug | ||
// edition:2018 | ||
// | ||
// Tests the pretty-printing behavior of inserting `NoDelim` groups | ||
|
||
extern crate test_macros; | ||
use test_macros::print_bang_consume; | ||
|
||
macro_rules! expand_it { | ||
(($val1:expr) ($val2:expr)) => { expand_it!($val1 + $val2) }; | ||
($val:expr) => { print_bang_consume!("hi" $val (1 + 1)) }; | ||
} | ||
|
||
fn main() { | ||
expand_it!(1 + (25) + 1); | ||
expand_it!(("hello".len()) ("world".len())); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.