Skip to content

Commit 4bcbd76

Browse files
committed
Move the no-variants handling code earlier in expand_enum_method_body.
To avoid computing a bunch of stuff that it doesn't need.
1 parent f1d9e2b commit 4bcbd76

File tree

1 file changed

+6
-5
lines changed
  • compiler/rustc_builtin_macros/src/deriving/generic

1 file changed

+6
-5
lines changed

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,12 @@ impl<'a> MethodDef<'a> {
11731173
let span = trait_.span;
11741174
let variants = &enum_def.variants;
11751175

1176+
// There is no sensible code to be generated for *any* deriving on a
1177+
// zero-variant enum. So we just generate a failing expression.
1178+
if variants.is_empty() {
1179+
return BlockOrExpr(vec![], Some(deriving::call_unreachable(cx, span)));
1180+
}
1181+
11761182
let prefixes = iter::once("__self".to_string())
11771183
.chain(
11781184
selflike_args
@@ -1365,11 +1371,6 @@ impl<'a> MethodDef<'a> {
13651371
let all_match = cx.expr_match(span, match_arg, match_arms);
13661372
let arm_expr = cx.expr_if(span, discriminant_test, all_match, Some(arm_expr));
13671373
BlockOrExpr(index_let_stmts, Some(arm_expr))
1368-
} else if variants.is_empty() {
1369-
// There is no sensible code to be generated for *any* deriving on
1370-
// a zero-variant enum. So we just generate a failing expression
1371-
// for the zero variant case.
1372-
BlockOrExpr(vec![], Some(deriving::call_unreachable(cx, span)))
13731374
} else {
13741375
let match_arg = if selflike_args.len() == 1 {
13751376
selflike_args.pop().unwrap()

0 commit comments

Comments
 (0)