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 helper macros within $crate #107

Merged
merged 1 commit into from
Jul 15, 2018
Merged

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Jul 15, 2018

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

extern crate lazy_static;
use lazy_static::lazy_static;
error: cannot find macro `__lazy_static_internal!` in this scope
  --> src/main.rs:8:1
   |
8  | / lazy_static! {
9  | |     static ref M: HashMap<String, String> = HashMap::new();
10 | | }
   | |_^
   |

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

The attribute is ignored by pre-2018 compilers so lazy_static 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 helper macros.

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

    extern crate lazy_static;
    use lazy_static::lazy_static;

    error: cannot find macro `__lazy_static_internal!` in this scope
      --> src/main.rs:8:1
       |
    8  | / lazy_static! {
    9  | |     static ref M: HashMap<String, String> = HashMap::new();
    10 | | }
       | |_^
       |

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

The attribute is ignored by pre-2018 compilers so lazy_static 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 helper 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.

1 participant