Skip to content

macros: improve 1.0/2.0 interaction - #46551

Merged
bors merged 2 commits into
rust-lang:masterfrom
jseyfried:improve_legacy_modern_macro_interaction
Jan 12, 2018
Merged

macros: improve 1.0/2.0 interaction#46551
bors merged 2 commits into
rust-lang:masterfrom
jseyfried:improve_legacy_modern_macro_interaction

Conversation

@jseyfried

@jseyfriedjseyfried commented Dec 7, 2017

Copy link
Copy Markdown
Contributor

This PR supports using unhygienic macros from hygienic macros without breaking the latter's hygiene.

// crate A:#[macro_export]macro_rules! m1 {() => {
f();// unhygienic: this macro needs `f` in its environmentfn g(){}// (1) unhygienic: `g` is usable outside the macro definition}}// crate B:#![feature(decl_macro)]externcrateA;useA::m1;macro m2(){fnf(){}// (2)m1!();// After this PR, `f()` in the expansion resolves to (2), not (3)g();// After this PR, this resolves to `fn g() {}` from the above expansion.// Today, it is a resolution error.}fntest(){fnf(){}// (3)m2!();// Today, `m2!()` can see (3) even though it should be hygienic.fng(){}// Today, this conflicts with `fn g() {}` from the expansion, even though it should be hygienic.}

Once this PR lands, you can make an existing unhygienic macro hygienic by wrapping it in a hygienic macro. There is an example of this in the tests.

r? @nrc

Comment threadsrc/libproc_macro/lib.rs Outdated

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kennytmkennytm added the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Dec 7, 2017
@kennytmkennytm added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Dec 13, 2017
@kennytm

Copy link
Copy Markdown
Member

Both #46550 and #46419 have been merged.

@jseyfried
jseyfriedforce-pushed the improve_legacy_modern_macro_interaction branch 2 times, most recently from fb04829 to d6a8566CompareDecember 13, 2017 20:42
@jseyfried
jseyfriedforce-pushed the improve_legacy_modern_macro_interaction branch from d6a8566 to b766fa8CompareDecember 13, 2017 21:33
@kennytm

Copy link
Copy Markdown
Member

Review ping for you @nrc!

@alexcrichton

Copy link
Copy Markdown
Member

ping @nrc, this may be ready for a look now!

@kennytm

Copy link
Copy Markdown
Member

Review ping for you @nrc!

@nrc

nrc commented Jan 12, 2018

Copy link
Copy Markdown
Member

@bors: r+

@bors

bors commented Jan 12, 2018

Copy link
Copy Markdown
Collaborator

📌 Commit b766fa8 has been approved by nrc

@bors

bors commented Jan 12, 2018

Copy link
Copy Markdown
Collaborator

⌛ Testing commit b766fa8 with merge 0b90e4e...

bors added a commit that referenced this pull request Jan 12, 2018
…ion, r=nrc
macros: improve 1.0/2.0 interaction
This PR supports using unhygienic macros from hygienic macros without breaking the latter's hygiene.
```rust
// crate A:
#[macro_export]
macro_rules! m1 { () => {
f(); // unhygienic: this macro needs `f` in its environment
fn g() {} // (1) unhygienic: `g` is usable outside the macro definition
} }
// crate B:
#![feature(decl_macro)]
extern crate A;
use A::m1;
macro m2() {
fn f() {} // (2)
m1!(); // After this PR, `f()` in the expansion resolves to (2), not (3)
g(); // After this PR, this resolves to `fn g() {}` from the above expansion.
// Today, it is a resolution error.
}
fn test() {
fn f() {} // (3)
m2!(); // Today, `m2!()` can see (3) even though it should be hygienic.
fn g() {} // Today, this conflicts with `fn g() {}` from the expansion, even though it should be hygienic.
}
```
Once this PR lands, you can make an existing unhygienic macro hygienic by wrapping it in a hygienic macro. There is an [example](b766fa8) of this in the tests.
r? @nrc
@bors

bors commented Jan 12, 2018

Copy link
Copy Markdown
Collaborator

☀️ Test successful - status-appveyor, status-travis
Approved by: nrc
Pushing 0b90e4e to master...

@bors
bors merged commit b766fa8 into rust-lang:masterJan 12, 2018
@jseyfried
jseyfried deleted the improve_legacy_modern_macro_interaction branch March 23, 2018 21:35
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-reviewStatus: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@jseyfried@kennytm@alexcrichton@nrc@bors