1
Fork 0

Fix explanation of handling of empty enums

This commit is contained in:
Nadrieril 2019-11-30 15:41:27 +00:00
parent 86fb2ef2e1
commit 063d74f5d9

View file

@ -1267,23 +1267,14 @@ fn all_constructors<'a, 'tcx>(
let is_declared_nonexhaustive = let is_declared_nonexhaustive =
def.is_variant_list_non_exhaustive() && !cx.is_local(pcx.ty); def.is_variant_list_non_exhaustive() && !cx.is_local(pcx.ty);
// If our scrutinee is *privately* an empty enum, we must treat it as though it had // If `exhaustive_patterns` is disabled and our scrutinee is an empty enum, we treat it
// an "unknown" constructor (in that case, all other patterns obviously can't be // as though it had an "unknown" constructor to avoid exposing its emptyness. Note that
// variants) to avoid exposing its emptyness. See the `match_privately_empty` test // an empty match will still be considered exhaustive because that case is handled
// for details. // separately in `check_match`.
let is_privately_empty = if cx.tcx.features().exhaustive_patterns { let is_secretly_empty =
// This cannot happen because we have already filtered out uninhabited variants. def.variants.is_empty() && !cx.tcx.features().exhaustive_patterns;
false
} else {
// FIXME: this is fishy
def.variants.is_empty()
};
if is_privately_empty || is_declared_nonexhaustive { if is_secretly_empty || is_declared_nonexhaustive { vec![NonExhaustive] } else { ctors }
vec![NonExhaustive]
} else {
ctors
}
} }
ty::Char => { ty::Char => {
vec![ vec![