Skip to content

Commit

Permalink
fix derive(RustcEncodable, RustcDecodable)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skgland committed Feb 9, 2021
1 parent 091ef95 commit 0375022
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
15 changes: 6 additions & 9 deletions compiler/rustc_builtin_macros/src/deriving/decodable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn decodable_substructure(
Named(ref fields) => fields.len(),
};
let fn_read_struct_field_path: Vec<_> =
cx.def_site_path(&[sym::rustc_serialize, sym::Decodable, sym::read_struct_field]);
cx.def_site_path(&[sym::rustc_serialize, sym::Decoder, sym::read_struct_field]);

let path = cx.path_ident(trait_span, substr.type_ident);
let result =
Expand All @@ -113,7 +113,7 @@ fn decodable_substructure(
});
let result = cx.expr_ok(trait_span, result);
let fn_read_struct_path: Vec<_> =
cx.def_site_path(&[sym::rustc_serialize, sym::Decodable, sym::read_struct]);
cx.def_site_path(&[sym::rustc_serialize, sym::Decoder, sym::read_struct]);

cx.expr_call_global(
trait_span,
Expand All @@ -132,11 +132,8 @@ fn decodable_substructure(
let mut arms = Vec::with_capacity(fields.len() + 1);
let mut variants = Vec::with_capacity(fields.len());

let fn_read_enum_variant_arg_path: Vec<_> = cx.def_site_path(&[
sym::rustc_serialize,
sym::Decodable,
sym::read_enum_variant_arg,
]);
let fn_read_enum_variant_arg_path: Vec<_> =
cx.def_site_path(&[sym::rustc_serialize, sym::Decoder, sym::read_enum_variant_arg]);

for (i, &(ident, v_span, ref parts)) in fields.iter().enumerate() {
variants.push(cx.expr_str(v_span, ident.name));
Expand Down Expand Up @@ -168,14 +165,14 @@ fn decodable_substructure(
let variant_vec = cx.expr_vec(trait_span, variants);
let variant_vec = cx.expr_addr_of(trait_span, variant_vec);
let fn_read_enum_variant_path: Vec<_> =
cx.def_site_path(&[sym::rustc_serialize, sym::Decodable, sym::read_enum_variant]);
cx.def_site_path(&[sym::rustc_serialize, sym::Decoder, sym::read_enum_variant]);
let result = cx.expr_call_global(
trait_span,
fn_read_enum_variant_path,
vec![blkdecoder, variant_vec, lambda],
);
let fn_read_enum_path: Vec<_> =
cx.def_site_path(&[sym::rustc_serialize, sym::Decodable, sym::read_enum]);
cx.def_site_path(&[sym::rustc_serialize, sym::Decoder, sym::read_enum]);

cx.expr_call_global(
trait_span,
Expand Down
15 changes: 6 additions & 9 deletions compiler/rustc_builtin_macros/src/deriving/encodable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ fn encodable_substructure(
match *substr.fields {
Struct(_, ref fields) => {
let fn_emit_struct_field_path =
cx.def_site_path(&[sym::rustc_serialize, sym::Encodable, sym::emit_struct_field]);
cx.def_site_path(&[sym::rustc_serialize, sym::Encoder, sym::emit_struct_field]);
let mut stmts = Vec::new();
for (i, &FieldInfo { name, ref self_, span, .. }) in fields.iter().enumerate() {
let name = match name {
Expand Down Expand Up @@ -222,7 +222,7 @@ fn encodable_substructure(
};

let fn_emit_struct_path =
cx.def_site_path(&[sym::rustc_serialize, sym::Encodable, sym::emit_struct]);
cx.def_site_path(&[sym::rustc_serialize, sym::Encoder, sym::emit_struct]);

cx.expr_call_global(
trait_span,
Expand All @@ -244,11 +244,8 @@ fn encodable_substructure(
let me = cx.stmt_let(trait_span, false, blkarg, encoder);
let encoder = cx.expr_ident(trait_span, blkarg);

let fn_emit_enum_variant_arg_path: Vec<_> = cx.def_site_path(&[
sym::rustc_serialize,
sym::Encodable,
sym::emit_enum_variant_arg,
]);
let fn_emit_enum_variant_arg_path: Vec<_> =
cx.def_site_path(&[sym::rustc_serialize, sym::Encoder, sym::emit_enum_variant_arg]);

let mut stmts = Vec::new();
if !fields.is_empty() {
Expand Down Expand Up @@ -281,7 +278,7 @@ fn encodable_substructure(
let name = cx.expr_str(trait_span, variant.ident.name);

let fn_emit_enum_variant_path: Vec<_> =
cx.def_site_path(&[sym::rustc_serialize, sym::Encodable, sym::emit_enum_variant]);
cx.def_site_path(&[sym::rustc_serialize, sym::Encoder, sym::emit_enum_variant]);

let call = cx.expr_call_global(
trait_span,
Expand All @@ -297,7 +294,7 @@ fn encodable_substructure(

let blk = cx.lambda1(trait_span, call, blkarg);
let fn_emit_enum_path: Vec<_> =
cx.def_site_path(&[sym::rustc_serialize, sym::Encodable, sym::emit_enum]);
cx.def_site_path(&[sym::rustc_serialize, sym::Encoder, sym::emit_enum]);
let ret = cx.expr_call_global(
trait_span,
fn_emit_enum_path,
Expand Down

0 comments on commit 0375022

Please sign in to comment.