mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-14 16:03:17 +00:00
Move the no-variants handling code earlier in expand_enum_method_body
.
To avoid computing a bunch of stuff that it doesn't need.
This commit is contained in:
parent
f1d9e2b50c
commit
4bcbd76bc9
@ -1173,6 +1173,12 @@ impl<'a> MethodDef<'a> {
|
||||
let span = trait_.span;
|
||||
let variants = &enum_def.variants;
|
||||
|
||||
// There is no sensible code to be generated for *any* deriving on a
|
||||
// zero-variant enum. So we just generate a failing expression.
|
||||
if variants.is_empty() {
|
||||
return BlockOrExpr(vec![], Some(deriving::call_unreachable(cx, span)));
|
||||
}
|
||||
|
||||
let prefixes = iter::once("__self".to_string())
|
||||
.chain(
|
||||
selflike_args
|
||||
@ -1365,11 +1371,6 @@ impl<'a> MethodDef<'a> {
|
||||
let all_match = cx.expr_match(span, match_arg, match_arms);
|
||||
let arm_expr = cx.expr_if(span, discriminant_test, all_match, Some(arm_expr));
|
||||
BlockOrExpr(index_let_stmts, Some(arm_expr))
|
||||
} else if variants.is_empty() {
|
||||
// There is no sensible code to be generated for *any* deriving on
|
||||
// a zero-variant enum. So we just generate a failing expression
|
||||
// for the zero variant case.
|
||||
BlockOrExpr(vec![], Some(deriving::call_unreachable(cx, span)))
|
||||
} else {
|
||||
let match_arg = if selflike_args.len() == 1 {
|
||||
selflike_args.pop().unwrap()
|
||||
|
Loading…
Reference in New Issue
Block a user