let trait_def = TraitDef {
span,
attributes: Vec::new(),
- path: Path::new_(vec![krate, sym::Decodable], None, vec![], PathKind::Global),
+ path: Path::new_(vec![krate, sym::Decodable], vec![], PathKind::Global),
additional_bounds: Vec::new(),
generics: Bounds::empty(),
- is_unsafe: false,
supports_unions: false,
methods: vec![MethodDef {
name: sym::decode,
generics: Bounds {
bounds: vec![(
typaram,
- vec![Path::new_(vec![krate, sym::Decoder], None, vec![], PathKind::Global)],
+ vec![Path::new_(vec![krate, sym::Decoder], vec![], PathKind::Global)],
)],
},
- explicit_self: None,
- args: vec![(
- Ptr(Box::new(Literal(Path::new_local(typaram))), Borrowed(None, Mutability::Mut)),
+ explicit_self: false,
+ nonself_args: vec![(
+ Ref(Box::new(Path(Path::new_local(typaram))), Mutability::Mut),
sym::d,
)],
- ret_ty: Literal(Path::new_(
+ ret_ty: Path(Path::new_(
pathvec_std!(result::Result),
- None,
vec![
Box::new(Self_),
- Box::new(Literal(Path::new_(
- vec![typaram, sym::Error],
- None,
- vec![],
- PathKind::Local,
- ))),
+ Box::new(Path(Path::new_(vec![typaram, sym::Error], vec![], PathKind::Local))),
],
PathKind::Std,
)),
attributes: Vec::new(),
- is_unsafe: false,
unify_fieldless_variants: false,
combine_substructure: combine_substructure(Box::new(|a, b, c| {
decodable_substructure(a, b, c, krate)
trait_span: Span,
substr: &Substructure<'_>,
krate: Symbol,
-) -> P<Expr> {
- let decoder = substr.nonself_args[0].clone();
+) -> BlockOrExpr {
+ let decoder = substr.nonselflike_args[0].clone();
let recurse = vec![
Ident::new(krate, trait_span),
Ident::new(sym::Decodable, trait_span),
let blkarg = Ident::new(sym::_d, trait_span);
let blkdecoder = cx.expr_ident(trait_span, blkarg);
- match *substr.fields {
+ let expr = match *substr.fields {
StaticStruct(_, ref summary) => {
let nfields = match *summary {
Unnamed(ref fields, _) => fields.len(),
cx.expr_match(trait_span, cx.expr_ident(trait_span, variant), arms),
);
let lambda = cx.lambda(trait_span, vec![blkarg, variant], result);
- let variant_vec = cx.expr_vec(trait_span, variants);
- let variant_vec = cx.expr_addr_of(trait_span, variant_vec);
+ let variant_array_ref = cx.expr_array_ref(trait_span, variants);
let fn_read_enum_variant_path: Vec<_> =
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],
+ vec![blkdecoder, variant_array_ref, lambda],
);
let fn_read_enum_path: Vec<_> =
cx.def_site_path(&[sym::rustc_serialize, sym::Decoder, sym::read_enum]);
)
}
_ => cx.bug("expected StaticEnum or StaticStruct in derive(Decodable)"),
- }
+ };
+ BlockOrExpr::new_expr(expr)
}
/// Creates a decoder for a single enum variant/struct: