Skip to content

#[macro_use] does not work on macro-expanded extern crates #33936

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

Closed
jseyfried opened this issue May 29, 2016 · 2 comments · Fixed by #34032
Closed

#[macro_use] does not work on macro-expanded extern crates #33936

jseyfried opened this issue May 29, 2016 · 2 comments · Fixed by #34032
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

Comments

@jseyfried
Copy link
Contributor

For example, this compiles:

#![feature(rustc_private)]

#[macro_use]
extern crate syntax;

fn main() {
    help!(S, "");

    struct S;
    impl S { fn help(&self, _: &str) {} }
}

but this doesn't:

#![feature(rustc_private)]

macro_rules! my_extern_crate {
    ($i:ident) => { #[macro_use] extern crate $i; }
}
my_extern_crate!(syntax);

fn main() { ... }
@TimNN
Copy link
Contributor

TimNN commented May 29, 2016

Probably the same issue as #28071.

@jseyfried
Copy link
Contributor Author

@TimNN I believe #28071 is a special case of this issue -- thanks for linking it!

@steveklabnik steveklabnik added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label Jun 6, 2016
bors added a commit that referenced this issue 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants