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

Use local_inner_macros to resolve all local macros within $crate #288

Merged
merged 1 commit into from
Aug 17, 2018
Merged

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Aug 17, 2018

This fixes the following error when using Rust 2018 style macro imports.

use log::info;

fn main() {
    info!("...");
}
error: cannot find macro `log!` in this scope
 --> src/main.rs:4:5
  |
4 |     info!("...");
  |     ^^^^^^^^^^^^^

The local_inner_macros modifier resolves all macro invocations made from within that macro as macros in the same crate. So if info! expands to an invocation of log! then this would be resolved as $crate::log! rather than requiring the caller to have log in scope.

The attribute is ignored by pre-2018 compilers so log will continue to work as normal with #[macro_use].

In the future when dropping compatibility with pre-2018 compilers we can remove the local_inner_macros modifier and use our own explicit $crate:: prefixes on invocations of local macros.

Fixes #54.

This fixes the following error when using Rust 2018 style macro imports.

    use log::info;

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

    error: cannot find macro `log!` in this scope
     --> src/main.rs:4:5
      |
    4 |     info!("...");
      |     ^^^^^^^^^^^^^

The `local_inner_macros` modifier resolves all macro invocations made
from within that macro as macros in the same crate. So if `info!`
expands to an invocation of `log!` then this would be resolved as
`$crate::log!` rather than requiring the caller to have `log` in scope.

The attribute is ignored by pre-2018 compilers so log will continue to
work as normal with #[macro_use].

In the future when dropping compatibility with pre-2018 compilers we can
remove the `local_inner_macros` modifier and use our own explicit
`$crate::` prefixes on invocations of local macros.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

#[macro_use(info)] raise error: macro undefined: 'log!'
2 participants