@@ -162,7 +162,7 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt,
162162 attributes: Vec :: new( ) ,
163163 is_unsafe: false ,
164164 combine_substructure: combine_substructure( Box :: new( |a, b, c| {
165- encodable_substructure( a, b, c)
165+ encodable_substructure( a, b, c, krate )
166166 } ) ) ,
167167 }
168168 ) ,
@@ -173,12 +173,14 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt,
173173}
174174
175175fn encodable_substructure ( cx : & mut ExtCtxt , trait_span : Span ,
176- substr : & Substructure ) -> P < Expr > {
176+ substr : & Substructure , krate : & ' static str ) -> P < Expr > {
177177 let encoder = substr. nonself_args [ 0 ] . clone ( ) ;
178178 // throw an underscore in front to suppress unused variable warnings
179179 let blkarg = cx. ident_of ( "_e" ) ;
180180 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" ) ] ) ) ;
182184
183185 return match * substr. fields {
184186 Struct ( _, ref fields) => {
@@ -196,8 +198,8 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
196198 token:: intern_and_get_ident ( & format ! ( "_field{}" , i) )
197199 }
198200 } ;
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( ) ] ) ;
201203 let lambda = cx. lambda_expr_1 ( span, enc, blkarg) ;
202204 let call = cx. expr_method_call ( span, blkencoder. clone ( ) ,
203205 emit_struct_field,
@@ -245,8 +247,9 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
245247 if !fields. is_empty ( ) {
246248 let last = fields. len ( ) - 1 ;
247249 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( ) ] ) ;
250253 let lambda = cx. lambda_expr_1 ( span, enc, blkarg) ;
251254 let call = cx. expr_method_call ( span, blkencoder. clone ( ) ,
252255 emit_variant_arg,
0 commit comments