Skip to content

Commit 8291d68

Browse files
committed
Auto merge of rust-lang#122792 - Nadrieril:stabilize-min-exh-pats2, r=fee1-dead
Stabilize `min_exhaustive_patterns` ## Stabilisation report I propose we stabilize the [`min_exhaustive_patterns`](rust-lang#119612) language feature. With this feature, patterns of empty types are considered unreachable when matched by-value. This allows: ```rust enum Void {} fn foo() -> Result<u32, Void>; fn main() { let Ok(x) = foo(); // also match foo() { Ok(x) => ..., } } ``` This is a subset of the long-unstable [`exhaustive_patterns`](rust-lang#51085) feature. That feature is blocked because omitting empty patterns is tricky when *not* matched by-value. This PR stabilizes the by-value case, which is not tricky. The not-by-value cases (behind references, pointers, and unions) stay as they are today, e.g. ```rust enum Void {} fn foo() -> Result<u32, &Void>; fn main() { let Ok(x) = foo(); // ERROR: missing `Err(_)` } ``` The consequence on existing code is some extra "unreachable pattern" warnings. This is fully backwards-compatible. ### Comparison with today's rust This proposal only affects match checking of empty types (i.e. types with no valid values). Non-empty types behave the same with or without this feature. Note that everything below is phrased in terms of `match` but applies equallly to `if let` and other pattern-matching expressions. To be precise, a visibly empty type is: - an enum with no variants; - the never type `!`; - a struct with a *visible* field of a visibly empty type (and no #[non_exhaustive] annotation); - a tuple where one of the types is visibly empty; - en enum with all variants visibly empty (and no `#[non_exhaustive]` annotation); - a `[T; N]` with `N != 0` and `T` visibly empty; - all other types are nonempty. (An extra change was proposed below: that we ignore #[non_exhaustive] for structs since adding fields cannot turn an empty struct into a non-empty one) For normal types, exhaustiveness checking requires that we list all variants (or use a wildcard). For empty types it's more subtle: in some cases we require a `_` pattern even though there are no valid values that can match it. This is where the difference lies regarding this feature. #### Today's rust Under today's rust, a `_` is required for all empty types, except specifically: if the matched expression is of type `!` (the never type) or `EmptyEnum` (where `EmptyEnum` is an enum with no variants), then the `_` is not required. ```rust let foo: Result<u32, !> = ...; match foo { Ok(x) => ..., Err(_) => ..., // required } let foo: Result<u32, &!> = ...; match foo { Ok(x) => ..., Err(_) => ..., // required } let foo: &! = ...; match foo { _ => ..., // required } fn blah(foo: (u32, !)) { match foo { _ => ..., // required } } unsafe { let ptr: *const ! = ...; match *ptr {} // allowed let ptr: *const (u32, !) = ...; match *ptr { (x, _) => { ... } // required } let ptr: *const Result<u32, !> = ...; match *ptr { Ok(x) => { ... } Err(_) => { ... } // required } } ``` #### After this PR After this PR, a pattern of an empty type can be omitted if (and only if): - the match scrutinee expression has type `!` or `EmptyEnum` (like before); - *or* the empty type is matched by value (that's the new behavior). In all other cases, a `_` is required to match on an empty type. ```rust let foo: Result<u32, !> = ...; match foo { Ok(x) => ..., // `Err` not required } let foo: Result<u32, &!> = ...; match foo { Ok(x) => ..., Err(_) => ..., // required because `!` is under a dereference } let foo: &! = ...; match foo { _ => ..., // required because `!` is under a dereference } fn blah(foo: (u32, !)) { match foo {} // allowed } unsafe { let ptr: *const ! = ...; match *ptr {} // allowed let ptr: *const (u32, !) = ...; match *ptr { (x, _) => { ... } // required because the matched place is under a (pointer) dereference } let ptr: *const Result<u32, !> = ...; match *ptr { Ok(x) => { ... } Err(_) => { ... } // required because the matched place is under a (pointer) dereference } } ``` ### Documentation The reference does not say anything specific about exhaustiveness checking, hence there is nothing to update there. The nomicon does, I opened rust-lang/nomicon#445 to reflect the changes. ### Tests The relevant tests are in `tests/ui/pattern/usefulness/empty-types.rs`. ### Unresolved Questions None that I know of. try-job: dist-aarch64-apple
2 parents 48090b1 + e77612d commit 8291d68

File tree

100 files changed

+1061
-935
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+1061
-935
lines changed

compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs

+1
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ pub enum E2<X> {
585585
V4,
586586
}
587587

588+
#[allow(unreachable_patterns)]
588589
fn check_niche_behavior() {
589590
if let E1::V2 { .. } = (E1::V1 { f: true }) {
590591
intrinsics::abort();

compiler/rustc_codegen_gcc/example/mini_core_hello_world.rs

+1
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ pub enum E2<X> {
430430
V4,
431431
}
432432

433+
#[allow(unreachable_patterns)]
433434
fn check_niche_behavior () {
434435
if let E1::V2 { .. } = (E1::V1 { f: true }) {
435436
intrinsics::abort();

compiler/rustc_errors/src/diagnostic_impls.rs

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ macro_rules! into_diag_arg_for_number {
6666
impl IntoDiagArg for $ty {
6767
fn into_diag_arg(self) -> DiagArgValue {
6868
// Convert to a string if it won't fit into `Number`.
69+
#[allow(irrefutable_let_patterns)]
6970
if let Ok(n) = TryInto::<i32>::try_into(self) {
7071
DiagArgValue::Number(n)
7172
} else {

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.

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.

compiler/rustc_middle/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#![allow(rustc::diagnostic_outside_of_impl)]
2929
#![allow(rustc::potential_query_instability)]
3030
#![allow(rustc::untranslatable_diagnostic)]
31+
#![cfg_attr(bootstrap, feature(min_exhaustive_patterns))]
3132
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
3233
#![doc(rust_logo)]
3334
#![feature(allocator_api)]
@@ -48,7 +49,6 @@
4849
#![feature(iter_from_coroutine)]
4950
#![feature(let_chains)]
5051
#![feature(macro_metavar_expr)]
51-
#![feature(min_exhaustive_patterns)]
5252
#![feature(min_specialization)]
5353
#![feature(negative_impls)]
5454
#![feature(never_type)]

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 {

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"));

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;

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)

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

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
}

compiler/rustc_target/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
1010
// tidy-alphabetical-start
1111
#![allow(internal_features)]
12+
#![cfg_attr(bootstrap, feature(min_exhaustive_patterns))]
1213
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
1314
#![doc(rust_logo)]
1415
#![feature(assert_matches)]
1516
#![feature(iter_intersperse)]
1617
#![feature(let_chains)]
17-
#![feature(min_exhaustive_patterns)]
1818
#![feature(rustc_attrs)]
1919
#![feature(rustdoc_internals)]
2020
// tidy-alphabetical-end

compiler/rustc_transmute/src/layout/nfa.rs

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ where
8787
pub(crate) fn from_tree(tree: Tree<!, R>) -> Result<Self, Uninhabited> {
8888
Ok(match tree {
8989
Tree::Byte(b) => Self::from_byte(b),
90+
#[cfg(bootstrap)]
9091
Tree::Def(..) => unreachable!(),
9192
Tree::Ref(r) => Self::from_ref(r),
9293
Tree::Alt(alts) => {

compiler/rustc_type_ir/src/fold.rs

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ pub trait TypeFoldable<I: Interner>: TypeVisitable<I> {
9191
fn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self {
9292
match self.try_fold_with(folder) {
9393
Ok(t) => t,
94+
#[cfg(bootstrap)]
9495
Err(e) => match e {},
9596
}
9697
}
@@ -115,6 +116,7 @@ pub trait TypeSuperFoldable<I: Interner>: TypeFoldable<I> {
115116
fn super_fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self {
116117
match self.try_super_fold_with(folder) {
117118
Ok(t) => t,
119+
#[cfg(bootstrap)]
118120
Err(e) => match e {},
119121
}
120122
}

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
}

library/core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192
//
193193
// Language features:
194194
// tidy-alphabetical-start
195+
#![cfg_attr(bootstrap, feature(min_exhaustive_patterns))]
195196
#![feature(abi_unadjusted)]
196197
#![feature(adt_const_params)]
197198
#![feature(allow_internal_unsafe)]
@@ -225,7 +226,6 @@
225226
#![feature(link_llvm_intrinsics)]
226227
#![feature(macro_metavar_expr)]
227228
#![feature(marker_trait_attr)]
228-
#![feature(min_exhaustive_patterns)]
229229
#![feature(min_specialization)]
230230
#![feature(multiple_supertrait_upcastable)]
231231
#![feature(must_not_suspend)]

library/std/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@
272272
//
273273
// Language features:
274274
// tidy-alphabetical-start
275+
#![cfg_attr(bootstrap, feature(min_exhaustive_patterns))]
275276
#![feature(alloc_error_handler)]
276277
#![feature(allocator_internals)]
277278
#![feature(allow_internal_unsafe)]
@@ -299,7 +300,6 @@
299300
#![feature(link_cfg)]
300301
#![feature(linkage)]
301302
#![feature(macro_metavar_expr_concat)]
302-
#![feature(min_exhaustive_patterns)]
303303
#![feature(min_specialization)]
304304
#![feature(must_not_suspend)]
305305
#![feature(needs_panic_runtime)]

src/tools/clippy/clippy_utils/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2931,6 +2931,7 @@ pub fn expr_use_ctxt<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> ExprU
29312931
moved_before_use,
29322932
same_ctxt,
29332933
},
2934+
#[allow(unreachable_patterns)]
29342935
Some(ControlFlow::Break(_)) => unreachable!("type of node is ControlFlow<!>"),
29352936
None => ExprUseCtxt {
29362937
node: Node::Crate(cx.tcx.hir().root_module()),

src/tools/clippy/tests/ui/single_match_else.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn main() {
8989

9090
// lint here
9191
use std::convert::Infallible;
92-
if let Ok(a) = Result::<i32, Infallible>::Ok(1) { println!("${:?}", a) } else {
92+
if let Ok(a) = Result::<i32, &Infallible>::Ok(1) { println!("${:?}", a) } else {
9393
println!("else block");
9494
return;
9595
}

src/tools/clippy/tests/ui/single_match_else.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ fn main() {
9898

9999
// lint here
100100
use std::convert::Infallible;
101-
match Result::<i32, Infallible>::Ok(1) {
101+
match Result::<i32, &Infallible>::Ok(1) {
102102
Ok(a) => println!("${:?}", a),
103103
Err(_) => {
104104
println!("else block");

src/tools/clippy/tests/ui/single_match_else.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ LL + }
6464
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
6565
--> tests/ui/single_match_else.rs:101:5
6666
|
67-
LL | / match Result::<i32, Infallible>::Ok(1) {
67+
LL | / match Result::<i32, &Infallible>::Ok(1) {
6868
LL | | Ok(a) => println!("${:?}", a),
6969
LL | | Err(_) => {
7070
LL | | println!("else block");
@@ -75,7 +75,7 @@ LL | | }
7575
|
7676
help: try
7777
|
78-
LL ~ if let Ok(a) = Result::<i32, Infallible>::Ok(1) { println!("${:?}", a) } else {
78+
LL ~ if let Ok(a) = Result::<i32, &Infallible>::Ok(1) { println!("${:?}", a) } else {
7979
LL + println!("else block");
8080
LL + return;
8181
LL + }

src/tools/miri/src/eval.rs

+1
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ pub fn eval_entry<'tcx>(
463463
let res = match res {
464464
Err(res) => res,
465465
// `Ok` can never happen
466+
#[cfg(bootstrap)]
466467
Ok(never) => match never {},
467468
};
468469

src/tools/miri/tests/pass/async-fn.rs

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ async fn hello_world() {
5959
}
6060

6161
// This example comes from https://github.com/rust-lang/rust/issues/115145
62+
#[allow(unreachable_patterns)]
6263
async fn uninhabited_variant() {
6364
async fn unreachable(_: Never) {}
6465

src/tools/miri/tests/pass/enums.rs

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ fn discriminant_overflow() {
4343
}
4444
}
4545

46+
#[allow(unreachable_patterns)]
4647
fn more_discriminant_overflow() {
4748
pub enum Infallible {}
4849

src/tools/rust-analyzer/crates/hir-ty/src/mir/eval/shim.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ macro_rules! from_bytes {
2727
($ty:tt, $value:expr) => {
2828
($ty::from_le_bytes(match ($value).try_into() {
2929
Ok(it) => it,
30+
#[allow(unreachable_patterns)]
3031
Err(_) => return Err(MirEvalError::InternalError("mismatched size".into())),
3132
}))
3233
};

src/tools/rust-analyzer/crates/hir-ty/src/mir/lower.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
11611161
ProjectionElem::OpaqueCast(it) => {
11621162
ProjectionElem::OpaqueCast(it)
11631163
}
1164+
#[allow(unreachable_patterns)]
11641165
ProjectionElem::Index(it) => match it {},
11651166
})
11661167
.collect(),

tests/mir-opt/building/match/never_patterns.opt1.SimplifyCfg-initial.after.mir

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ fn opt1(_1: &Result<u32, Void>) -> &u32 {
1313

1414
bb0: {
1515
PlaceMention(_1);
16-
_2 = discriminant((*_1));
17-
switchInt(move _2) -> [0: bb2, 1: bb3, otherwise: bb1];
16+
falseEdge -> [real: bb4, imaginary: bb1];
1817
}
1918

2019
bb1: {
21-
FakeRead(ForMatchedPlace(None), _1);
22-
unreachable;
20+
_2 = discriminant((*_1));
21+
switchInt(move _2) -> [1: bb3, otherwise: bb2];
2322
}
2423

2524
bb2: {
26-
falseEdge -> [real: bb4, imaginary: bb3];
25+
FakeRead(ForMatchedPlace(None), _1);
26+
unreachable;
2727
}
2828

2929
bb3: {

tests/mir-opt/building/match/never_patterns.opt2.SimplifyCfg-initial.after.mir

-15
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,10 @@ fn opt2(_1: &Result<u32, Void>) -> &u32 {
1111

1212
bb0: {
1313
PlaceMention(_1);
14-
_2 = discriminant((*_1));
15-
switchInt(move _2) -> [0: bb2, 1: bb3, otherwise: bb1];
16-
}
17-
18-
bb1: {
19-
FakeRead(ForMatchedPlace(None), _1);
20-
unreachable;
21-
}
22-
23-
bb2: {
2414
StorageLive(_3);
2515
_3 = &(((*_1) as Ok).0: u32);
2616
_0 = &(*_3);
2717
StorageDead(_3);
2818
return;
2919
}
30-
31-
bb3: {
32-
FakeRead(ForMatchedPlace(None), (((*_1) as Err).0: Void));
33-
unreachable;
34-
}
3520
}

0 commit comments

Comments
 (0)