Skip to content

Commit 8ee5761

Browse files
committed
Stabilize min_exhaustive_patterns
1 parent 5945222 commit 8ee5761

File tree

5 files changed

+14
-30
lines changed

5 files changed

+14
-30
lines changed

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

+5-8
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,11 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
229229
subpairs = cx.field_match_pairs(downcast_place, subpatterns);
230230

231231
let irrefutable = adt_def.variants().iter_enumerated().all(|(i, v)| {
232-
i == variant_index || {
233-
(cx.tcx.features().exhaustive_patterns
234-
|| cx.tcx.features().min_exhaustive_patterns)
235-
&& !v
236-
.inhabited_predicate(cx.tcx, adt_def)
237-
.instantiate(cx.tcx, args)
238-
.apply_ignore_module(cx.tcx, cx.param_env)
239-
}
232+
i == variant_index
233+
|| !v
234+
.inhabited_predicate(cx.tcx, adt_def)
235+
.instantiate(cx.tcx, args)
236+
.apply_ignore_module(cx.tcx, cx.param_env)
240237
}) && (adt_def.did().is_local()
241238
|| !adt_def.is_variant_list_non_exhaustive());
242239
if irrefutable {

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -669,9 +669,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
669669

670670
// Emit an extra note if the first uncovered witness would be uninhabited
671671
// if we disregard visibility.
672-
let witness_1_is_privately_uninhabited = if (self.tcx.features().exhaustive_patterns
673-
|| self.tcx.features().min_exhaustive_patterns)
674-
&& let Some(witness_1) = witnesses.get(0)
672+
let witness_1_is_privately_uninhabited = if let Some(witness_1) = witnesses.get(0)
675673
&& let ty::Adt(adt, args) = witness_1.ty().kind()
676674
&& adt.is_enum()
677675
&& let Constructor::Variant(variant_index) = witness_1.ctor()

compiler/rustc_pattern_analysis/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ pub trait PatCx: Sized + fmt::Debug {
9999
type PatData: Clone;
100100

101101
fn is_exhaustive_patterns_feature_on(&self) -> bool;
102-
fn is_min_exhaustive_patterns_feature_on(&self) -> bool;
103102

104103
/// The number of fields for this constructor.
105104
fn ctor_arity(&self, ctor: &Constructor<Self>, ty: &Self::Ty) -> usize;

compiler/rustc_pattern_analysis/src/rustc.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
224224
let tys = cx.variant_sub_tys(ty, variant).map(|(field, ty)| {
225225
let is_visible =
226226
adt.is_enum() || field.vis.is_accessible_from(cx.module, cx.tcx);
227-
let is_uninhabited = (cx.tcx.features().exhaustive_patterns
228-
|| cx.tcx.features().min_exhaustive_patterns)
229-
&& cx.is_uninhabited(*ty);
227+
let is_uninhabited = cx.is_uninhabited(*ty);
230228
let skip = is_uninhabited && (!is_visible || is_non_exhaustive);
231229
(ty, PrivateUninhabitedField(skip))
232230
});
@@ -850,9 +848,6 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> {
850848
fn is_exhaustive_patterns_feature_on(&self) -> bool {
851849
self.tcx.features().exhaustive_patterns
852850
}
853-
fn is_min_exhaustive_patterns_feature_on(&self) -> bool {
854-
self.tcx.features().min_exhaustive_patterns
855-
}
856851

857852
fn ctor_arity(&self, ctor: &crate::constructor::Constructor<Self>, ty: &Self::Ty) -> usize {
858853
self.ctor_arity(ctor, *ty)

compiler/rustc_pattern_analysis/src/usefulness.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -543,13 +543,11 @@
543543
//! recurse into subpatterns. That second part is done through [`PlaceValidity`], most notably
544544
//! [`PlaceValidity::specialize`].
545545
//!
546-
//! Having said all that, in practice we don't fully follow what's been presented in this section.
547-
//! Let's call "toplevel exception" the case where the match scrutinee itself has type `!` or
548-
//! `EmptyEnum`. First, on stable rust, we require `_` patterns for empty types in all cases apart
549-
//! from the toplevel exception. The `exhaustive_patterns` and `min_exaustive_patterns` allow
550-
//! omitting patterns in the cases described above. There's a final detail: in the toplevel
551-
//! exception or with the `exhaustive_patterns` feature, we ignore place validity when checking
552-
//! whether a pattern is required for exhaustiveness. I (Nadrieril) hope to deprecate this behavior.
546+
//! Having said all that, we don't fully follow what's been presented in this section. For
547+
//! backwards-compatibility, we ignore place validity when checking whether a pattern is required
548+
//! for exhaustiveness in two cases: when the `exhaustive_patterns` feature gate is on, or when the
549+
//! match scrutinee itself has type `!` or `EmptyEnum`. I (Nadrieril) hope to deprecate this
550+
//! exception.
553551
//!
554552
//!
555553
//!
@@ -883,13 +881,10 @@ impl<Cx: PatCx> PlaceInfo<Cx> {
883881
self.is_scrutinee && matches!(ctors_for_ty, ConstructorSet::NoConstructors);
884882
// Whether empty patterns are counted as useful or not. We only warn an empty arm unreachable if
885883
// it is guaranteed unreachable by the opsem (i.e. if the place is `known_valid`).
886-
let empty_arms_are_unreachable = self.validity.is_known_valid()
887-
&& (is_toplevel_exception
888-
|| cx.is_exhaustive_patterns_feature_on()
889-
|| cx.is_min_exhaustive_patterns_feature_on());
884+
let empty_arms_are_unreachable = self.validity.is_known_valid();
890885
// Whether empty patterns can be omitted for exhaustiveness. We ignore place validity in the
891886
// toplevel exception and `exhaustive_patterns` cases for backwards compatibility.
892-
let can_omit_empty_arms = empty_arms_are_unreachable
887+
let can_omit_empty_arms = self.validity.is_known_valid()
893888
|| is_toplevel_exception
894889
|| cx.is_exhaustive_patterns_feature_on();
895890

0 commit comments

Comments
 (0)