Skip to content

Commit 063d74f

Browse files
committed
Fix explanation of handling of empty enums
1 parent 86fb2ef commit 063d74f

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

src/librustc_mir/hair/pattern/_match.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,23 +1267,14 @@ fn all_constructors<'a, 'tcx>(
12671267
let is_declared_nonexhaustive =
12681268
def.is_variant_list_non_exhaustive() && !cx.is_local(pcx.ty);
12691269

1270-
// If our scrutinee is *privately* an empty enum, we must treat it as though it had
1271-
// an "unknown" constructor (in that case, all other patterns obviously can't be
1272-
// variants) to avoid exposing its emptyness. See the `match_privately_empty` test
1273-
// for details.
1274-
let is_privately_empty = if cx.tcx.features().exhaustive_patterns {
1275-
// This cannot happen because we have already filtered out uninhabited variants.
1276-
false
1277-
} else {
1278-
// FIXME: this is fishy
1279-
def.variants.is_empty()
1280-
};
1281-
1282-
if is_privately_empty || is_declared_nonexhaustive {
1283-
vec![NonExhaustive]
1284-
} else {
1285-
ctors
1286-
}
1270+
// If `exhaustive_patterns` is disabled and our scrutinee is an empty enum, we treat it
1271+
// as though it had an "unknown" constructor to avoid exposing its emptyness. Note that
1272+
// an empty match will still be considered exhaustive because that case is handled
1273+
// separately in `check_match`.
1274+
let is_secretly_empty =
1275+
def.variants.is_empty() && !cx.tcx.features().exhaustive_patterns;
1276+
1277+
if is_secretly_empty || is_declared_nonexhaustive { vec![NonExhaustive] } else { ctors }
12871278
}
12881279
ty::Char => {
12891280
vec![

0 commit comments

Comments
 (0)