@@ -6,13 +6,11 @@ extern crate syn;
66#[ macro_use]
77extern crate quote;
88extern crate proc_macro;
9- extern crate proc_macro2;
109
1110use syn:: { Visibility , Ident , Type , Expr } ;
1211use syn:: synom:: Synom ;
1312use syn:: spanned:: Spanned ;
1413use proc_macro:: TokenStream ;
15- use proc_macro2:: Span ;
1614
1715/// Parses the following syntax, which aligns with the input of the real
1816/// `lazy_static` crate.
@@ -51,7 +49,6 @@ impl Synom for LazyStatic {
5149#[ proc_macro]
5250pub fn lazy_static ( input : TokenStream ) -> TokenStream {
5351 let LazyStatic { visibility, name, ty, init } = syn:: parse ( input) . unwrap ( ) ;
54- let def_site = Span :: def_site ( ) ;
5552
5653 // The warning looks like this.
5754 //
@@ -84,20 +81,15 @@ pub fn lazy_static(input: TokenStream) -> TokenStream {
8481
8582 // Assert that the static type implements Sync. If not, user sees an error
8683 // message like the following. We span this assertion with the field type's
87- // line/column so that the error message appears in the correct place, but
88- // resolve it at the def site so that we are guaranteed it is checking the
89- // correct Sync. If the `Sync` token were resolved at the call site, the
90- // user could circumvent the check by defining their own Sync trait that is
91- // implemented for their type.
84+ // line/column so that the error message appears in the correct place.
9285 //
9386 // error[E0277]: the trait bound `*const (): std::marker::Sync` is not satisfied
9487 // --> src/main.rs:10:21
9588 // |
9689 // 10 | static ref PTR: *const () = &();
9790 // | ^^^^^^^^^ `*const ()` cannot be shared between threads safely
98- let ty_span = ty. span ( ) . resolved_at ( def_site) ;
99- let assert_sync = quote_spanned ! { ty_span=>
100- struct _AssertSync where #ty: Sync ;
91+ let assert_sync = quote_spanned ! { ty. span( ) =>
92+ struct _AssertSync where #ty: :: std:: marker:: Sync ;
10193 } ;
10294
10395 // Check for Sized. Not vital to check here, but the error message is less
@@ -109,28 +101,25 @@ pub fn lazy_static(input: TokenStream) -> TokenStream {
109101 // |
110102 // 10 | static ref A: str = "";
111103 // | ^^^ `str` does not have a constant size known at compile-time
112- let assert_sized = quote_spanned ! { ty_span =>
113- struct _AssertSized where #ty: Sized ;
104+ let assert_sized = quote_spanned ! { ty . span ( ) =>
105+ struct _AssertSized where #ty: :: std :: marker :: Sized ;
114106 } ;
115107
116- let init_span = init. span ( ) . resolved_at ( def_site) ;
117- let init_ptr = quote_spanned ! { init_span=>
108+ let init_ptr = quote_spanned ! { init. span( ) =>
118109 Box :: into_raw( Box :: new( #init) )
119110 } ;
120111
121112 let expanded = quote ! {
122- extern crate std;
123-
124113 #visibility struct #name;
125114
126- impl std:: ops:: Deref for #name {
115+ impl :: std:: ops:: Deref for #name {
127116 type Target = #ty;
128117
129118 fn deref( & self ) -> & #ty {
130119 #assert_sync
131120 #assert_sized
132121
133- static ONCE : std:: sync:: Once = std:: sync:: ONCE_INIT ;
122+ static ONCE : :: std:: sync:: Once = :: std:: sync:: ONCE_INIT ;
134123 static mut VALUE : * mut #ty = 0 as * mut #ty;
135124
136125 unsafe {
0 commit comments