Skip to content

Commit 3c17caf

Browse files
committed
Stabilize min_exhaustive_patterns
1 parent a128516 commit 3c17caf

File tree

9 files changed

+18
-34
lines changed

9 files changed

+18
-34
lines changed

compiler/rustc_feature/src/accepted.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ declare_features! (
250250
(accepted, min_const_generics, "1.51.0", Some(74878)),
251251
/// Allows calling `const unsafe fn` inside `unsafe` blocks in `const fn` functions.
252252
(accepted, min_const_unsafe_fn, "1.33.0", Some(55607)),
253+
/// Allows exhaustive pattern matching on uninhabited types when matched by value.
254+
(accepted, min_exhaustive_patterns, "1.77.0", Some(119612)),
253255
/// Allows using `Self` and associated types in struct expressions and patterns.
254256
(accepted, more_struct_aliases, "1.16.0", Some(37544)),
255257
/// Allows using the MOVBE target feature.

compiler/rustc_feature/src/unstable.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,6 @@ declare_features! (
516516
(unstable, macro_metavar_expr, "1.61.0", Some(83527)),
517517
/// Allows `#[marker]` on certain traits allowing overlapping implementations.
518518
(unstable, marker_trait_attr, "1.30.0", Some(29864)),
519-
/// Allows exhaustive pattern matching on types that contain uninhabited types in cases that are
520-
/// unambiguously sound.
521-
(unstable, min_exhaustive_patterns, "1.77.0", Some(119612)),
522519
/// A minimal, sound subset of specialization intended to be used by the
523520
/// standard library until the soundness issues with specialization
524521
/// are fixed.

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

Lines changed: 5 additions & 8 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 6 deletions
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

Lines changed: 7 additions & 12 deletions
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

library/alloc/src/collections/vec_deque/into_iter.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
120120
{
121121
match self.try_fold(init, |b, item| Ok::<B, !>(f(b, item))) {
122122
Ok(b) => b,
123+
#[cfg(bootstrap)]
123124
Err(e) => match e {},
124125
}
125126
}
@@ -241,6 +242,7 @@ impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> {
241242
{
242243
match self.try_rfold(init, |b, item| Ok::<B, !>(f(b, item))) {
243244
Ok(b) => b,
245+
#[cfg(bootstrap)]
244246
Err(e) => match e {},
245247
}
246248
}

tests/ui/pattern/usefulness/empty-types.rs

Lines changed: 0 additions & 1 deletion
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)