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

include!ed files are unable to #[macro_use] #28071

Closed
codyps opened this issue Aug 28, 2015 · 3 comments · Fixed by #34032
Closed

include!ed files are unable to #[macro_use] #28071

codyps opened this issue Aug 28, 2015 · 3 comments · Fixed by #34032
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

Comments

@codyps
Copy link
Contributor

codyps commented Aug 28, 2015

This makes using codegen a bit more cumbersome.

What happens:

main_real.rs:

// main_real.rs:
#[macro_use]
extern crate log;

fn main() {
    info!("Hi!");
}

main.rs:

include!{"main_real.rs"}

Cargo.toml:

[package]
name = "macro-use-include"
version = "0.1.0"
authors = ["Cody P Schafer <dev@codyps.com>"]

[dependencies]
log = "*"

Attempt to build:

% cargo build
   Compiling macro-use-include v0.1.0 (file:///home/cody/macro-use-include)
src/main_real.rs:5:5: 5:9 error: macro undefined: 'info!'
src/main_real.rs:5     info!("Hi");
                       ^~~~
error: aborting due to previous error
Could not compile `macro-use-include`.

To learn more, run the command again with --verbose.

Moving main_real.rs to main.rs builds as expected.

@jonas-schievink
Copy link
Contributor

Does this perhaps have to do with #27626?

@codyps
Copy link
Contributor Author

codyps commented Aug 28, 2015

I suppose that depends on what is considered "module root".

Plain extern crate foo; seems to function as expected in include!()ed files, so I don't think it's directly related.

@jseyfried
Copy link
Contributor

This is unrelated to #27626.

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.

4 participants