Uh oh!
There was an error while loading. Please reload this page.
macros: Make metavariables hygienic - #35453
Conversation
nrc
commented
Aug 8, 2016
@bors: r+ |
bors
commented
Aug 8, 2016
📌 Commit cdbfe9f has been approved by |
bors
commented
Aug 8, 2016
⌛ Testing commit cdbfe9f with merge 26f17ba... |
bors
commented
Aug 8, 2016
💔 Test failed - auto-win-gnu-64-opt |
durka
commented
Aug 8, 2016
LLVM didn't build? |
alexcrichton
commented
Aug 8, 2016
@bors: retry
|
bors
commented
Aug 10, 2016
⌛ Testing commit cdbfe9f with merge 70bb60c... |
bors
commented
Aug 10, 2016
💔 Test failed - auto-win-gnu-32-opt-rustbuild |
durka
commented
Aug 10, 2016
|
jseyfried
commented
Aug 12, 2016
bors
commented
Aug 12, 2016
📌 Commit b62ff25 has been approved by |
bors
commented
Aug 12, 2016
📌 Commit b62ff25 has been approved by |
b62ff25 to
95b68aaComparebors
commented
Aug 12, 2016
📌 Commit 95b68aa has been approved by |
durka
commented
Aug 12, 2016
So... this is a syntax-breaking change if there is test fallout (sorry). |
eddyb
commented
Aug 12, 2016
cc @Manishearth |
jseyfried
commented
Aug 13, 2016
@durka Good point. |
I think so. @dtolnay whatsay? |
Manishearth
commented
Aug 13, 2016
We're gettign a pile of PRs that will break aster (and only aster) right now though. So it might be good to do a rollup. OTOH there's a bunch of diagnostics work coming up which I'd like to include. |
dtolnay
commented
Aug 13, 2016
This PR does not affect quasi/aster. For the others - I have time in the next two weeks to deal with fallout so this would be a good time. Thanks for the heads up. |
Manishearth
commented
Aug 13, 2016
Cool. @GuillaumeGomez could you get all libsyntax refactors necessary for diagnostics in now? |
jseyfried
commented
Aug 13, 2016
@bors r=nrc |
bors
commented
Aug 13, 2016
📌 Commit 95b68aa has been approved by |
bors
commented
Aug 14, 2016
⌛ Testing commit 95b68aa with merge f6ba0ad... |
alexcrichton
commented
Aug 14, 2016
@bors: retry force clean
|
macros: Make metavariables hygienic
This PR makes metavariables hygienic. For example, consider:
```rust
macro_rules! foo {
($x:tt) => { // Suppose that this token tree argument is always a metavariable.
macro_rules! bar { ($x:expr, $y:expr) => { ($x, $y) } }
}
}
fn main() {
foo!($z); // This currently compiles.
foo!($y); // This is an error today but compiles after this PR.
}
```
Today, the `macro_rules! bar { ... }` definition is only valid when the metavariable passed to `foo` is not `$y` (since it unhygienically conflicts with the `$y` in the definition of `bar`) or `$x` (c.f. #35450).
After this PR, the definition of `bar` is always valid (and `bar!(a, b)` always expands to `(a, b)` as expected).
This can break code that was allowed in #34925 (landed two weeks ago). For example,
```rust
macro_rules! outer {
($t:tt) => {
macro_rules! inner { ($i:item) => { $t } }
}
}
outer!($i); // This `$i` should not interact with the `$i` in the definition of `inner!`.
inner!(fn main() {}); // After this PR, this is an error ("unknown macro variable `i`").
```
Due to the severe limitations on nested `macro_rules!` before #34925, this is not a breaking change for stable/beta.
Fixes#35450.
r? @nrc
This PR makes metavariables hygienic. For example, consider:
Today, the
macro_rules! bar { ... }definition is only valid when the metavariable passed tofoois not$y(since it unhygienically conflicts with the$yin the definition ofbar) or$x(c.f. #35450).After this PR, the definition of
baris always valid (andbar!(a, b)always expands to(a, b)as expected).This can break code that was allowed in #34925 (landed two weeks ago). For example,
Due to the severe limitations on nested
macro_rules!before #34925, this is not a breaking change for stable/beta.Fixes#35450.
r? @nrc