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

Support #[macro_use] on macro-expanded crates #34032

Merged
merged 3 commits into from
Jun 9, 2016

Conversation

jseyfried
Copy link
Contributor

@jseyfried jseyfried commented Jun 2, 2016

This PR loads macros from #[macro_use] crates during expansion so that

This is a [breaking-change]. For example, this will break:

macro_rules! m {
    () => { #[macro_use(foo)] extern crate core; } //~ ERROR imported macro not found
}
m!();

Also, this will break:

macro_rules! try { () => {} }
#[macro_use] extern crate core; //< This will now "overwrite" the above `try!` ...
// #[macro_use] mod bar { macro_rules! try { ... } } //< ... just like this would ...
fn main() { try!(); } //< ... making this an error

r? @nrc

@jseyfried
Copy link
Contributor Author

cc @durka

@jseyfried jseyfried force-pushed the load_macros_in_expansion branch from 1b05450 to 38166c8 Compare June 3, 2016 12:59
@@ -925,4 +940,8 @@ impl SyntaxEnv {
let last_chain_index = self.chain.len() - 1;
&mut self.chain[last_chain_index].info
}

pub fn is_crate_root(&mut self) -> bool {
self.chain.len() == 2
Copy link
Contributor

Choose a reason for hiding this comment

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

Huh? Why 2? This probably needs a comment. :d

Copy link
Contributor Author

@jseyfried jseyfried Jun 5, 2016

Choose a reason for hiding this comment

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

Done.

@LeoTestard
Copy link
Contributor

(Otherwise: 👍 💯)

@jseyfried jseyfried force-pushed the load_macros_in_expansion branch from f953a79 to acbff87 Compare June 5, 2016 02:18
@nrc
Copy link
Member

nrc commented Jun 7, 2016

@bors: r+

@bors
Copy link
Contributor

bors commented Jun 7, 2016

📌 Commit acbff87 has been approved by nrc

@bors
Copy link
Contributor

bors commented Jun 8, 2016

🔒 Merge conflict

@bors
Copy link
Contributor

bors commented Jun 8, 2016

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

@jseyfried jseyfried force-pushed the load_macros_in_expansion branch from acbff87 to dbf0326 Compare June 9, 2016 00:50
@jseyfried
Copy link
Contributor Author

Rebased. @bors r=nrc

@bors
Copy link
Contributor

bors commented Jun 9, 2016

📌 Commit dbf0326 has been approved by nrc

@bors
Copy link
Contributor

bors commented Jun 9, 2016

⌛ Testing commit dbf0326 with merge dc77c5e...

bors added a commit that referenced this pull request Jun 9, 2016
Support `#[macro_use]` on macro-expanded crates

This PR loads macros from `#[macro_use]` crates during expansion so that
 - macro-expanded `#[macro_use]` crates work (fixes #33936, fixes #28071), and
 - macros imported from crates have the same scope as macros imported from modules.

This is a [breaking-change]. For example, this will break:
```rust
macro_rules! m {
    () => { #[macro_use(foo)] extern crate core; } //~ ERROR imported macro not found
}
m!();
```
Also, this will break:
```rust
macro_rules! try { () => {} }
// #[macro_use] mod bar { macro_rules! try { ... } } //< ... just like this would ...
fn main() { try!(); } //< ... making this an error
```

r? @nrc
@bors bors merged commit dbf0326 into rust-lang:master Jun 9, 2016
@jseyfried
Copy link
Contributor Author

@nrc This may need a relnotes tag (c.f. #33458).

@alexcrichton alexcrichton added the relnotes Marks issues that should be documented in the release notes of the next release. label Jun 10, 2016
@alexcrichton
Copy link
Member

Added

bors added a commit that referenced this pull request Jun 16, 2016
Revert a change in the scope of macros imported from crates to fix a regression

Fixes #34212.
The regression was caused by #34032, which changed the scope of macros imported from extern crates to match the scope of macros imported from modules.
r? @nrc
@jseyfried jseyfried deleted the load_macros_in_expansion branch September 25, 2016 20:28
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.

#[macro_use] does not work on macro-expanded extern crates include!ed files are unable to #[macro_use]
5 participants