use ufcs in derive(RustDecodable)
This commit is contained in:
parent
525fc4b8e4
commit
091ef95f8e
@ -91,18 +91,19 @@ fn decodable_substructure(
|
|||||||
Unnamed(ref fields, _) => fields.len(),
|
Unnamed(ref fields, _) => fields.len(),
|
||||||
Named(ref fields) => fields.len(),
|
Named(ref fields) => fields.len(),
|
||||||
};
|
};
|
||||||
let read_struct_field = Ident::new(sym::read_struct_field, trait_span);
|
let fn_read_struct_field_path: Vec<_> =
|
||||||
|
cx.def_site_path(&[sym::rustc_serialize, sym::Decodable, sym::read_struct_field]);
|
||||||
|
|
||||||
let path = cx.path_ident(trait_span, substr.type_ident);
|
let path = cx.path_ident(trait_span, substr.type_ident);
|
||||||
let result =
|
let result =
|
||||||
decode_static_fields(cx, trait_span, path, summary, |cx, span, name, field| {
|
decode_static_fields(cx, trait_span, path, summary, |cx, span, name, field| {
|
||||||
cx.expr_try(
|
cx.expr_try(
|
||||||
span,
|
span,
|
||||||
cx.expr_method_call(
|
cx.expr_call_global(
|
||||||
span,
|
span,
|
||||||
blkdecoder.clone(),
|
fn_read_struct_field_path.clone(),
|
||||||
read_struct_field,
|
|
||||||
vec![
|
vec![
|
||||||
|
blkdecoder.clone(),
|
||||||
cx.expr_str(span, name),
|
cx.expr_str(span, name),
|
||||||
cx.expr_usize(span, field),
|
cx.expr_usize(span, field),
|
||||||
exprdecode.clone(),
|
exprdecode.clone(),
|
||||||
@ -111,11 +112,14 @@ fn decodable_substructure(
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
let result = cx.expr_ok(trait_span, result);
|
let result = cx.expr_ok(trait_span, result);
|
||||||
cx.expr_method_call(
|
let fn_read_struct_path: Vec<_> =
|
||||||
|
cx.def_site_path(&[sym::rustc_serialize, sym::Decodable, sym::read_struct]);
|
||||||
|
|
||||||
|
cx.expr_call_global(
|
||||||
trait_span,
|
trait_span,
|
||||||
decoder,
|
fn_read_struct_path,
|
||||||
Ident::new(sym::read_struct, trait_span),
|
|
||||||
vec![
|
vec![
|
||||||
|
decoder,
|
||||||
cx.expr_str(trait_span, substr.type_ident.name),
|
cx.expr_str(trait_span, substr.type_ident.name),
|
||||||
cx.expr_usize(trait_span, nfields),
|
cx.expr_usize(trait_span, nfields),
|
||||||
cx.lambda1(trait_span, result, blkarg),
|
cx.lambda1(trait_span, result, blkarg),
|
||||||
@ -127,7 +131,12 @@ fn decodable_substructure(
|
|||||||
|
|
||||||
let mut arms = Vec::with_capacity(fields.len() + 1);
|
let mut arms = Vec::with_capacity(fields.len() + 1);
|
||||||
let mut variants = Vec::with_capacity(fields.len());
|
let mut variants = Vec::with_capacity(fields.len());
|
||||||
let rvariant_arg = Ident::new(sym::read_enum_variant_arg, trait_span);
|
|
||||||
|
let fn_read_enum_variant_arg_path: Vec<_> = cx.def_site_path(&[
|
||||||
|
sym::rustc_serialize,
|
||||||
|
sym::Decodable,
|
||||||
|
sym::read_enum_variant_arg,
|
||||||
|
]);
|
||||||
|
|
||||||
for (i, &(ident, v_span, ref parts)) in fields.iter().enumerate() {
|
for (i, &(ident, v_span, ref parts)) in fields.iter().enumerate() {
|
||||||
variants.push(cx.expr_str(v_span, ident.name));
|
variants.push(cx.expr_str(v_span, ident.name));
|
||||||
@ -138,11 +147,10 @@ fn decodable_substructure(
|
|||||||
let idx = cx.expr_usize(span, field);
|
let idx = cx.expr_usize(span, field);
|
||||||
cx.expr_try(
|
cx.expr_try(
|
||||||
span,
|
span,
|
||||||
cx.expr_method_call(
|
cx.expr_call_global(
|
||||||
span,
|
span,
|
||||||
blkdecoder.clone(),
|
fn_read_enum_variant_arg_path.clone(),
|
||||||
rvariant_arg,
|
vec![blkdecoder.clone(), idx, exprdecode.clone()],
|
||||||
vec![idx, exprdecode.clone()],
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
@ -159,17 +167,21 @@ fn decodable_substructure(
|
|||||||
let lambda = cx.lambda(trait_span, vec![blkarg, variant], result);
|
let lambda = cx.lambda(trait_span, vec![blkarg, variant], result);
|
||||||
let variant_vec = cx.expr_vec(trait_span, variants);
|
let variant_vec = cx.expr_vec(trait_span, variants);
|
||||||
let variant_vec = cx.expr_addr_of(trait_span, variant_vec);
|
let variant_vec = cx.expr_addr_of(trait_span, variant_vec);
|
||||||
let result = cx.expr_method_call(
|
let fn_read_enum_variant_path: Vec<_> =
|
||||||
|
cx.def_site_path(&[sym::rustc_serialize, sym::Decodable, sym::read_enum_variant]);
|
||||||
|
let result = cx.expr_call_global(
|
||||||
trait_span,
|
trait_span,
|
||||||
blkdecoder,
|
fn_read_enum_variant_path,
|
||||||
Ident::new(sym::read_enum_variant, trait_span),
|
vec![blkdecoder, variant_vec, lambda],
|
||||||
vec![variant_vec, lambda],
|
|
||||||
);
|
);
|
||||||
cx.expr_method_call(
|
let fn_read_enum_path: Vec<_> =
|
||||||
|
cx.def_site_path(&[sym::rustc_serialize, sym::Decodable, sym::read_enum]);
|
||||||
|
|
||||||
|
cx.expr_call_global(
|
||||||
trait_span,
|
trait_span,
|
||||||
decoder,
|
fn_read_enum_path,
|
||||||
Ident::new(sym::read_enum, trait_span),
|
|
||||||
vec![
|
vec![
|
||||||
|
decoder,
|
||||||
cx.expr_str(trait_span, substr.type_ident.name),
|
cx.expr_str(trait_span, substr.type_ident.name),
|
||||||
cx.lambda1(trait_span, result, blkarg),
|
cx.lambda1(trait_span, result, blkarg),
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user