Skip to content

Commit cd40769

Browse files
committed
Stabilize min_exhaustive_patterns
1 parent 19469cb commit cd40769

File tree

10 files changed

+19
-39
lines changed

10 files changed

+19
-39
lines changed

Diff for: compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ declare_features! (
267267
(accepted, min_const_generics, "1.51.0", Some(74878)),
268268
/// Allows calling `const unsafe fn` inside `unsafe` blocks in `const fn` functions.
269269
(accepted, min_const_unsafe_fn, "1.33.0", Some(55607)),
270+
/// Allows exhaustive pattern matching on uninhabited types when matched by value.
271+
(accepted, min_exhaustive_patterns, "CURRENT_RUSTC_VERSION", Some(119612)),
270272
/// Allows using `Self` and associated types in struct expressions and patterns.
271273
(accepted, more_struct_aliases, "1.16.0", Some(37544)),
272274
/// Allows using the MOVBE target feature.

Diff for: compiler/rustc_feature/src/unstable.rs

-3
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,6 @@ declare_features! (
519519
(unstable, macro_metavar_expr_concat, "1.81.0", Some(124225)),
520520
/// Allows `#[marker]` on certain traits allowing overlapping implementations.
521521
(unstable, marker_trait_attr, "1.30.0", Some(29864)),
522-
/// Allows exhaustive pattern matching on types that contain uninhabited types in cases that are
523-
/// unambiguously sound.
524-
(unstable, min_exhaustive_patterns, "1.77.0", Some(119612)),
525522
/// A minimal, sound subset of specialization intended to be used by the
526523
/// standard library until the soundness issues with specialization
527524
/// are fixed.

Diff for: compiler/rustc_mir_build/src/build/matches/match_pair.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,11 @@ impl<'pat, 'tcx> MatchPairTree<'pat, 'tcx> {
208208
subpairs = cx.field_match_pairs(downcast_place, subpatterns);
209209

210210
let irrefutable = adt_def.variants().iter_enumerated().all(|(i, v)| {
211-
i == variant_index || {
212-
(cx.tcx.features().exhaustive_patterns
213-
|| cx.tcx.features().min_exhaustive_patterns)
214-
&& !v
215-
.inhabited_predicate(cx.tcx, adt_def)
216-
.instantiate(cx.tcx, args)
217-
.apply_ignore_module(cx.tcx, cx.param_env)
218-
}
211+
i == variant_index
212+
|| !v
213+
.inhabited_predicate(cx.tcx, adt_def)
214+
.instantiate(cx.tcx, args)
215+
.apply_ignore_module(cx.tcx, cx.param_env)
219216
}) && (adt_def.did().is_local()
220217
|| !adt_def.is_variant_list_non_exhaustive());
221218
if irrefutable {

Diff for: compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
695695

696696
// Emit an extra note if the first uncovered witness would be uninhabited
697697
// if we disregard visibility.
698-
let witness_1_is_privately_uninhabited = if (self.tcx.features().exhaustive_patterns
699-
|| self.tcx.features().min_exhaustive_patterns)
700-
&& let Some(witness_1) = witnesses.get(0)
698+
let witness_1_is_privately_uninhabited = if let Some(witness_1) = witnesses.get(0)
701699
&& let ty::Adt(adt, args) = witness_1.ty().kind()
702700
&& adt.is_enum()
703701
&& let Constructor::Variant(variant_index) = witness_1.ctor()
@@ -1059,7 +1057,7 @@ fn report_non_exhaustive_match<'p, 'tcx>(
10591057
err.note("`&str` cannot be matched exhaustively, so a wildcard `_` is necessary");
10601058
} else if cx.is_foreign_non_exhaustive_enum(ty) {
10611059
err.note(format!("`{ty}` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustively"));
1062-
} else if cx.is_uninhabited(ty.inner()) && cx.tcx.features().min_exhaustive_patterns {
1060+
} else if cx.is_uninhabited(ty.inner()) {
10631061
// The type is uninhabited yet there is a witness: we must be in the `MaybeInvalid`
10641062
// case.
10651063
err.note(format!("`{ty}` is uninhabited but is not being matched by value, so a wildcard `_` is required"));

Diff for: compiler/rustc_pattern_analysis/src/lib.rs

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

5656
fn is_exhaustive_patterns_feature_on(&self) -> bool;
57-
fn is_min_exhaustive_patterns_feature_on(&self) -> bool;
5857

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

Diff for: compiler/rustc_pattern_analysis/src/rustc.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
237237
let tys = cx.variant_sub_tys(ty, variant).map(|(field, ty)| {
238238
let is_visible =
239239
adt.is_enum() || field.vis.is_accessible_from(cx.module, cx.tcx);
240-
let is_uninhabited = (cx.tcx.features().exhaustive_patterns
241-
|| cx.tcx.features().min_exhaustive_patterns)
242-
&& cx.is_uninhabited(*ty);
240+
let is_uninhabited = cx.is_uninhabited(*ty);
243241
let skip = is_uninhabited && (!is_visible || is_non_exhaustive);
244242
(ty, PrivateUninhabitedField(skip))
245243
});
@@ -925,9 +923,6 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> {
925923
fn is_exhaustive_patterns_feature_on(&self) -> bool {
926924
self.tcx.features().exhaustive_patterns
927925
}
928-
fn is_min_exhaustive_patterns_feature_on(&self) -> bool {
929-
self.tcx.features().min_exhaustive_patterns
930-
}
931926

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

Diff for: 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
//!
@@ -953,13 +951,10 @@ impl<Cx: PatCx> PlaceInfo<Cx> {
953951
self.is_scrutinee && matches!(ctors_for_ty, ConstructorSet::NoConstructors);
954952
// Whether empty patterns are counted as useful or not. We only warn an empty arm unreachable if
955953
// it is guaranteed unreachable by the opsem (i.e. if the place is `known_valid`).
956-
let empty_arms_are_unreachable = self.validity.is_known_valid()
957-
&& (is_toplevel_exception
958-
|| cx.is_exhaustive_patterns_feature_on()
959-
|| cx.is_min_exhaustive_patterns_feature_on());
954+
let empty_arms_are_unreachable = self.validity.is_known_valid();
960955
// Whether empty patterns can be omitted for exhaustiveness. We ignore place validity in the
961956
// toplevel exception and `exhaustive_patterns` cases for backwards compatibility.
962-
let can_omit_empty_arms = empty_arms_are_unreachable
957+
let can_omit_empty_arms = self.validity.is_known_valid()
963958
|| is_toplevel_exception
964959
|| cx.is_exhaustive_patterns_feature_on();
965960

Diff for: compiler/rustc_pattern_analysis/tests/common/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ impl PatCx for Cx {
152152
false
153153
}
154154

155-
fn is_min_exhaustive_patterns_feature_on(&self) -> bool {
156-
true
157-
}
158-
159155
fn ctor_arity(&self, ctor: &Constructor<Self>, ty: &Self::Ty) -> usize {
160156
ty.sub_tys(ctor).len()
161157
}

Diff for: library/alloc/src/collections/vec_deque/into_iter.rs

+2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
121121
{
122122
match self.try_fold(init, |b, item| Ok::<B, !>(f(b, item))) {
123123
Ok(b) => b,
124+
#[cfg(bootstrap)]
124125
Err(e) => match e {},
125126
}
126127
}
@@ -242,6 +243,7 @@ impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> {
242243
{
243244
match self.try_rfold(init, |b, item| Ok::<B, !>(f(b, item))) {
244245
Ok(b) => b,
246+
#[cfg(bootstrap)]
245247
Err(e) => match e {},
246248
}
247249
}

Diff for: tests/ui/pattern/usefulness/empty-types.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ revisions: normal min_exh_pats exhaustive_patterns never_pats
2-
// gate-test-min_exhaustive_patterns
32
//
43
// This tests correct handling of empty types in exhaustiveness checking.
54
//

0 commit comments

Comments
 (0)