-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Add hygiene annotations for tokens in macro_rules! bodies
#153308
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
+174
−12
Merged
Changes from all commits
Commits
Show all changes
2 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| //@ check-pass | ||
| //@ compile-flags: -Zunpretty=expanded,hygiene | ||
|
|
||
| // Regression test for token hygiene annotations in -Zunpretty=expanded,hygiene | ||
| // Previously, metavar parameters in macro-generated macro_rules! definitions | ||
| // were missing hygiene annotations, making identical `$marg` bindings | ||
| // indistinguishable. | ||
|
|
||
| // Don't break whenever Symbol numbering changes | ||
| //@ normalize-stdout: "\d+#" -> "0#" | ||
|
|
||
| #![feature(no_core)] | ||
| #![no_core] | ||
|
|
||
| macro_rules! make_macro { | ||
| (@inner $name:ident ($dol:tt) $a:ident) => { | ||
| macro_rules! $name { | ||
| ($dol $a : expr, $dol marg : expr) => {} | ||
| } | ||
| }; | ||
| ($name:ident) => { | ||
| make_macro!{@inner $name ($) marg} | ||
| }; | ||
| } | ||
|
|
||
| make_macro!(add2); | ||
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,53 @@ | ||
| //@ check-pass | ||
| //@ compile-flags: -Zunpretty=expanded,hygiene | ||
|
|
||
| // Regression test for token hygiene annotations in -Zunpretty=expanded,hygiene | ||
| // Previously, metavar parameters in macro-generated macro_rules! definitions | ||
| // were missing hygiene annotations, making identical `$marg` bindings | ||
| // indistinguishable. | ||
|
|
||
| // Don't break whenever Symbol numbering changes | ||
| //@ normalize-stdout: "\d+#" -> "0#" | ||
|
|
||
| #![feature /* 0#0 */(no_core /* 0#0 */)] | ||
| #![no_core /* 0#0 */] | ||
|
|
||
| macro_rules! make_macro | ||
| /* | ||
| 0#0 | ||
| */ { | ||
| (@inner /* 0#0 */ $name /* 0#0 */:ident /* 0#0 | ||
| */($dol /* 0#0 */:tt /* 0#0 */) $a /* 0#0 */:ident /* 0#0 */) | ||
| => | ||
| { | ||
| macro_rules /* 0#0 */! $name /* 0#0 */ | ||
| { | ||
| ($dol /* 0#0 */ $a /* 0#0 */ : expr /* 0#0 */, $dol /* | ||
| 0#0 */ marg /* 0#0 */ : expr /* 0#0 */) => {} | ||
| } | ||
| }; ($name /* 0#0 */:ident /* 0#0 */) => | ||
| { | ||
| make_macro /* 0#0 | ||
| */!{@inner /* 0#0 */ $name /* 0#0 */($) marg /* 0#0 */} | ||
| }; | ||
| } | ||
| macro_rules! add2 | ||
| /* | ||
| 0#0 | ||
| */ { | ||
| ($ marg /* 0#1 */ : expr /* 0#2 */, $marg /* 0#2 */ : expr /* | ||
| 0#2 */) => {} | ||
| } | ||
|
|
||
|
|
||
| /* | ||
| Expansions: | ||
| crate0::{{expn0}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Root | ||
| crate0::{{expn1}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "make_macro") | ||
| crate0::{{expn2}}: parent: crate0::{{expn1}}, call_site_ctxt: #1, def_site_ctxt: #0, kind: Macro(Bang, "make_macro") | ||
|
|
||
| SyntaxContexts: | ||
| #0: parent: #0, outer_mark: (crate0::{{expn0}}, Opaque) | ||
| #1: parent: #0, outer_mark: (crate0::{{expn1}}, SemiOpaque) | ||
| #2: parent: #0, outer_mark: (crate0::{{expn2}}, SemiOpaque) | ||
| */ |
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 @@ | ||
| //@ check-pass | ||
| //@ compile-flags: -Zunpretty=expanded,hygiene | ||
|
|
||
| // Regression test for token hygiene annotations in -Zunpretty=expanded,hygiene | ||
| // Previously, tokens in macro_rules! bodies were missing hygiene annotations, | ||
| // making it impossible to see how a macro's reference to a shadowed variable | ||
| // is distinguished from the shadowing binding. | ||
|
|
||
| // Don't break whenever Symbol numbering changes | ||
| //@ normalize-stdout: "\d+#" -> "0#" | ||
|
|
||
| #![feature(no_core)] | ||
| #![no_core] | ||
|
|
||
| fn f() { | ||
| let x = 0; | ||
| macro_rules! use_x { () => { x }; } | ||
| let x = 1; | ||
| use_x!(); | ||
| } |
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,30 @@ | ||
| //@ check-pass | ||
| //@ compile-flags: -Zunpretty=expanded,hygiene | ||
|
|
||
| // Regression test for token hygiene annotations in -Zunpretty=expanded,hygiene | ||
| // Previously, tokens in macro_rules! bodies were missing hygiene annotations, | ||
| // making it impossible to see how a macro's reference to a shadowed variable | ||
| // is distinguished from the shadowing binding. | ||
|
|
||
| // Don't break whenever Symbol numbering changes | ||
| //@ normalize-stdout: "\d+#" -> "0#" | ||
|
|
||
| #![feature /* 0#0 */(no_core /* 0#0 */)] | ||
| #![no_core /* 0#0 */] | ||
|
|
||
| fn f /* 0#0 */() { | ||
| let x /* 0#0 */ = 0; | ||
| macro_rules! use_x /* 0#0 */ { () => { x /* 0#0 */ }; } | ||
| let x /* 0#0 */ = 1; | ||
| x /* 0#1 */; | ||
| } | ||
|
|
||
| /* | ||
| Expansions: | ||
| crate0::{{expn0}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Root | ||
| crate0::{{expn1}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "use_x") | ||
|
|
||
| SyntaxContexts: | ||
| #0: parent: #0, outer_mark: (crate0::{{expn0}}, Opaque) | ||
| #1: parent: #0, outer_mark: (crate0::{{expn1}}, SemiOpaque) | ||
| */ |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there an issue about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Kivooeo no, mainly because I discovered this bug while looking through the hygiene output -- I thought about making an issue, but I realised it would be just as quick to fix the issue ... hence this PR!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess two follow-ons: