@@ -162,7 +162,7 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt,
162
162
attributes: Vec :: new( ) ,
163
163
is_unsafe: false ,
164
164
combine_substructure: combine_substructure( Box :: new( |a, b, c| {
165
- encodable_substructure( a, b, c)
165
+ encodable_substructure( a, b, c, krate )
166
166
} ) ) ,
167
167
}
168
168
) ,
@@ -173,12 +173,14 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt,
173
173
}
174
174
175
175
fn encodable_substructure ( cx : & mut ExtCtxt , trait_span : Span ,
176
- substr : & Substructure ) -> P < Expr > {
176
+ substr : & Substructure , krate : & ' static str ) -> P < Expr > {
177
177
let encoder = substr. nonself_args [ 0 ] . clone ( ) ;
178
178
// throw an underscore in front to suppress unused variable warnings
179
179
let blkarg = cx. ident_of ( "_e" ) ;
180
180
let blkencoder = cx. expr_ident ( trait_span, blkarg) ;
181
- let encode = cx. ident_of ( "encode" ) ;
181
+ let fn_path = cx. expr_path ( cx. path_global ( trait_span, vec ! [ cx. ident_of( krate) ,
182
+ cx. ident_of( "Encodable" ) ,
183
+ cx. ident_of( "encode" ) ] ) ) ;
182
184
183
185
return match * substr. fields {
184
186
Struct ( _, ref fields) => {
@@ -196,8 +198,8 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
196
198
token:: intern_and_get_ident ( & format ! ( "_field{}" , i) )
197
199
}
198
200
} ;
199
- let enc = cx. expr_method_call ( span, self_. clone ( ) ,
200
- encode , vec ! ( blkencoder. clone( ) ) ) ;
201
+ let self_ref = cx. expr_addr_of ( span, self_. clone ( ) ) ;
202
+ let enc = cx . expr_call ( span , fn_path . clone ( ) , vec ! [ self_ref , blkencoder. clone( ) ] ) ;
201
203
let lambda = cx. lambda_expr_1 ( span, enc, blkarg) ;
202
204
let call = cx. expr_method_call ( span, blkencoder. clone ( ) ,
203
205
emit_struct_field,
@@ -245,8 +247,9 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
245
247
if !fields. is_empty ( ) {
246
248
let last = fields. len ( ) - 1 ;
247
249
for ( i, & FieldInfo { ref self_, span, .. } ) in fields. iter ( ) . enumerate ( ) {
248
- let enc = cx. expr_method_call ( span, self_. clone ( ) ,
249
- encode, vec ! ( blkencoder. clone( ) ) ) ;
250
+ let self_ref = cx. expr_addr_of ( span, self_. clone ( ) ) ;
251
+ let enc = cx. expr_call ( span, fn_path. clone ( ) , vec ! [ self_ref,
252
+ blkencoder. clone( ) ] ) ;
250
253
let lambda = cx. lambda_expr_1 ( span, enc, blkarg) ;
251
254
let call = cx. expr_method_call ( span, blkencoder. clone ( ) ,
252
255
emit_variant_arg,
0 commit comments