Skip to content

Commit

Permalink
Optimise decode return expression for unit structs
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Mar 22, 2018
1 parent 0d278ca commit ad50f33
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/libsyntax_ext/deriving/encodable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ fn encodable_substructure(cx: &mut ExtCtxt,
}

// unit structs have no fields and need to return Ok()
if stmts.is_empty() {
let blk = if stmts.is_empty() {
let ok = cx.expr_ok(trait_span, cx.expr_tuple(trait_span, vec![]));
let ret_ok = cx.expr(trait_span, ExprKind::Ret(Some(ok)));
stmts.push(cx.stmt_expr(ret_ok));
}
cx.lambda1(trait_span, ok, blkarg)
} else {
cx.lambda_stmts_1(trait_span, stmts, blkarg)
};

let blk = cx.lambda_stmts_1(trait_span, stmts, blkarg);
cx.expr_method_call(trait_span,
encoder,
cx.ident_of("emit_struct"),
Expand Down

0 comments on commit ad50f33

Please sign in to comment.