Skip to content

Commit 160eebe

Browse files
committed
Only need TyErr for uninhabited types
1 parent a5294b6 commit 160eebe

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/librustc_mir_build/hair/pattern/_match.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -880,15 +880,15 @@ impl<'tcx> Constructor<'tcx> {
880880
let ty = field.ty(cx.tcx, substs);
881881
let is_visible = adt.is_enum()
882882
|| field.vis.is_accessible_from(cx.module, cx.tcx);
883-
let is_uninhabited = cx.is_uninhabited(ty);
884-
// Treat all non-visible fields as `TyErr`. They can't appear
885-
// in any other pattern from this match (because they are
883+
let is_inhabited = !cx.is_uninhabited(ty);
884+
// Treat all uninhabited non-visible fields as `TyErr`. They can't
885+
// appear in any other pattern from this match (because they are
886886
// private), so their type does not matter - but we don't want
887887
// to know they are uninhabited.
888888
// Also treat all uninhabited types in non-exhaustive variants as
889889
// `TyErr`.
890890
let allowed_to_inspect =
891-
is_visible && !(is_non_exhaustive && is_uninhabited);
891+
is_inhabited || (is_visible && !is_non_exhaustive);
892892

893893
if allowed_to_inspect {
894894
Pat::wildcard_from_ty(ty)

0 commit comments

Comments
 (0)