Skip to content

Commit 7035d78

Browse files
committed
Enable exhaustive_patterns by default
This doesn't stabilize the feature, it just makes it a no-op. This is to get a perf run as suggested [here]. [here]: #51085 (comment)
1 parent e4c3571 commit 7035d78

File tree

4 files changed

+12
-34
lines changed

4 files changed

+12
-34
lines changed

compiler/rustc_mir_build/src/build/matches/simplify.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
252252
PatKind::Variant { adt_def, substs, variant_index, ref subpatterns } => {
253253
let irrefutable = adt_def.variants.iter_enumerated().all(|(i, v)| {
254254
i == variant_index || {
255-
self.hir.tcx().features().exhaustive_patterns
256-
&& !v
257-
.uninhabited_from(
258-
self.hir.tcx(),
259-
substs,
260-
adt_def.adt_kind(),
261-
self.hir.param_env,
262-
)
263-
.is_empty()
255+
!v.uninhabited_from(
256+
self.hir.tcx(),
257+
substs,
258+
adt_def.adt_kind(),
259+
self.hir.param_env,
260+
)
261+
.is_empty()
264262
}
265263
}) && (adt_def.did.is_local()
266264
|| !adt_def.is_variant_list_non_exhaustive());

compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -835,19 +835,10 @@ fn all_constructors<'p, 'tcx>(pcx: PatCtxt<'_, 'p, 'tcx>) -> Vec<Constructor<'tc
835835
// witness.
836836
let is_declared_nonexhaustive = cx.is_foreign_non_exhaustive_enum(pcx.ty);
837837

838-
// If `exhaustive_patterns` is disabled and our scrutinee is an empty enum, we treat it
839-
// as though it had an "unknown" constructor to avoid exposing its emptiness. The
840-
// exception is if the pattern is at the top level, because we want empty matches to be
841-
// considered exhaustive.
842-
let is_secretly_empty = def.variants.is_empty()
843-
&& !cx.tcx.features().exhaustive_patterns
844-
&& !pcx.is_top_level;
845-
846-
if is_secretly_empty || is_declared_nonexhaustive {
838+
if is_declared_nonexhaustive {
847839
vec![NonExhaustive]
848-
} else if cx.tcx.features().exhaustive_patterns {
849-
// If `exhaustive_patterns` is enabled, we exclude variants known to be
850-
// uninhabited.
840+
} else {
841+
// We exclude variants known to be uninhabited.
851842
def.variants
852843
.iter()
853844
.filter(|v| {
@@ -856,8 +847,6 @@ fn all_constructors<'p, 'tcx>(pcx: PatCtxt<'_, 'p, 'tcx>) -> Vec<Constructor<'tc
856847
})
857848
.map(|v| Variant(v.def_id))
858849
.collect()
859-
} else {
860-
def.variants.iter().map(|v| Variant(v.def_id)).collect()
861850
}
862851
}
863852
ty::Char => {
@@ -887,12 +876,6 @@ fn all_constructors<'p, 'tcx>(pcx: PatCtxt<'_, 'p, 'tcx>) -> Vec<Constructor<'tc
887876
let max = size.truncate(u128::MAX);
888877
vec![make_range(0, max)]
889878
}
890-
// If `exhaustive_patterns` is disabled and our scrutinee is the never type, we cannot
891-
// expose its emptiness. The exception is if the pattern is at the top level, because we
892-
// want empty matches to be considered exhaustive.
893-
ty::Never if !cx.tcx.features().exhaustive_patterns && !pcx.is_top_level => {
894-
vec![NonExhaustive]
895-
}
896879
ty::Never => vec![],
897880
_ if cx.is_uninhabited(pcx.ty) => vec![],
898881
ty::Adt(..) | ty::Tuple(..) | ty::Ref(..) => vec![Single],

compiler/rustc_mir_build/src/thir/pattern/usefulness.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,7 @@ crate struct MatchCheckCtxt<'a, 'tcx> {
338338

339339
impl<'a, 'tcx> MatchCheckCtxt<'a, 'tcx> {
340340
pub(super) fn is_uninhabited(&self, ty: Ty<'tcx>) -> bool {
341-
if self.tcx.features().exhaustive_patterns {
342-
self.tcx.is_ty_uninhabited_from(self.module, ty, self.param_env)
343-
} else {
344-
false
345-
}
341+
self.tcx.is_ty_uninhabited_from(self.module, ty, self.param_env)
346342
}
347343

348344
/// Returns whether the given type is an enum from another crate declared `#[non_exhaustive]`.

compiler/rustc_traits/src/chalk/lowering.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'t
487487
})
488488
}
489489
chalk_ir::LifetimeData::Static => ty::RegionKind::ReStatic,
490+
#[cfg(bootstrap)]
490491
chalk_ir::LifetimeData::Phantom(_, _) => unimplemented!(),
491492
};
492493
interner.tcx.mk_region(kind)

0 commit comments

Comments
 (0)