Skip to content

Commit e3b8efe

Browse files
committed
Use local_inner_macros to resolve all helper macros within $crate
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.
1 parent bc51ed6 commit e3b8efe

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub mod lazy;
123123
#[doc(hidden)]
124124
pub use core::ops::Deref as __Deref;
125125

126-
#[macro_export]
126+
#[macro_export(local_inner_macros)]
127127
#[doc(hidden)]
128128
macro_rules! __lazy_static_internal {
129129
// optional visibility restrictions are wrapped in `()` to allow for
@@ -170,7 +170,7 @@ macro_rules! __lazy_static_internal {
170170
() => ()
171171
}
172172

173-
#[macro_export]
173+
#[macro_export(local_inner_macros)]
174174
macro_rules! lazy_static {
175175
($(#[$attr:meta])* static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => {
176176
// use `()` to explicitly forward the information about private items

0 commit comments

Comments
 (0)