@@ -23,7 +23,7 @@ mod util;
23
23
use proc_macro2:: { Span , TokenStream } ;
24
24
use proc_macro_crate:: FoundCrate ;
25
25
use proc_macro_error:: { abort, abort_if_dirty, emit_error, proc_macro_error} ;
26
- use quote:: quote;
26
+ use quote:: { quote, quote_spanned } ;
27
27
use syn:: spanned:: Spanned ;
28
28
use syn:: {
29
29
parse_macro_input, parse_quote, Data , DataStruct , DeriveInput , Fields , GenericParam , Generics ,
@@ -50,11 +50,6 @@ pub fn derive_oauth1_authorize(input: proc_macro::TokenStream) -> proc_macro::To
50
50
fn expand_derive_oauth1_authorize ( mut input : DeriveInput ) -> TokenStream {
51
51
let name = & input. ident ;
52
52
53
- // We assume that `dummy` does not conflict with any of call-side identifiers
54
- // and (ab)use it to avoid potential name collisions.
55
- let dummy = format ! ( "_impl_ToOAuth1Request_for_{}" , name) ;
56
- let dummy = Ident :: new ( & dummy, Span :: call_site ( ) ) ;
57
-
58
53
let krate = match proc_macro_crate:: crate_name ( "oauth1-request" ) . unwrap ( ) {
59
54
FoundCrate :: Name ( krate) => krate,
60
55
// This is used in `oauth1_request`'s doctests.
@@ -105,36 +100,22 @@ fn expand_derive_oauth1_authorize(mut input: DeriveInput) -> TokenStream {
105
100
106
101
abort_if_dirty ( ) ;
107
102
108
- let mut fn_generics = input. generics . clone ( ) ;
109
- fn_generics. params . push ( parse_quote ! {
110
- #dummy: _oauth1_request:: serializer:: Serializer
111
- } ) ;
112
- let ( fn_generics, _, _) = fn_generics. split_for_impl ( ) ;
113
-
114
- let body = MethodBody :: new ( & fields, & dummy) ;
103
+ let body = MethodBody :: new ( & fields) ;
115
104
116
- quote ! {
105
+ quote_spanned ! { Span :: mixed_site ( ) =>
117
106
const _: ( ) = {
118
107
extern crate #krate as _oauth1_request;
119
108
120
- #[ allow( nonstandard_style) ]
121
- fn #dummy #fn_generics( mut #dummy: ( & #name #ty_generics, #dummy) ) -> #dummy:: Output
122
- #where_clause
123
- {
124
- #body
125
- }
126
-
127
109
impl #impl_generics _oauth1_request:: Request for #name #ty_generics
128
110
#where_clause
129
111
{
130
- // We do not want to mess with the signature which appears in the docs
131
- // and do not want to expose the `serializer` and `S` to the macro caller,
132
- // so we are separating the implementation to another function.
133
- fn serialize<S >( & self , serializer: S ) -> S :: Output
112
+ // `_S`'s span resolves at call site so prefix it with underscore to avoid conflict.
113
+ // TODO: Use def-site hygiene once it stabilizes.
114
+ fn serialize<_S>( & self , mut serializer: _S) -> _S:: Output
134
115
where
135
- S : _oauth1_request:: serializer:: Serializer ,
116
+ _S : _oauth1_request:: serializer:: Serializer ,
136
117
{
137
- #dummy ( ( self , serializer ) )
118
+ #body
138
119
}
139
120
}
140
121
} ;
0 commit comments