Skip to content
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

macros: improve `$crate` #37213

Merged
merged 3 commits into from Oct 19, 2016

Conversation

Projects
None yet
4 participants
@jseyfried
Copy link
Contributor

jseyfried commented Oct 16, 2016

This PR refactors the implementation of $crate so that

  • $crate is only allowed at the start of a path (like super),
  • we can make $crate work with inter-crate re-exports (groundwork for macro modularization), and
  • we can support importing macros from an extern crate that is not declared at the crate root (also groundwork for macro modularization).

This is a [breaking-change]. For example, the following would break:

fn foo() {}
macro_rules! m { () => {
    $crate foo $crate () $crate $crate;
    //^ Today, `$crate` is allowed just about anywhere in unexported macros.
} }
fn main() {
    m!();
}

r? @nrc

@jseyfried jseyfried changed the title macros: Improve `$crate` macros: improve `$crate` Oct 16, 2016

@jseyfried

This comment has been minimized.

Copy link
Contributor Author

jseyfried commented Oct 16, 2016

cc #35896

@nrc

This comment has been minimized.

Copy link
Member

nrc commented Oct 18, 2016

we can support importing macros from an extern crate that is not declared at the crate root

to clarify - this PR doesn't actually allow any changes to the actual importing behaviour of such macros, it just lays internal groundwork to allow this in the future?

@jseyfried

This comment has been minimized.

Copy link
Contributor Author

jseyfried commented Oct 18, 2016

Right, the only observable change from this PR is restricting where $crate is allowed.

@nrc

This comment has been minimized.

Copy link
Member

nrc commented Oct 18, 2016

@bors: r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 18, 2016

📌 Commit 2676b25 has been approved by nrc

@eddyb eddyb referenced this pull request Oct 18, 2016

Closed

Rollup of 16 pull requests #37262

bors added a commit that referenced this pull request Oct 18, 2016

Auto merge of #37262 - eddyb:rollup, r=eddyb
Rollup of 16 pull requests

- Successful merges: #36964, #37117, #37124, #37161, #37193, #37198, #37202, #37208, #37218, #37220, #37221, #37224, #37231, #37233, #37240, #37257
- Failed merges: #37213

bors added a commit that referenced this pull request Oct 19, 2016

Auto merge of #37262 - eddyb:rollup, r=eddyb
Rollup of 16 pull requests

- Successful merges: #36964, #37117, #37124, #37161, #37193, #37198, #37202, #37208, #37218, #37220, #37221, #37224, #37231, #37233, #37240, #37257
- Failed merges: #37213

@eddyb eddyb referenced this pull request Oct 19, 2016

Merged

Rollup of 23 pull requests #37269

bors added a commit that referenced this pull request Oct 19, 2016

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 19, 2016

🔒 Merge conflict

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 19, 2016

☔️ The latest upstream changes (presumably #37269) made this pull request unmergeable. Please resolve the merge conflicts.

@jseyfried jseyfried force-pushed the jseyfried:refactor_crate_var branch from 2676b25 to 8b0c292 Oct 19, 2016

@jseyfried

This comment has been minimized.

Copy link
Contributor Author

jseyfried commented Oct 19, 2016

@bors r=nrc

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 19, 2016

📌 Commit 8b0c292 has been approved by nrc

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 19, 2016

⌛️ Testing commit 8b0c292 with merge cfc9b51...

bors added a commit that referenced this pull request Oct 19, 2016

Auto merge of #37213 - jseyfried:refactor_crate_var, r=nrc
macros: improve `$crate`

This PR refactors the implementation of `$crate` so that
 - `$crate` is only allowed at the start of a path (like `super`),
 - we can make `$crate` work with inter-crate re-exports (groundwork for macro modularization), and
 - we can support importing macros from an extern crate that is not declared at the crate root (also groundwork for macro modularization).

This is a [breaking-change]. For example, the following would break:
```rust
fn foo() {}
macro_rules! m { () => {
    $crate foo $crate () $crate $crate;
    //^ Today, `$crate` is allowed just about anywhere in unexported macros.
} }
fn main() {
    m!();
}
```
r? @nrc

@bors bors merged commit 8b0c292 into rust-lang:master Oct 19, 2016

1 check passed

homu Test successful
Details

@bluss bluss added the relnotes label Oct 19, 2016

@jseyfried jseyfried deleted the jseyfried:refactor_crate_var branch Oct 19, 2016

bors added a commit that referenced this pull request Nov 10, 2016

Auto merge of #37645 - jseyfried:fix_crate_var_in_custom_derives, r=nrc
Fix regression involving custom derives on items with `$crate`

The regression was introduced in #37213.

I believe we cannot make the improvements from #37213 work with the current custom derive setup (c.f. #37637 (comment)) -- we'll have to wait for `TokenStream`'s API to improve.

Fixes #37637.
r? @nrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.