@@ -116,24 +116,12 @@ pub use core::ops::Deref as __Deref;
116116#[ cfg_attr( feature="nightly" , allow_internal_unstable) ]
117117#[ doc( hidden) ]
118118macro_rules! __lazy_static_internal {
119- ( $( #[ $attr: meta] ) * static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
120- __lazy_static_internal!( @PRIV , $( #[ $attr] ) * static ref $N : $T = $e; $( $t) * ) ;
121- } ;
122- ( $( #[ $attr: meta] ) * pub ( in $pub_in: path) static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
123- __lazy_static_internal!( @PUB_IN , $pub_in, $( #[ $attr] ) * static ref $N : $T = $e; $( $t) * ) ;
124- } ;
125- ( $( #[ $attr: meta] ) * pub static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
126- __lazy_static_internal!( @PUB , $( #[ $attr] ) * static ref $N : $T = $e; $( $t) * ) ;
127- } ;
128- ( @PUB_IN , $pub_in: path, $( #[ $attr: meta] ) * static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
129- __lazy_static_internal!( @MAKE TY , PUB_IN , $pub_in, $( #[ $attr] ) * , $N) ;
119+ // optional visibility restrictions are wrapped in `()` to allow for
120+ // explicitly passing otherwise implicit information about private items
121+ ( $( #[ $attr: meta] ) * ( $( $vis: tt) * ) static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
122+ __lazy_static_internal!( @MAKE TY , $( #[ $attr] ) * , ( $( $vis) * ) , $N) ;
130123 __lazy_static_internal!( @TAIL , $N : $T = $e) ;
131- __lazy_static_internal!( $( $t) * ) ;
132- } ;
133- ( @$VIS: ident, $( #[ $attr: meta] ) * static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
134- __lazy_static_internal!( @MAKE TY , $VIS, $( #[ $attr] ) * , $N) ;
135- __lazy_static_internal!( @TAIL , $N : $T = $e) ;
136- __lazy_static_internal!( $( $t) * ) ;
124+ lazy_static!( $( $t) * ) ;
137125 } ;
138126 ( @TAIL , $N: ident : $T: ty = $e: expr) => {
139127 impl $crate:: __Deref for $N {
@@ -159,32 +147,15 @@ macro_rules! __lazy_static_internal {
159147 }
160148 }
161149 } ;
162- ( @MAKE TY , PUB , $( #[ $attr: meta] ) * , $N: ident) => {
150+ // `vis` is wrapped in `()` to prevent parsing ambiguity
151+ ( @MAKE TY , $( #[ $attr: meta] ) * , ( $( $vis: tt) * ) , $N: ident) => {
163152 #[ allow( missing_copy_implementations) ]
164153 #[ allow( non_camel_case_types) ]
165154 #[ allow( dead_code) ]
166155 $( #[ $attr] ) *
167- pub struct $N { __private_field: ( ) }
156+ $ ( $vis ) * struct $N { __private_field: ( ) }
168157 #[ doc( hidden) ]
169- pub static $N: $N = $N { __private_field: ( ) } ;
170- } ;
171- ( @MAKE TY , PUB_IN , $pub_in: path, $( #[ $attr: meta] ) * , $N: ident) => {
172- #[ allow( missing_copy_implementations) ]
173- #[ allow( non_camel_case_types) ]
174- #[ allow( dead_code) ]
175- $( #[ $attr] ) *
176- pub ( in $pub_in) struct $N { __private_field: ( ) }
177- #[ doc( hidden) ]
178- pub ( in $pub_in) static $N: $N = $N { __private_field: ( ) } ;
179- } ;
180- ( @MAKE TY , PRIV , $( #[ $attr: meta] ) * , $N: ident) => {
181- #[ allow( missing_copy_implementations) ]
182- #[ allow( non_camel_case_types) ]
183- #[ allow( dead_code) ]
184- $( #[ $attr] ) *
185- struct $N { __private_field: ( ) }
186- #[ doc( hidden) ]
187- static $N: $N = $N { __private_field: ( ) } ;
158+ $( $vis) * static $N: $N = $N { __private_field: ( ) } ;
188159 } ;
189160 ( ) => ( )
190161}
@@ -193,13 +164,14 @@ macro_rules! __lazy_static_internal {
193164#[ cfg_attr( feature="nightly" , allow_internal_unstable) ]
194165macro_rules! lazy_static {
195166 ( $( #[ $attr: meta] ) * static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
196- __lazy_static_internal!( @PRIV , $( #[ $attr] ) * static ref $N : $T = $e; $( $t) * ) ;
197- } ;
198- ( $( #[ $attr: meta] ) * pub ( in $pub_in: path) static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
199- __lazy_static_internal!( @PUB_IN , $pub_in, $( #[ $attr] ) * static ref $N : $T = $e; $( $t) * ) ;
167+ // use `()` to explicitly forward the information about private items
168+ __lazy_static_internal!( $( #[ $attr] ) * ( ) static ref $N : $T = $e; $( $t) * ) ;
200169 } ;
201170 ( $( #[ $attr: meta] ) * pub static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
202- __lazy_static_internal!( @PUB , $( #[ $attr] ) * static ref $N : $T = $e; $( $t) * ) ;
171+ __lazy_static_internal!( $( #[ $attr] ) * ( pub ) static ref $N : $T = $e; $( $t) * ) ;
172+ } ;
173+ ( $( #[ $attr: meta] ) * pub ( $( $vis: tt) +) static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
174+ __lazy_static_internal!( $( #[ $attr] ) * ( pub ( $( $vis) +) ) static ref $N : $T = $e; $( $t) * ) ;
203175 } ;
204176 ( ) => ( )
205177}
0 commit comments