about summary refs log tree commit diff
path: root/src/libsyntax_ext
diff options
context:
space:
mode:
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>2016-04-12 15:41:46 +0200
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>2016-04-12 15:41:46 +0200
commit2fd2210b880498829bf1556aee47f3753887ecfa (patch)
tree637b875edac406c6d91460d3225640c2a9e425dc /src/libsyntax_ext
parent28c9fdafc06a259c25c1b889044fd49b4dfc69e2 (diff)
downloadrust-2fd2210b880498829bf1556aee47f3753887ecfa.tar.gz
rust-2fd2210b880498829bf1556aee47f3753887ecfa.zip
prevent other `encode` methods from breaking `derive(RustcEncodable)`
Diffstat (limited to 'src/libsyntax_ext')
-rw-r--r--src/libsyntax_ext/deriving/encodable.rs17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/libsyntax_ext/deriving/encodable.rs b/src/libsyntax_ext/deriving/encodable.rs
index a05bd7869b2..6e47f2dd08f 100644
--- a/src/libsyntax_ext/deriving/encodable.rs
+++ b/src/libsyntax_ext/deriving/encodable.rs
@@ -162,7 +162,7 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt,
                 attributes: Vec::new(),
                 is_unsafe: false,
                 combine_substructure: combine_substructure(Box::new(|a, b, c| {
-                    encodable_substructure(a, b, c)
+                    encodable_substructure(a, b, c, krate)
                 })),
             }
         ),
@@ -173,12 +173,14 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt,
 }
 
 fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
-                          substr: &Substructure) -> P<Expr> {
+                          substr: &Substructure, krate: &'static str) -> P<Expr> {
     let encoder = substr.nonself_args[0].clone();
     // throw an underscore in front to suppress unused variable warnings
     let blkarg = cx.ident_of("_e");
     let blkencoder = cx.expr_ident(trait_span, blkarg);
-    let encode = cx.ident_of("encode");
+    let fn_path = cx.expr_path(cx.path_global(trait_span, vec![cx.ident_of(krate),
+                                                               cx.ident_of("Encodable"),
+                                                               cx.ident_of("encode")]));
 
     return match *substr.fields {
         Struct(_, ref fields) => {
@@ -196,8 +198,8 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
                         token::intern_and_get_ident(&format!("_field{}", i))
                     }
                 };
-                let enc = cx.expr_method_call(span, self_.clone(),
-                                              encode, vec!(blkencoder.clone()));
+                let self_ref = cx.expr_addr_of(span, self_.clone());
+                let enc = cx.expr_call(span, fn_path.clone(), vec![self_ref, blkencoder.clone()]);
                 let lambda = cx.lambda_expr_1(span, enc, blkarg);
                 let call = cx.expr_method_call(span, blkencoder.clone(),
                                                emit_struct_field,
@@ -245,8 +247,9 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
             if !fields.is_empty() {
                 let last = fields.len() - 1;
                 for (i, &FieldInfo { ref self_, span, .. }) in fields.iter().enumerate() {
-                    let enc = cx.expr_method_call(span, self_.clone(),
-                                                  encode, vec!(blkencoder.clone()));
+                let self_ref = cx.expr_addr_of(span, self_.clone());
+                    let enc = cx.expr_call(span, fn_path.clone(), vec![self_ref,
+                                                                       blkencoder.clone()]);
                     let lambda = cx.lambda_expr_1(span, enc, blkarg);
                     let call = cx.expr_method_call(span, blkencoder.clone(),
                                                    emit_variant_arg,