Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Enable exhaustive_patterns by default #79394

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions compiler/rustc_mir_build/src/build/matches/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
PatKind::Variant { adt_def, substs, variant_index, ref subpatterns } => {
let irrefutable = adt_def.variants.iter_enumerated().all(|(i, v)| {
i == variant_index || {
self.hir.tcx().features().exhaustive_patterns
&& !v
.uninhabited_from(
self.hir.tcx(),
substs,
adt_def.adt_kind(),
self.hir.param_env,
)
.is_empty()
!v.uninhabited_from(
self.hir.tcx(),
substs,
adt_def.adt_kind(),
self.hir.param_env,
)
.is_empty()
}
}) && (adt_def.did.is_local()
|| !adt_def.is_variant_list_non_exhaustive());
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,12 +922,12 @@ impl<'tcx> SplitWildcard<'tcx> {
// exception is if the pattern is at the top level, because we want empty matches to be
// considered exhaustive.
let is_secretly_empty = def.variants.is_empty()
&& !cx.tcx.features().exhaustive_patterns
&& !true
&& !pcx.is_top_level;

if is_secretly_empty || is_declared_nonexhaustive {
smallvec![NonExhaustive]
} else if cx.tcx.features().exhaustive_patterns {
} else if true {
// If `exhaustive_patterns` is enabled, we exclude variants known to be
// uninhabited.
def.variants
Expand Down Expand Up @@ -972,7 +972,7 @@ impl<'tcx> SplitWildcard<'tcx> {
// If `exhaustive_patterns` is disabled and our scrutinee is the never type, we cannot
// expose its emptiness. The exception is if the pattern is at the top level, because we
// want empty matches to be considered exhaustive.
ty::Never if !cx.tcx.features().exhaustive_patterns && !pcx.is_top_level => {
ty::Never if !true && !pcx.is_top_level => {
smallvec![NonExhaustive]
}
ty::Never => smallvec![],
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_mir_build/src/thir/pattern/usefulness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,7 @@ crate struct MatchCheckCtxt<'a, 'tcx> {

impl<'a, 'tcx> MatchCheckCtxt<'a, 'tcx> {
pub(super) fn is_uninhabited(&self, ty: Ty<'tcx>) -> bool {
if self.tcx.features().exhaustive_patterns {
self.tcx.is_ty_uninhabited_from(self.module, ty, self.param_env)
} else {
false
}
self.tcx.is_ty_uninhabited_from(self.module, ty, self.param_env)
}

/// Returns whether the given type is an enum from another crate declared `#[non_exhaustive]`.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_traits/src/chalk/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'t
})
}
chalk_ir::LifetimeData::Static => ty::RegionKind::ReStatic,
#[cfg(bootstrap)]
chalk_ir::LifetimeData::Phantom(_, _) => unimplemented!(),
};
interner.tcx.mk_region(kind)
Expand Down