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
Merged

macros: improve $crate #37213

merged 3 commits into from
Oct 19, 2016

Conversation

jseyfried
Copy link
Contributor

@jseyfried 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
Copy link
Contributor Author

cc #35896

@nrc
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
Copy link
Contributor Author

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

@nrc
Copy link
Member

nrc commented Oct 18, 2016

@bors: r+

@bors
Copy link
Contributor

bors commented Oct 18, 2016

📌 Commit 2676b25 has been approved by nrc

bors added a commit that referenced this pull request Oct 19, 2016
@bors
Copy link
Contributor

bors commented Oct 19, 2016

🔒 Merge conflict

@bors
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
Copy link
Contributor Author

@bors r=nrc

@bors
Copy link
Contributor

bors commented Oct 19, 2016

📌 Commit 8b0c292 has been approved by nrc

@bors
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
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
@bluss bluss added the relnotes Marks issues that should be documented in the release notes of the next release. label Oct 19, 2016
@jseyfried jseyfried deleted the refactor_crate_var branch October 19, 2016 20:26
bors added a commit that referenced this pull request Nov 10, 2016
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
Labels
relnotes Marks issues that should be documented in the release notes of the next release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants