Skip to content

Commit 65d0bfb

Browse files
committed
Cut down large comment about zero-variant enums.
When deriving functions for zero-variant enums, we just generated a function body that calls `std::instrincs::unreachable`. There is a large comment with some not-very-useful historical discussion about alternatives, including some discussion of feature-gating zero-variant enums, which is clearly irrelevant today. This commit cuts the comment down greatly.
1 parent 7f1dfca commit 65d0bfb

File tree

1 file changed

+3
-49
lines changed
  • compiler/rustc_builtin_macros/src/deriving/generic

1 file changed

+3
-49
lines changed

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

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,55 +1378,9 @@ impl<'a> MethodDef<'a> {
13781378
let arm_expr = cx.expr_if(span, discriminant_test, all_match, Some(arm_expr));
13791379
BlockOrExpr(index_let_stmts, Some(arm_expr))
13801380
} else if variants.is_empty() {
1381-
// As an additional wrinkle, For a zero-variant enum A,
1382-
// currently the compiler
1383-
// will accept `fn (a: &Self) { match *a { } }`
1384-
// but rejects `fn (a: &Self) { match (&*a,) { } }`
1385-
// as well as `fn (a: &Self) { match ( *a,) { } }`
1386-
//
1387-
// This means that the strategy of building up a tuple of
1388-
// all Self arguments fails when Self is a zero variant
1389-
// enum: rustc rejects the expanded program, even though
1390-
// the actual code tends to be impossible to execute (at
1391-
// least safely), according to the type system.
1392-
//
1393-
// The most expedient fix for this is to just let the
1394-
// code fall through to the catch-all. But even this is
1395-
// error-prone, since the catch-all as defined above would
1396-
// generate code like this:
1397-
//
1398-
// _ => { let __self0 = match *self { };
1399-
// let __self1 = match *__arg_0 { };
1400-
// <catch-all-expr> }
1401-
//
1402-
// Which is yields bindings for variables which type
1403-
// inference cannot resolve to unique types.
1404-
//
1405-
// One option to the above might be to add explicit type
1406-
// annotations. But the *only* reason to go down that path
1407-
// would be to try to make the expanded output consistent
1408-
// with the case when the number of enum variants >= 1.
1409-
//
1410-
// That just isn't worth it. In fact, trying to generate
1411-
// sensible code for *any* deriving on a zero-variant enum
1412-
// does not make sense. But at the same time, for now, we
1413-
// do not want to cause a compile failure just because the
1414-
// user happened to attach a deriving to their
1415-
// zero-variant enum.
1416-
//
1417-
// Instead, just generate a failing expression for the
1418-
// zero variant case, skipping matches and also skipping
1419-
// delegating back to the end user code entirely.
1420-
//
1421-
// (See also #4499 and #12609; note that some of the
1422-
// discussions there influence what choice we make here;
1423-
// e.g., if we feature-gate `match x { ... }` when x refers
1424-
// to an uninhabited type (e.g., a zero-variant enum or a
1425-
// type holding such an enum), but do not feature-gate
1426-
// zero-variant enums themselves, then attempting to
1427-
// derive Debug on such a type could here generate code
1428-
// that needs the feature gate enabled.)
1429-
1381+
// There is no sensible code to be generated for *any* deriving on
1382+
// a zero-variant enum. So we just generate a failing expression
1383+
// for the zero variant case.
14301384
BlockOrExpr(vec![], Some(deriving::call_unreachable(cx, span)))
14311385
} else {
14321386
// Final wrinkle: the selflike_args are expressions that deref

0 commit comments

Comments
 (0)