@@ -17,10 +17,13 @@ lazy_static! {
1717}
1818```
1919
20+ Metadata (such as doc comments) is allowed on each ref.
21+
2022# Semantic
2123
22- For a given `static ref NAME: TYPE = EXPR;`, the macro generates a
23- unique type that implements `Deref<TYPE>` and stores it in a static with name `NAME`.
24+ For a given `static ref NAME: TYPE = EXPR;`, the macro generates a unique type that
25+ implements `Deref<TYPE>` and stores it in a static with name `NAME`. (Metadata ends up
26+ attaching to this type.)
2427
2528On first deref, `EXPR` gets evaluated and stored internally, such that all further derefs
2629can return a reference to the same object.
@@ -72,14 +75,14 @@ define uninitialized `static mut` values.
7275
7376#[ macro_export]
7477macro_rules! lazy_static {
75- ( static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
76- lazy_static!( PRIV static ref $N : $T = $e; $( $t) * ) ;
78+ ( $ ( # [ $attr : meta ] ) * static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
79+ lazy_static!( PRIV , $ ( # [ $attr ] ) * static ref $N : $T = $e; $( $t) * ) ;
7780 } ;
78- ( pub static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
79- lazy_static!( PUB static ref $N : $T = $e; $( $t) * ) ;
81+ ( $ ( # [ $attr : meta ] ) * pub static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
82+ lazy_static!( PUB , $ ( # [ $attr ] ) * static ref $N : $T = $e; $( $t) * ) ;
8083 } ;
81- ( $VIS: ident static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
82- lazy_static!( MAKE TY $VIS $N) ;
84+ ( $VIS: ident, $ ( # [ $attr : meta ] ) * static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
85+ lazy_static!( MAKE TY , $VIS, $ ( # [ $attr ] ) * , $N) ;
8386 impl :: std:: ops:: Deref for $N {
8487 type Target = $T;
8588 fn deref<' a>( & ' a self ) -> & ' a $T {
@@ -106,18 +109,22 @@ macro_rules! lazy_static {
106109 }
107110 lazy_static!( $( $t) * ) ;
108111 } ;
109- ( MAKE TY PUB $N: ident) => {
112+ ( MAKE TY , PUB , $ ( # [ $attr : meta ] ) * , $N: ident) => {
110113 #[ allow( missing_copy_implementations) ]
111114 #[ allow( non_camel_case_types) ]
112115 #[ allow( dead_code) ]
116+ $( #[ $attr] ) *
113117 pub struct $N { __private_field: ( ) }
118+ #[ doc( hidden) ]
114119 pub static $N: $N = $N { __private_field: ( ) } ;
115120 } ;
116- ( MAKE TY PRIV $N: ident) => {
121+ ( MAKE TY , PRIV , $ ( # [ $attr : meta ] ) * , $N: ident) => {
117122 #[ allow( missing_copy_implementations) ]
118123 #[ allow( non_camel_case_types) ]
119124 #[ allow( dead_code) ]
125+ $( #[ $attr] ) *
120126 struct $N { __private_field: ( ) }
127+ #[ doc( hidden) ]
121128 static $N: $N = $N { __private_field: ( ) } ;
122129 } ;
123130 ( ) => ( )
0 commit comments