Skip to content

Avoid unnecessary closures when deriving RustcDecodable #21199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/libsyntax/ext/deriving/decodable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ fn decodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
let recurse = vec!(cx.ident_of(krate),
cx.ident_of("Decodable"),
cx.ident_of("decode"));
let exprdecode = cx.expr_path(cx.path_global(trait_span, recurse));
// throw an underscore in front to suppress unused variable warnings
let blkarg = cx.ident_of("_d");
let blkdecoder = cx.expr_ident(trait_span, blkarg);
let calldecode = cx.expr_call_global(trait_span, recurse, vec!(blkdecoder.clone()));
let lambdadecode = cx.lambda_expr_1(trait_span, calldecode, blkarg);

return match *substr.fields {
StaticStruct(_, ref summary) => {
Expand All @@ -116,7 +115,7 @@ fn decodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
cx.expr_method_call(span, blkdecoder.clone(), read_struct_field,
vec!(cx.expr_str(span, name),
cx.expr_uint(span, field),
lambdadecode.clone())))
exprdecode.clone())))
});
let result = cx.expr_ok(trait_span, result);
cx.expr_method_call(trait_span,
Expand Down Expand Up @@ -147,7 +146,7 @@ fn decodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
let idx = cx.expr_uint(span, field);
cx.expr_try(span,
cx.expr_method_call(span, blkdecoder.clone(), rvariant_arg,
vec!(idx, lambdadecode.clone())))
vec!(idx, exprdecode.clone())))
});

arms.push(cx.arm(v_span,
Expand Down