From 9717dadaa19235798a2d64b0d6f8f50ede944878 Mon Sep 17 00:00:00 2001 From: Nadrieril <nadrieril+git@gmail.com> Date: Wed, 20 Mar 2024 19:24:42 +0100 Subject: [PATCH 1/5] Stabilize `min_exhaustive_patterns` --- compiler/rustc_feature/src/accepted.rs | 2 ++ compiler/rustc_feature/src/unstable.rs | 3 --- .../src/build/matches/match_pair.rs | 13 +++++-------- .../src/thir/pattern/check_match.rs | 6 ++---- compiler/rustc_pattern_analysis/src/lib.rs | 1 - compiler/rustc_pattern_analysis/src/rustc.rs | 7 +------ .../rustc_pattern_analysis/src/usefulness.rs | 19 +++++++------------ .../tests/common/mod.rs | 4 ---- .../src/collections/vec_deque/into_iter.rs | 2 ++ tests/ui/pattern/usefulness/empty-types.rs | 1 - 10 files changed, 19 insertions(+), 39 deletions(-) diff --git a/compiler/rustc_feature/src/accepted.rs b/compiler/rustc_feature/src/accepted.rs index e42a655531b5d..44286cfeeefaa 100644 --- a/compiler/rustc_feature/src/accepted.rs +++ b/compiler/rustc_feature/src/accepted.rs @@ -267,6 +267,8 @@ declare_features! ( (accepted, min_const_generics, "1.51.0", Some(74878)), /// Allows calling `const unsafe fn` inside `unsafe` blocks in `const fn` functions. (accepted, min_const_unsafe_fn, "1.33.0", Some(55607)), + /// Allows exhaustive pattern matching on uninhabited types when matched by value. + (accepted, min_exhaustive_patterns, "CURRENT_RUSTC_VERSION", Some(119612)), /// Allows using `Self` and associated types in struct expressions and patterns. (accepted, more_struct_aliases, "1.16.0", Some(37544)), /// Allows using the MOVBE target feature. diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 88a4b5a838246..47810bc9165ef 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -519,9 +519,6 @@ declare_features! ( (unstable, macro_metavar_expr_concat, "1.81.0", Some(124225)), /// Allows `#[marker]` on certain traits allowing overlapping implementations. (unstable, marker_trait_attr, "1.30.0", Some(29864)), - /// Allows exhaustive pattern matching on types that contain uninhabited types in cases that are - /// unambiguously sound. - (unstable, min_exhaustive_patterns, "1.77.0", Some(119612)), /// A minimal, sound subset of specialization intended to be used by the /// standard library until the soundness issues with specialization /// are fixed. diff --git a/compiler/rustc_mir_build/src/build/matches/match_pair.rs b/compiler/rustc_mir_build/src/build/matches/match_pair.rs index 95fec154918a5..ab2bfcbca3aa6 100644 --- a/compiler/rustc_mir_build/src/build/matches/match_pair.rs +++ b/compiler/rustc_mir_build/src/build/matches/match_pair.rs @@ -208,14 +208,11 @@ impl<'pat, 'tcx> MatchPairTree<'pat, 'tcx> { subpairs = cx.field_match_pairs(downcast_place, subpatterns); let irrefutable = adt_def.variants().iter_enumerated().all(|(i, v)| { - i == variant_index || { - (cx.tcx.features().exhaustive_patterns - || cx.tcx.features().min_exhaustive_patterns) - && !v - .inhabited_predicate(cx.tcx, adt_def) - .instantiate(cx.tcx, args) - .apply_ignore_module(cx.tcx, cx.param_env) - } + i == variant_index + || !v + .inhabited_predicate(cx.tcx, adt_def) + .instantiate(cx.tcx, args) + .apply_ignore_module(cx.tcx, cx.param_env) }) && (adt_def.did().is_local() || !adt_def.is_variant_list_non_exhaustive()); if irrefutable { diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index 64c6ff952c686..efaa75800fca4 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -695,9 +695,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> { // Emit an extra note if the first uncovered witness would be uninhabited // if we disregard visibility. - let witness_1_is_privately_uninhabited = if (self.tcx.features().exhaustive_patterns - || self.tcx.features().min_exhaustive_patterns) - && let Some(witness_1) = witnesses.get(0) + let witness_1_is_privately_uninhabited = if let Some(witness_1) = witnesses.get(0) && let ty::Adt(adt, args) = witness_1.ty().kind() && adt.is_enum() && let Constructor::Variant(variant_index) = witness_1.ctor() @@ -1059,7 +1057,7 @@ fn report_non_exhaustive_match<'p, 'tcx>( err.note("`&str` cannot be matched exhaustively, so a wildcard `_` is necessary"); } else if cx.is_foreign_non_exhaustive_enum(ty) { err.note(format!("`{ty}` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustively")); - } else if cx.is_uninhabited(ty.inner()) && cx.tcx.features().min_exhaustive_patterns { + } else if cx.is_uninhabited(ty.inner()) { // The type is uninhabited yet there is a witness: we must be in the `MaybeInvalid` // case. err.note(format!("`{ty}` is uninhabited but is not being matched by value, so a wildcard `_` is required")); diff --git a/compiler/rustc_pattern_analysis/src/lib.rs b/compiler/rustc_pattern_analysis/src/lib.rs index a5c0b13c90be1..e37fa072b6d65 100644 --- a/compiler/rustc_pattern_analysis/src/lib.rs +++ b/compiler/rustc_pattern_analysis/src/lib.rs @@ -54,7 +54,6 @@ pub trait PatCx: Sized + fmt::Debug { type PatData: Clone; fn is_exhaustive_patterns_feature_on(&self) -> bool; - fn is_min_exhaustive_patterns_feature_on(&self) -> bool; /// The number of fields for this constructor. fn ctor_arity(&self, ctor: &Constructor<Self>, ty: &Self::Ty) -> usize; diff --git a/compiler/rustc_pattern_analysis/src/rustc.rs b/compiler/rustc_pattern_analysis/src/rustc.rs index 6290aeb252312..25f7cc17c11ff 100644 --- a/compiler/rustc_pattern_analysis/src/rustc.rs +++ b/compiler/rustc_pattern_analysis/src/rustc.rs @@ -237,9 +237,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { let tys = cx.variant_sub_tys(ty, variant).map(|(field, ty)| { let is_visible = adt.is_enum() || field.vis.is_accessible_from(cx.module, cx.tcx); - let is_uninhabited = (cx.tcx.features().exhaustive_patterns - || cx.tcx.features().min_exhaustive_patterns) - && cx.is_uninhabited(*ty); + let is_uninhabited = cx.is_uninhabited(*ty); let skip = is_uninhabited && (!is_visible || is_non_exhaustive); (ty, PrivateUninhabitedField(skip)) }); @@ -925,9 +923,6 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> { fn is_exhaustive_patterns_feature_on(&self) -> bool { self.tcx.features().exhaustive_patterns } - fn is_min_exhaustive_patterns_feature_on(&self) -> bool { - self.tcx.features().min_exhaustive_patterns - } fn ctor_arity(&self, ctor: &crate::constructor::Constructor<Self>, ty: &Self::Ty) -> usize { self.ctor_arity(ctor, *ty) diff --git a/compiler/rustc_pattern_analysis/src/usefulness.rs b/compiler/rustc_pattern_analysis/src/usefulness.rs index 9710c9e1303dd..6535afcc39862 100644 --- a/compiler/rustc_pattern_analysis/src/usefulness.rs +++ b/compiler/rustc_pattern_analysis/src/usefulness.rs @@ -543,13 +543,11 @@ //! recurse into subpatterns. That second part is done through [`PlaceValidity`], most notably //! [`PlaceValidity::specialize`]. //! -//! Having said all that, in practice we don't fully follow what's been presented in this section. -//! Let's call "toplevel exception" the case where the match scrutinee itself has type `!` or -//! `EmptyEnum`. First, on stable rust, we require `_` patterns for empty types in all cases apart -//! from the toplevel exception. The `exhaustive_patterns` and `min_exaustive_patterns` allow -//! omitting patterns in the cases described above. There's a final detail: in the toplevel -//! exception or with the `exhaustive_patterns` feature, we ignore place validity when checking -//! whether a pattern is required for exhaustiveness. I (Nadrieril) hope to deprecate this behavior. +//! Having said all that, we don't fully follow what's been presented in this section. For +//! backwards-compatibility, we ignore place validity when checking whether a pattern is required +//! for exhaustiveness in two cases: when the `exhaustive_patterns` feature gate is on, or when the +//! match scrutinee itself has type `!` or `EmptyEnum`. I (Nadrieril) hope to deprecate this +//! exception. //! //! //! @@ -953,13 +951,10 @@ impl<Cx: PatCx> PlaceInfo<Cx> { self.is_scrutinee && matches!(ctors_for_ty, ConstructorSet::NoConstructors); // Whether empty patterns are counted as useful or not. We only warn an empty arm unreachable if // it is guaranteed unreachable by the opsem (i.e. if the place is `known_valid`). - let empty_arms_are_unreachable = self.validity.is_known_valid() - && (is_toplevel_exception - || cx.is_exhaustive_patterns_feature_on() - || cx.is_min_exhaustive_patterns_feature_on()); + let empty_arms_are_unreachable = self.validity.is_known_valid(); // Whether empty patterns can be omitted for exhaustiveness. We ignore place validity in the // toplevel exception and `exhaustive_patterns` cases for backwards compatibility. - let can_omit_empty_arms = empty_arms_are_unreachable + let can_omit_empty_arms = self.validity.is_known_valid() || is_toplevel_exception || cx.is_exhaustive_patterns_feature_on(); diff --git a/compiler/rustc_pattern_analysis/tests/common/mod.rs b/compiler/rustc_pattern_analysis/tests/common/mod.rs index 01a56eaa78fcc..ec0bcd43ad24d 100644 --- a/compiler/rustc_pattern_analysis/tests/common/mod.rs +++ b/compiler/rustc_pattern_analysis/tests/common/mod.rs @@ -152,10 +152,6 @@ impl PatCx for Cx { false } - fn is_min_exhaustive_patterns_feature_on(&self) -> bool { - true - } - fn ctor_arity(&self, ctor: &Constructor<Self>, ty: &Self::Ty) -> usize { ty.sub_tys(ctor).len() } diff --git a/library/alloc/src/collections/vec_deque/into_iter.rs b/library/alloc/src/collections/vec_deque/into_iter.rs index 2d283dac9a97a..7be3de16b2da7 100644 --- a/library/alloc/src/collections/vec_deque/into_iter.rs +++ b/library/alloc/src/collections/vec_deque/into_iter.rs @@ -121,6 +121,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> { { match self.try_fold(init, |b, item| Ok::<B, !>(f(b, item))) { Ok(b) => b, + #[cfg(bootstrap)] Err(e) => match e {}, } } @@ -242,6 +243,7 @@ impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> { { match self.try_rfold(init, |b, item| Ok::<B, !>(f(b, item))) { Ok(b) => b, + #[cfg(bootstrap)] Err(e) => match e {}, } } diff --git a/tests/ui/pattern/usefulness/empty-types.rs b/tests/ui/pattern/usefulness/empty-types.rs index cc71f67831dd8..46024b1caebc7 100644 --- a/tests/ui/pattern/usefulness/empty-types.rs +++ b/tests/ui/pattern/usefulness/empty-types.rs @@ -1,5 +1,4 @@ //@ revisions: normal min_exh_pats exhaustive_patterns never_pats -// gate-test-min_exhaustive_patterns // // This tests correct handling of empty types in exhaustiveness checking. // From a10b8230ebef45123b4a0e84039d9f4c8f06a22f Mon Sep 17 00:00:00 2001 From: Nadrieril <nadrieril+git@gmail.com> Date: Sat, 27 Jul 2024 11:08:16 +0200 Subject: [PATCH 2/5] Update tests --- ...atterns.opt1.SimplifyCfg-initial.after.mir | 10 +- ...atterns.opt2.SimplifyCfg-initial.after.mir | 15 - ...atterns.opt3.SimplifyCfg-initial.after.mir | 17 +- ...ch.UnreachablePropagation.panic-abort.diff | 16 +- ...h.UnreachablePropagation.panic-unwind.diff | 16 +- tests/mir-opt/unreachable.rs | 10 +- tests/mir-opt/unreachable_enum_branching.rs | 2 +- ....UnreachableEnumBranching.panic-abort.diff | 24 +- ...UnreachableEnumBranching.panic-unwind.diff | 24 +- .../run_pass/multivariant.rs | 3 +- .../huge_multispan_highlight.svg | 2 +- .../write-to-uninhabited-enum-variant.rs | 4 +- tests/ui/enum-discriminant/issue-61696.rs | 1 + tests/ui/enum-discriminant/niche.rs | 1 + .../feature-gate-exhaustive-patterns.rs | 2 +- .../feature-gate-exhaustive-patterns.stderr | 10 +- tests/ui/never_type/never-result.rs | 5 +- ...bited-union-ref.exhaustive_patterns.stderr | 6 +- ... always-inhabited-union-ref.normal.stderr} | 6 +- .../usefulness/always-inhabited-union-ref.rs | 3 +- ...tch-check-notes.exhaustive_patterns.stderr | 6 +- .../empty-match-check-notes.normal.stderr | 7 +- .../usefulness/empty-match-check-notes.rs | 6 +- .../empty-match.exhaustive_patterns.stderr | 1 + .../usefulness/empty-match.normal.stderr | 1 + .../empty-types.exhaustive_patterns.stderr | 100 ++--- .../usefulness/empty-types.never_pats.stderr | 357 ++++++++++-------- .../usefulness/empty-types.normal.stderr | 355 +++++++++-------- tests/ui/pattern/usefulness/empty-types.rs | 91 ++--- .../usefulness/explain-unreachable-pats.rs | 1 - .../explain-unreachable-pats.stderr | 24 +- tests/ui/pattern/usefulness/impl-trait.rs | 1 - tests/ui/pattern/usefulness/impl-trait.stderr | 32 +- ...privately-empty.exhaustive_patterns.stderr | 2 +- .../match-privately-empty.normal.stderr | 21 ++ .../usefulness/match-privately-empty.rs | 3 +- .../slice_of_empty.exhaustive_patterns.stderr | 2 +- .../usefulness/slice_of_empty.normal.stderr | 30 ++ tests/ui/pattern/usefulness/slice_of_empty.rs | 7 +- tests/ui/pattern/usefulness/uninhabited.rs | 1 - .../ui/reachable/unreachable-loop-patterns.rs | 2 - .../unreachable-loop-patterns.stderr | 4 +- .../ui/rfcs/rfc-0000-never_patterns/check.rs | 8 +- .../rfcs/rfc-0000-never_patterns/check.stderr | 22 +- .../typeck.fail.stderr | 16 +- .../ui/rfcs/rfc-0000-never_patterns/typeck.rs | 1 - .../unreachable.exh_pats.stderr | 14 +- .../unreachable.normal.stderr | 44 +++ .../rfc-0000-never_patterns/unreachable.rs | 15 +- .../unreachable.stderr | 55 +++ .../uninhabited/indirect_match_same_crate.rs | 11 +- .../indirect_match_same_crate.stderr | 79 ---- ...indirect_match_with_exhaustive_patterns.rs | 1 - ...rect_match_with_exhaustive_patterns.stderr | 8 +- ...tch_with_exhaustive_patterns_same_crate.rs | 1 - .../uninhabited/match_same_crate.rs | 7 +- .../uninhabited/match_same_crate.stderr | 64 ---- .../match_with_exhaustive_patterns.rs | 1 - .../match_with_exhaustive_patterns.stderr | 8 +- ...tch_with_exhaustive_patterns_same_crate.rs | 1 - .../uninhabited/patterns.rs | 1 - .../uninhabited/patterns_same_crate.rs | 1 - .../uninhabited/patterns_same_crate.stderr | 10 +- tests/ui/try-trait/try-operator-custom.rs | 3 - .../exhaustive-wo-nevertype-issue-51221.rs | 2 - ...ted-irrefutable.exhaustive_patterns.stderr | 4 +- .../uninhabited-irrefutable.normal.stderr | 26 ++ .../ui/uninhabited/uninhabited-irrefutable.rs | 3 +- .../uninhabited-matches-feature-gated.rs | 7 +- .../uninhabited-matches-feature-gated.stderr | 66 +--- tests/ui/uninhabited/uninhabited-patterns.rs | 1 - .../uninhabited/uninhabited-patterns.stderr | 8 +- 72 files changed, 878 insertions(+), 841 deletions(-) rename tests/ui/pattern/usefulness/{always-inhabited-union-ref.min_exhaustive_patterns.stderr => always-inhabited-union-ref.normal.stderr} (87%) create mode 100644 tests/ui/pattern/usefulness/match-privately-empty.normal.stderr create mode 100644 tests/ui/pattern/usefulness/slice_of_empty.normal.stderr create mode 100644 tests/ui/rfcs/rfc-0000-never_patterns/unreachable.normal.stderr create mode 100644 tests/ui/rfcs/rfc-0000-never_patterns/unreachable.stderr delete mode 100644 tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/indirect_match_same_crate.stderr delete mode 100644 tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/match_same_crate.stderr create mode 100644 tests/ui/uninhabited/uninhabited-irrefutable.normal.stderr diff --git a/tests/mir-opt/building/match/never_patterns.opt1.SimplifyCfg-initial.after.mir b/tests/mir-opt/building/match/never_patterns.opt1.SimplifyCfg-initial.after.mir index 78356a90743a6..bba4d9c0149a1 100644 --- a/tests/mir-opt/building/match/never_patterns.opt1.SimplifyCfg-initial.after.mir +++ b/tests/mir-opt/building/match/never_patterns.opt1.SimplifyCfg-initial.after.mir @@ -13,17 +13,17 @@ fn opt1(_1: &Result<u32, Void>) -> &u32 { bb0: { PlaceMention(_1); - _2 = discriminant((*_1)); - switchInt(move _2) -> [0: bb2, 1: bb3, otherwise: bb1]; + falseEdge -> [real: bb4, imaginary: bb1]; } bb1: { - FakeRead(ForMatchedPlace(None), _1); - unreachable; + _2 = discriminant((*_1)); + switchInt(move _2) -> [1: bb3, otherwise: bb2]; } bb2: { - falseEdge -> [real: bb4, imaginary: bb3]; + FakeRead(ForMatchedPlace(None), _1); + unreachable; } bb3: { diff --git a/tests/mir-opt/building/match/never_patterns.opt2.SimplifyCfg-initial.after.mir b/tests/mir-opt/building/match/never_patterns.opt2.SimplifyCfg-initial.after.mir index 979fbb2860dcb..fc0769d6f7dcc 100644 --- a/tests/mir-opt/building/match/never_patterns.opt2.SimplifyCfg-initial.after.mir +++ b/tests/mir-opt/building/match/never_patterns.opt2.SimplifyCfg-initial.after.mir @@ -11,25 +11,10 @@ fn opt2(_1: &Result<u32, Void>) -> &u32 { bb0: { PlaceMention(_1); - _2 = discriminant((*_1)); - switchInt(move _2) -> [0: bb2, 1: bb3, otherwise: bb1]; - } - - bb1: { - FakeRead(ForMatchedPlace(None), _1); - unreachable; - } - - bb2: { StorageLive(_3); _3 = &(((*_1) as Ok).0: u32); _0 = &(*_3); StorageDead(_3); return; } - - bb3: { - FakeRead(ForMatchedPlace(None), (((*_1) as Err).0: Void)); - unreachable; - } } diff --git a/tests/mir-opt/building/match/never_patterns.opt3.SimplifyCfg-initial.after.mir b/tests/mir-opt/building/match/never_patterns.opt3.SimplifyCfg-initial.after.mir index 93ebe600b3ff7..86347db4d92eb 100644 --- a/tests/mir-opt/building/match/never_patterns.opt3.SimplifyCfg-initial.after.mir +++ b/tests/mir-opt/building/match/never_patterns.opt3.SimplifyCfg-initial.after.mir @@ -12,24 +12,19 @@ fn opt3(_1: &Result<u32, Void>) -> &u32 { bb0: { PlaceMention(_1); _2 = discriminant((*_1)); - switchInt(move _2) -> [0: bb3, 1: bb2, otherwise: bb1]; + switchInt(move _2) -> [1: bb2, otherwise: bb1]; } bb1: { - FakeRead(ForMatchedPlace(None), _1); - unreachable; - } - - bb2: { - FakeRead(ForMatchedPlace(None), (((*_1) as Err).0: Void)); - unreachable; - } - - bb3: { StorageLive(_3); _3 = &(((*_1) as Ok).0: u32); _0 = &(*_3); StorageDead(_3); return; } + + bb2: { + FakeRead(ForMatchedPlace(None), (((*_1) as Err).0: Void)); + unreachable; + } } diff --git a/tests/mir-opt/unreachable.as_match.UnreachablePropagation.panic-abort.diff b/tests/mir-opt/unreachable.as_match.UnreachablePropagation.panic-abort.diff index da7a2bd10e01a..1e1ddfae0eb9e 100644 --- a/tests/mir-opt/unreachable.as_match.UnreachablePropagation.panic-abort.diff +++ b/tests/mir-opt/unreachable.as_match.UnreachablePropagation.panic-abort.diff @@ -19,14 +19,16 @@ bb1: { _2 = discriminant(_1); -- switchInt(move _2) -> [0: bb4, 1: bb3, otherwise: bb2]; -+ _5 = Eq(_2, const 0_isize); +- switchInt(move _2) -> [1: bb3, otherwise: bb2]; ++ _5 = Ne(_2, const 1_isize); + assume(move _5); -+ goto -> bb4; ++ goto -> bb2; } bb2: { - unreachable; + _0 = const (); + StorageDead(_1); + return; } bb3: { @@ -35,11 +37,5 @@ - StorageLive(_4); unreachable; } - - bb4: { - _0 = const (); - StorageDead(_1); - return; - } } diff --git a/tests/mir-opt/unreachable.as_match.UnreachablePropagation.panic-unwind.diff b/tests/mir-opt/unreachable.as_match.UnreachablePropagation.panic-unwind.diff index a2121fc684f5b..809d24aa15a13 100644 --- a/tests/mir-opt/unreachable.as_match.UnreachablePropagation.panic-unwind.diff +++ b/tests/mir-opt/unreachable.as_match.UnreachablePropagation.panic-unwind.diff @@ -19,14 +19,16 @@ bb1: { _2 = discriminant(_1); -- switchInt(move _2) -> [0: bb4, 1: bb3, otherwise: bb2]; -+ _5 = Eq(_2, const 0_isize); +- switchInt(move _2) -> [1: bb3, otherwise: bb2]; ++ _5 = Ne(_2, const 1_isize); + assume(move _5); -+ goto -> bb4; ++ goto -> bb2; } bb2: { - unreachable; + _0 = const (); + StorageDead(_1); + return; } bb3: { @@ -35,11 +37,5 @@ - StorageLive(_4); unreachable; } - - bb4: { - _0 = const (); - StorageDead(_1); - return; - } } diff --git a/tests/mir-opt/unreachable.rs b/tests/mir-opt/unreachable.rs index 881e3542f0ac9..f7f4815ae7ce1 100644 --- a/tests/mir-opt/unreachable.rs +++ b/tests/mir-opt/unreachable.rs @@ -45,18 +45,16 @@ fn as_match() { // CHECK: bb0: { // CHECK: {{_.*}} = empty() // CHECK: bb1: { - // CHECK: [[eq:_.*]] = Eq({{.*}}, const 0_isize); + // CHECK: [[eq:_.*]] = Ne({{.*}}, const 1_isize); // CHECK-NEXT: assume(move [[eq]]); - // CHECK-NEXT: goto -> bb4; + // CHECK-NEXT: goto -> bb2; // CHECK: bb2: { - // CHECK-NEXT: unreachable; + // CHECK: return; // CHECK: bb3: { // CHECK-NEXT: unreachable; - // CHECK: bb4: { - // CHECK: return; match empty() { - None => {} Some(_x) => match _x {}, + None => {} } } diff --git a/tests/mir-opt/unreachable_enum_branching.rs b/tests/mir-opt/unreachable_enum_branching.rs index fac14042b1075..7647f9bf0779a 100644 --- a/tests/mir-opt/unreachable_enum_branching.rs +++ b/tests/mir-opt/unreachable_enum_branching.rs @@ -49,7 +49,7 @@ struct Plop { fn simple() { // CHECK-LABEL: fn simple( // CHECK: [[discr:_.*]] = discriminant( - // CHECK: switchInt(move [[discr]]) -> [0: [[unreachable:bb.*]], 1: [[unreachable]], 2: bb2, otherwise: [[unreachable]]]; + // CHECK: switchInt(move [[discr]]) -> [0: [[unreachable:bb.*]], 1: [[unreachable]], 2: bb1, otherwise: [[unreachable]]]; // CHECK: [[unreachable]]: { // CHECK-NEXT: unreachable; match Test1::C { diff --git a/tests/mir-opt/unreachable_enum_branching.simple.UnreachableEnumBranching.panic-abort.diff b/tests/mir-opt/unreachable_enum_branching.simple.UnreachableEnumBranching.panic-abort.diff index 8aef991493672..5c08648fac3bb 100644 --- a/tests/mir-opt/unreachable_enum_branching.simple.UnreachableEnumBranching.panic-abort.diff +++ b/tests/mir-opt/unreachable_enum_branching.simple.UnreachableEnumBranching.panic-abort.diff @@ -14,40 +14,40 @@ StorageLive(_2); _2 = Test1::C; _3 = discriminant(_2); -- switchInt(move _3) -> [0: bb4, 1: bb3, 2: bb2, otherwise: bb1]; -+ switchInt(move _3) -> [0: bb1, 1: bb1, 2: bb2, otherwise: bb1]; +- switchInt(move _3) -> [0: bb3, 1: bb2, otherwise: bb1]; ++ switchInt(move _3) -> [0: bb5, 1: bb5, 2: bb1, otherwise: bb5]; } bb1: { - unreachable; - } - - bb2: { StorageLive(_5); _5 = const "C"; _1 = &(*_5); StorageDead(_5); - goto -> bb5; + goto -> bb4; } - bb3: { + bb2: { StorageLive(_4); _4 = const "B(Empty)"; _1 = &(*_4); StorageDead(_4); - goto -> bb5; + goto -> bb4; } - bb4: { + bb3: { _1 = const "A(Empty)"; - goto -> bb5; + goto -> bb4; } - bb5: { + bb4: { StorageDead(_2); StorageDead(_1); _0 = const (); return; ++ } ++ ++ bb5: { ++ unreachable; } } diff --git a/tests/mir-opt/unreachable_enum_branching.simple.UnreachableEnumBranching.panic-unwind.diff b/tests/mir-opt/unreachable_enum_branching.simple.UnreachableEnumBranching.panic-unwind.diff index 8aef991493672..5c08648fac3bb 100644 --- a/tests/mir-opt/unreachable_enum_branching.simple.UnreachableEnumBranching.panic-unwind.diff +++ b/tests/mir-opt/unreachable_enum_branching.simple.UnreachableEnumBranching.panic-unwind.diff @@ -14,40 +14,40 @@ StorageLive(_2); _2 = Test1::C; _3 = discriminant(_2); -- switchInt(move _3) -> [0: bb4, 1: bb3, 2: bb2, otherwise: bb1]; -+ switchInt(move _3) -> [0: bb1, 1: bb1, 2: bb2, otherwise: bb1]; +- switchInt(move _3) -> [0: bb3, 1: bb2, otherwise: bb1]; ++ switchInt(move _3) -> [0: bb5, 1: bb5, 2: bb1, otherwise: bb5]; } bb1: { - unreachable; - } - - bb2: { StorageLive(_5); _5 = const "C"; _1 = &(*_5); StorageDead(_5); - goto -> bb5; + goto -> bb4; } - bb3: { + bb2: { StorageLive(_4); _4 = const "B(Empty)"; _1 = &(*_4); StorageDead(_4); - goto -> bb5; + goto -> bb4; } - bb4: { + bb3: { _1 = const "A(Empty)"; - goto -> bb5; + goto -> bb4; } - bb5: { + bb4: { StorageDead(_2); StorageDead(_1); _0 = const (); return; ++ } ++ ++ bb5: { ++ unreachable; } } diff --git a/tests/ui/closures/2229_closure_analysis/run_pass/multivariant.rs b/tests/ui/closures/2229_closure_analysis/run_pass/multivariant.rs index 52ed008137fce..74f37b514e4a4 100644 --- a/tests/ui/closures/2229_closure_analysis/run_pass/multivariant.rs +++ b/tests/ui/closures/2229_closure_analysis/run_pass/multivariant.rs @@ -1,10 +1,9 @@ // Test precise capture of a multi-variant enum (when remaining variants are // visibly uninhabited). -//@ revisions: min_exhaustive_patterns exhaustive_patterns +//@ revisions: normal exhaustive_patterns //@ edition:2021 //@ run-pass #![cfg_attr(exhaustive_patterns, feature(exhaustive_patterns))] -#![cfg_attr(min_exhaustive_patterns, feature(min_exhaustive_patterns))] #![feature(never_type)] pub fn main() { diff --git a/tests/ui/codemap_tests/huge_multispan_highlight.svg b/tests/ui/codemap_tests/huge_multispan_highlight.svg index 7b6dbb17c6f95..12058176dc0f1 100644 --- a/tests/ui/codemap_tests/huge_multispan_highlight.svg +++ b/tests/ui/codemap_tests/huge_multispan_highlight.svg @@ -1,4 +1,4 @@ -<svg width="740px" height="848px" xmlns="http://www.w3.org/2000/svg"> +<svg width="818px" height="848px" xmlns="http://www.w3.org/2000/svg"> <style> .fg { fill: #AAAAAA } .bg { background: #000000 } diff --git a/tests/ui/consts/const-eval/write-to-uninhabited-enum-variant.rs b/tests/ui/consts/const-eval/write-to-uninhabited-enum-variant.rs index 5628ae1be36a9..f4130319eea5d 100644 --- a/tests/ui/consts/const-eval/write-to-uninhabited-enum-variant.rs +++ b/tests/ui/consts/const-eval/write-to-uninhabited-enum-variant.rs @@ -1,8 +1,8 @@ //@ run-pass - +#![allow(unreachable_patterns)] #![allow(dead_code)] -enum Empty { } +enum Empty {} enum Test1 { A(u8), B(Empty), diff --git a/tests/ui/enum-discriminant/issue-61696.rs b/tests/ui/enum-discriminant/issue-61696.rs index d200b4410ff9d..e93fd0e07f61b 100644 --- a/tests/ui/enum-discriminant/issue-61696.rs +++ b/tests/ui/enum-discriminant/issue-61696.rs @@ -1,4 +1,5 @@ //@ run-pass +#![allow(unreachable_patterns)] pub enum Infallible {} diff --git a/tests/ui/enum-discriminant/niche.rs b/tests/ui/enum-discriminant/niche.rs index 15d227fd826ee..f9c4a135a6f15 100644 --- a/tests/ui/enum-discriminant/niche.rs +++ b/tests/ui/enum-discriminant/niche.rs @@ -1,4 +1,5 @@ //@ run-pass +#![allow(unreachable_patterns)] //! Make sure that we read and write enum discriminants correctly for corner cases caused //! by layout optimizations. diff --git a/tests/ui/feature-gates/feature-gate-exhaustive-patterns.rs b/tests/ui/feature-gates/feature-gate-exhaustive-patterns.rs index f0cc9ea70550e..7989159369275 100644 --- a/tests/ui/feature-gates/feature-gate-exhaustive-patterns.rs +++ b/tests/ui/feature-gates/feature-gate-exhaustive-patterns.rs @@ -5,5 +5,5 @@ fn foo() -> Result<u32, !> { } fn main() { - let Ok(_x) = foo(); //~ ERROR refutable pattern in local binding + let Ok(_x) = &foo(); //~ ERROR refutable pattern in local binding } diff --git a/tests/ui/feature-gates/feature-gate-exhaustive-patterns.stderr b/tests/ui/feature-gates/feature-gate-exhaustive-patterns.stderr index d34f257c8d910..4836ffe172318 100644 --- a/tests/ui/feature-gates/feature-gate-exhaustive-patterns.stderr +++ b/tests/ui/feature-gates/feature-gate-exhaustive-patterns.stderr @@ -1,16 +1,16 @@ error[E0005]: refutable pattern in local binding --> $DIR/feature-gate-exhaustive-patterns.rs:8:9 | -LL | let Ok(_x) = foo(); - | ^^^^^^ pattern `Err(_)` not covered +LL | let Ok(_x) = &foo(); + | ^^^^^^ pattern `&Err(_)` not covered | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html - = note: the matched value is of type `Result<u32, !>` + = note: the matched value is of type `&Result<u32, !>` help: you might want to use `let else` to handle the variant that isn't matched | -LL | let Ok(_x) = foo() else { todo!() }; - | ++++++++++++++++ +LL | let Ok(_x) = &foo() else { todo!() }; + | ++++++++++++++++ error: aborting due to 1 previous error diff --git a/tests/ui/never_type/never-result.rs b/tests/ui/never_type/never-result.rs index bdd06ec5bd13f..98ad140466621 100644 --- a/tests/ui/never_type/never-result.rs +++ b/tests/ui/never_type/never-result.rs @@ -2,9 +2,8 @@ #![allow(unused_variables)] #![allow(unreachable_code)] - +#![allow(unreachable_patterns)] // Test that we can extract a ! through pattern matching then use it as several different types. - #![feature(never_type)] fn main() { @@ -16,6 +15,6 @@ fn main() { let w: i32 = y; let e: String = y; y - }, + } } } diff --git a/tests/ui/pattern/usefulness/always-inhabited-union-ref.exhaustive_patterns.stderr b/tests/ui/pattern/usefulness/always-inhabited-union-ref.exhaustive_patterns.stderr index d6304a0b997d3..bc74069b3e774 100644 --- a/tests/ui/pattern/usefulness/always-inhabited-union-ref.exhaustive_patterns.stderr +++ b/tests/ui/pattern/usefulness/always-inhabited-union-ref.exhaustive_patterns.stderr @@ -1,5 +1,5 @@ error[E0004]: non-exhaustive patterns: type `&!` is non-empty - --> $DIR/always-inhabited-union-ref.rs:25:11 + --> $DIR/always-inhabited-union-ref.rs:24:11 | LL | match uninhab_ref() { | ^^^^^^^^^^^^^ @@ -14,13 +14,13 @@ LL + } | error[E0004]: non-exhaustive patterns: type `Foo` is non-empty - --> $DIR/always-inhabited-union-ref.rs:29:11 + --> $DIR/always-inhabited-union-ref.rs:28:11 | LL | match uninhab_union() { | ^^^^^^^^^^^^^^^ | note: `Foo` defined here - --> $DIR/always-inhabited-union-ref.rs:12:11 + --> $DIR/always-inhabited-union-ref.rs:11:11 | LL | pub union Foo { | ^^^ diff --git a/tests/ui/pattern/usefulness/always-inhabited-union-ref.min_exhaustive_patterns.stderr b/tests/ui/pattern/usefulness/always-inhabited-union-ref.normal.stderr similarity index 87% rename from tests/ui/pattern/usefulness/always-inhabited-union-ref.min_exhaustive_patterns.stderr rename to tests/ui/pattern/usefulness/always-inhabited-union-ref.normal.stderr index d6304a0b997d3..bc74069b3e774 100644 --- a/tests/ui/pattern/usefulness/always-inhabited-union-ref.min_exhaustive_patterns.stderr +++ b/tests/ui/pattern/usefulness/always-inhabited-union-ref.normal.stderr @@ -1,5 +1,5 @@ error[E0004]: non-exhaustive patterns: type `&!` is non-empty - --> $DIR/always-inhabited-union-ref.rs:25:11 + --> $DIR/always-inhabited-union-ref.rs:24:11 | LL | match uninhab_ref() { | ^^^^^^^^^^^^^ @@ -14,13 +14,13 @@ LL + } | error[E0004]: non-exhaustive patterns: type `Foo` is non-empty - --> $DIR/always-inhabited-union-ref.rs:29:11 + --> $DIR/always-inhabited-union-ref.rs:28:11 | LL | match uninhab_union() { | ^^^^^^^^^^^^^^^ | note: `Foo` defined here - --> $DIR/always-inhabited-union-ref.rs:12:11 + --> $DIR/always-inhabited-union-ref.rs:11:11 | LL | pub union Foo { | ^^^ diff --git a/tests/ui/pattern/usefulness/always-inhabited-union-ref.rs b/tests/ui/pattern/usefulness/always-inhabited-union-ref.rs index 5088098d0ae3a..335eff425abef 100644 --- a/tests/ui/pattern/usefulness/always-inhabited-union-ref.rs +++ b/tests/ui/pattern/usefulness/always-inhabited-union-ref.rs @@ -1,10 +1,9 @@ -//@ revisions: min_exhaustive_patterns exhaustive_patterns +//@ revisions: normal exhaustive_patterns // The precise semantics of inhabitedness with respect to unions and references is currently // undecided. This test file currently checks a conservative choice. #![cfg_attr(exhaustive_patterns, feature(exhaustive_patterns))] -#![cfg_attr(min_exhaustive_patterns, feature(min_exhaustive_patterns))] #![feature(never_type)] #![allow(dead_code)] #![allow(unreachable_code)] diff --git a/tests/ui/pattern/usefulness/empty-match-check-notes.exhaustive_patterns.stderr b/tests/ui/pattern/usefulness/empty-match-check-notes.exhaustive_patterns.stderr index 9e700ee55ef52..1b65ff7aa5751 100644 --- a/tests/ui/pattern/usefulness/empty-match-check-notes.exhaustive_patterns.stderr +++ b/tests/ui/pattern/usefulness/empty-match-check-notes.exhaustive_patterns.stderr @@ -38,7 +38,7 @@ LL | _ if false => {} error[E0005]: refutable pattern in local binding --> $DIR/empty-match-check-notes.rs:39:9 | -LL | let None = x; +LL | let None = *x; | ^^^^ pattern `Some(_)` not covered | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant @@ -47,8 +47,8 @@ LL | let None = x; = note: the matched value is of type `Option<SecretlyUninhabitedForeignStruct>` help: you might want to use `if let` to ignore the variant that isn't matched | -LL | if let None = x { todo!() }; - | ++ +++++++++++ +LL | if let None = *x { todo!() }; + | ++ +++++++++++ error[E0004]: non-exhaustive patterns: `0_u8..=u8::MAX` not covered --> $DIR/empty-match-check-notes.rs:49:11 diff --git a/tests/ui/pattern/usefulness/empty-match-check-notes.normal.stderr b/tests/ui/pattern/usefulness/empty-match-check-notes.normal.stderr index 480ae7095a6c2..1b65ff7aa5751 100644 --- a/tests/ui/pattern/usefulness/empty-match-check-notes.normal.stderr +++ b/tests/ui/pattern/usefulness/empty-match-check-notes.normal.stderr @@ -38,16 +38,17 @@ LL | _ if false => {} error[E0005]: refutable pattern in local binding --> $DIR/empty-match-check-notes.rs:39:9 | -LL | let None = x; +LL | let None = *x; | ^^^^ pattern `Some(_)` not covered | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html + = note: pattern `Some(_)` is currently uninhabited, but this variant contains private fields which may become inhabited in the future = note: the matched value is of type `Option<SecretlyUninhabitedForeignStruct>` help: you might want to use `if let` to ignore the variant that isn't matched | -LL | if let None = x { todo!() }; - | ++ +++++++++++ +LL | if let None = *x { todo!() }; + | ++ +++++++++++ error[E0004]: non-exhaustive patterns: `0_u8..=u8::MAX` not covered --> $DIR/empty-match-check-notes.rs:49:11 diff --git a/tests/ui/pattern/usefulness/empty-match-check-notes.rs b/tests/ui/pattern/usefulness/empty-match-check-notes.rs index 2eef283a21e45..61a75e6c801f9 100644 --- a/tests/ui/pattern/usefulness/empty-match-check-notes.rs +++ b/tests/ui/pattern/usefulness/empty-match-check-notes.rs @@ -35,14 +35,14 @@ fn empty_foreign_enum(x: empty::EmptyForeignEnum) { } } -fn empty_foreign_enum_private(x: Option<empty::SecretlyUninhabitedForeignStruct>) { - let None = x; +fn empty_foreign_enum_private(x: &Option<empty::SecretlyUninhabitedForeignStruct>) { + let None = *x; //~^ ERROR refutable pattern in local binding //~| NOTE `let` bindings require an "irrefutable pattern" //~| NOTE for more information, visit //~| NOTE the matched value is of type //~| NOTE pattern `Some(_)` not covered - //[exhaustive_patterns]~| NOTE currently uninhabited, but this variant contains private fields + //~| NOTE currently uninhabited, but this variant contains private fields } fn main() { diff --git a/tests/ui/pattern/usefulness/empty-match.exhaustive_patterns.stderr b/tests/ui/pattern/usefulness/empty-match.exhaustive_patterns.stderr index 5f895fab0fba4..bc12327a1b2a3 100644 --- a/tests/ui/pattern/usefulness/empty-match.exhaustive_patterns.stderr +++ b/tests/ui/pattern/usefulness/empty-match.exhaustive_patterns.stderr @@ -273,6 +273,7 @@ note: `NonEmptyUnion2` defined here LL | union NonEmptyUnion2 { | ^^^^^^^^^^^^^^ = note: the matched value is of type `NonEmptyUnion2` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required = note: match arms with guards don't count towards exhaustivity help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | diff --git a/tests/ui/pattern/usefulness/empty-match.normal.stderr b/tests/ui/pattern/usefulness/empty-match.normal.stderr index 5f895fab0fba4..bc12327a1b2a3 100644 --- a/tests/ui/pattern/usefulness/empty-match.normal.stderr +++ b/tests/ui/pattern/usefulness/empty-match.normal.stderr @@ -273,6 +273,7 @@ note: `NonEmptyUnion2` defined here LL | union NonEmptyUnion2 { | ^^^^^^^^^^^^^^ = note: the matched value is of type `NonEmptyUnion2` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required = note: match arms with guards don't count towards exhaustivity help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | diff --git a/tests/ui/pattern/usefulness/empty-types.exhaustive_patterns.stderr b/tests/ui/pattern/usefulness/empty-types.exhaustive_patterns.stderr index 416a50b87b594..17cb6fbd94b88 100644 --- a/tests/ui/pattern/usefulness/empty-types.exhaustive_patterns.stderr +++ b/tests/ui/pattern/usefulness/empty-types.exhaustive_patterns.stderr @@ -1,18 +1,18 @@ error: unreachable pattern - --> $DIR/empty-types.rs:51:9 + --> $DIR/empty-types.rs:49:9 | LL | _ => {} | ^ | = note: this pattern matches no values because `!` is uninhabited note: the lint level is defined here - --> $DIR/empty-types.rs:17:9 + --> $DIR/empty-types.rs:15:9 | LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:54:9 + --> $DIR/empty-types.rs:52:9 | LL | _x => {} | ^^ @@ -20,7 +20,7 @@ LL | _x => {} = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: type `&!` is non-empty - --> $DIR/empty-types.rs:58:11 + --> $DIR/empty-types.rs:56:11 | LL | match ref_never {} | ^^^^^^^^^ @@ -35,7 +35,7 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:73:9 + --> $DIR/empty-types.rs:70:9 | LL | (_, _) => {} | ^^^^^^ @@ -43,7 +43,7 @@ LL | (_, _) => {} = note: this pattern matches no values because `(u32, !)` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:80:9 + --> $DIR/empty-types.rs:76:9 | LL | _ => {} | ^ @@ -51,7 +51,7 @@ LL | _ => {} = note: this pattern matches no values because `(!, !)` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:83:9 + --> $DIR/empty-types.rs:79:9 | LL | (_, _) => {} | ^^^^^^ @@ -59,7 +59,7 @@ LL | (_, _) => {} = note: this pattern matches no values because `(!, !)` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:87:9 + --> $DIR/empty-types.rs:83:9 | LL | _ => {} | ^ @@ -67,7 +67,7 @@ LL | _ => {} = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: `Ok(_)` not covered - --> $DIR/empty-types.rs:91:11 + --> $DIR/empty-types.rs:87:11 | LL | match res_u32_never {} | ^^^^^^^^^^^^^ pattern `Ok(_)` not covered @@ -86,7 +86,7 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:99:9 + --> $DIR/empty-types.rs:94:9 | LL | Err(_) => {} | ^^^^^^ @@ -94,7 +94,7 @@ LL | Err(_) => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:104:9 + --> $DIR/empty-types.rs:99:9 | LL | Err(_) => {} | ^^^^^^ @@ -102,7 +102,7 @@ LL | Err(_) => {} = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: `Ok(1_u32..=u32::MAX)` not covered - --> $DIR/empty-types.rs:101:11 + --> $DIR/empty-types.rs:96:11 | LL | match res_u32_never { | ^^^^^^^^^^^^^ pattern `Ok(1_u32..=u32::MAX)` not covered @@ -120,7 +120,7 @@ LL ~ Ok(1_u32..=u32::MAX) => todo!() | error[E0005]: refutable pattern in local binding - --> $DIR/empty-types.rs:108:9 + --> $DIR/empty-types.rs:102:9 | LL | let Ok(_x) = res_u32_never.as_ref(); | ^^^^^^ pattern `Err(_)` not covered @@ -134,7 +134,7 @@ LL | let Ok(_x) = res_u32_never.as_ref() else { todo!() }; | ++++++++++++++++ error: unreachable pattern - --> $DIR/empty-types.rs:119:9 + --> $DIR/empty-types.rs:112:9 | LL | _ => {} | ^ @@ -142,7 +142,7 @@ LL | _ => {} = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:123:9 + --> $DIR/empty-types.rs:115:9 | LL | Ok(_) => {} | ^^^^^ @@ -150,7 +150,7 @@ LL | Ok(_) => {} = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:126:9 + --> $DIR/empty-types.rs:118:9 | LL | Ok(_) => {} | ^^^^^ @@ -158,7 +158,7 @@ LL | Ok(_) => {} = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:127:9 + --> $DIR/empty-types.rs:119:9 | LL | _ => {} | ^ @@ -166,7 +166,7 @@ LL | _ => {} = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:130:9 + --> $DIR/empty-types.rs:122:9 | LL | Ok(_) => {} | ^^^^^ @@ -174,7 +174,7 @@ LL | Ok(_) => {} = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:131:9 + --> $DIR/empty-types.rs:123:9 | LL | Err(_) => {} | ^^^^^^ @@ -182,7 +182,7 @@ LL | Err(_) => {} = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:140:13 + --> $DIR/empty-types.rs:132:13 | LL | _ => {} | ^ @@ -190,7 +190,7 @@ LL | _ => {} = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:143:13 + --> $DIR/empty-types.rs:135:13 | LL | _ if false => {} | ^ @@ -198,7 +198,7 @@ LL | _ if false => {} = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:152:13 + --> $DIR/empty-types.rs:143:13 | LL | Some(_) => {} | ^^^^^^^ @@ -206,7 +206,7 @@ LL | Some(_) => {} = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:156:13 + --> $DIR/empty-types.rs:147:13 | LL | None => {} | ---- matches all the values already @@ -214,7 +214,7 @@ LL | _ => {} | ^ unreachable pattern error: unreachable pattern - --> $DIR/empty-types.rs:208:13 + --> $DIR/empty-types.rs:199:13 | LL | _ => {} | ^ @@ -222,7 +222,7 @@ LL | _ => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:213:13 + --> $DIR/empty-types.rs:204:13 | LL | _ => {} | ^ @@ -230,7 +230,7 @@ LL | _ => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:218:13 + --> $DIR/empty-types.rs:209:13 | LL | _ => {} | ^ @@ -238,7 +238,7 @@ LL | _ => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:223:13 + --> $DIR/empty-types.rs:214:13 | LL | _ => {} | ^ @@ -246,7 +246,7 @@ LL | _ => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:229:13 + --> $DIR/empty-types.rs:220:13 | LL | _ => {} | ^ @@ -254,7 +254,7 @@ LL | _ => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:288:9 + --> $DIR/empty-types.rs:279:9 | LL | _ => {} | ^ @@ -262,7 +262,7 @@ LL | _ => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:291:9 + --> $DIR/empty-types.rs:282:9 | LL | (_, _) => {} | ^^^^^^ @@ -270,7 +270,7 @@ LL | (_, _) => {} = note: this pattern matches no values because `(!, !)` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:294:9 + --> $DIR/empty-types.rs:285:9 | LL | Ok(_) => {} | ^^^^^ @@ -278,7 +278,7 @@ LL | Ok(_) => {} = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:295:9 + --> $DIR/empty-types.rs:286:9 | LL | Err(_) => {} | ^^^^^^ @@ -286,7 +286,7 @@ LL | Err(_) => {} = note: this pattern matches no values because `Result<!, !>` is uninhabited error[E0004]: non-exhaustive patterns: type `&[!]` is non-empty - --> $DIR/empty-types.rs:327:11 + --> $DIR/empty-types.rs:318:11 | LL | match slice_never {} | ^^^^^^^^^^^ @@ -300,7 +300,7 @@ LL + } | error[E0004]: non-exhaustive patterns: `&[]` not covered - --> $DIR/empty-types.rs:338:11 + --> $DIR/empty-types.rs:329:11 | LL | match slice_never { | ^^^^^^^^^^^ pattern `&[]` not covered @@ -313,7 +313,7 @@ LL + &[] => todo!() | error[E0004]: non-exhaustive patterns: `&[]` not covered - --> $DIR/empty-types.rs:352:11 + --> $DIR/empty-types.rs:343:11 | LL | match slice_never { | ^^^^^^^^^^^ pattern `&[]` not covered @@ -327,7 +327,7 @@ LL + &[] => todo!() | error[E0004]: non-exhaustive patterns: type `[!]` is non-empty - --> $DIR/empty-types.rs:359:11 + --> $DIR/empty-types.rs:350:11 | LL | match *slice_never {} | ^^^^^^^^^^^^ @@ -341,7 +341,7 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:369:9 + --> $DIR/empty-types.rs:359:9 | LL | _ => {} | ^ @@ -349,7 +349,7 @@ LL | _ => {} = note: this pattern matches no values because `[!; 3]` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:372:9 + --> $DIR/empty-types.rs:362:9 | LL | [_, _, _] => {} | ^^^^^^^^^ @@ -357,7 +357,7 @@ LL | [_, _, _] => {} = note: this pattern matches no values because `[!; 3]` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:375:9 + --> $DIR/empty-types.rs:365:9 | LL | [_, ..] => {} | ^^^^^^^ @@ -365,7 +365,7 @@ LL | [_, ..] => {} = note: this pattern matches no values because `[!; 3]` is uninhabited error[E0004]: non-exhaustive patterns: type `[!; 0]` is non-empty - --> $DIR/empty-types.rs:389:11 + --> $DIR/empty-types.rs:379:11 | LL | match array_0_never {} | ^^^^^^^^^^^^^ @@ -379,7 +379,7 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:396:9 + --> $DIR/empty-types.rs:386:9 | LL | [] => {} | -- matches all the values already @@ -387,7 +387,7 @@ LL | _ => {} | ^ unreachable pattern error[E0004]: non-exhaustive patterns: `[]` not covered - --> $DIR/empty-types.rs:398:11 + --> $DIR/empty-types.rs:388:11 | LL | match array_0_never { | ^^^^^^^^^^^^^ pattern `[]` not covered @@ -401,7 +401,7 @@ LL + [] => todo!() | error: unreachable pattern - --> $DIR/empty-types.rs:417:9 + --> $DIR/empty-types.rs:407:9 | LL | Some(_) => {} | ^^^^^^^ @@ -409,7 +409,7 @@ LL | Some(_) => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:422:9 + --> $DIR/empty-types.rs:412:9 | LL | Some(_a) => {} | ^^^^^^^^ @@ -417,7 +417,7 @@ LL | Some(_a) => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:427:9 + --> $DIR/empty-types.rs:417:9 | LL | None => {} | ---- matches all the values already @@ -426,7 +426,7 @@ LL | _ => {} | ^ unreachable pattern error: unreachable pattern - --> $DIR/empty-types.rs:432:9 + --> $DIR/empty-types.rs:422:9 | LL | None => {} | ---- matches all the values already @@ -435,7 +435,7 @@ LL | _a => {} | ^^ unreachable pattern error: unreachable pattern - --> $DIR/empty-types.rs:604:9 + --> $DIR/empty-types.rs:594:9 | LL | _ => {} | ^ @@ -443,7 +443,7 @@ LL | _ => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:607:9 + --> $DIR/empty-types.rs:597:9 | LL | _x => {} | ^^ @@ -451,7 +451,7 @@ LL | _x => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:610:9 + --> $DIR/empty-types.rs:600:9 | LL | _ if false => {} | ^ @@ -459,7 +459,7 @@ LL | _ if false => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:613:9 + --> $DIR/empty-types.rs:603:9 | LL | _x if false => {} | ^^ diff --git a/tests/ui/pattern/usefulness/empty-types.never_pats.stderr b/tests/ui/pattern/usefulness/empty-types.never_pats.stderr index 4856a2f8e08d3..1ecb15f2cae3a 100644 --- a/tests/ui/pattern/usefulness/empty-types.never_pats.stderr +++ b/tests/ui/pattern/usefulness/empty-types.never_pats.stderr @@ -1,5 +1,5 @@ warning: the feature `never_patterns` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/empty-types.rs:14:33 + --> $DIR/empty-types.rs:12:33 | LL | #![cfg_attr(never_pats, feature(never_patterns))] | ^^^^^^^^^^^^^^ @@ -8,20 +8,20 @@ LL | #![cfg_attr(never_pats, feature(never_patterns))] = note: `#[warn(incomplete_features)]` on by default error: unreachable pattern - --> $DIR/empty-types.rs:51:9 + --> $DIR/empty-types.rs:49:9 | LL | _ => {} | ^ | = note: this pattern matches no values because `!` is uninhabited note: the lint level is defined here - --> $DIR/empty-types.rs:17:9 + --> $DIR/empty-types.rs:15:9 | LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:54:9 + --> $DIR/empty-types.rs:52:9 | LL | _x => {} | ^^ @@ -29,7 +29,7 @@ LL | _x => {} = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: type `&!` is non-empty - --> $DIR/empty-types.rs:58:11 + --> $DIR/empty-types.rs:56:11 | LL | match ref_never {} | ^^^^^^^^^ @@ -43,84 +43,75 @@ LL + _ => todo!(), LL + } | -error[E0004]: non-exhaustive patterns: type `(u32, !)` is non-empty - --> $DIR/empty-types.rs:70:11 - | -LL | match tuple_half_never {} - | ^^^^^^^^^^^^^^^^ - | - = note: the matched value is of type `(u32, !)` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown +error: unreachable pattern + --> $DIR/empty-types.rs:70:9 | -LL ~ match tuple_half_never { -LL + _ => todo!(), -LL + } +LL | (_, _) => {} + | ^^^^^^ | + = note: this pattern matches no values because `(u32, !)` is uninhabited -error[E0004]: non-exhaustive patterns: type `(!, !)` is non-empty - --> $DIR/empty-types.rs:77:11 +error: unreachable pattern + --> $DIR/empty-types.rs:76:9 | -LL | match tuple_never {} - | ^^^^^^^^^^^ +LL | _ => {} + | ^ | - = note: the matched value is of type `(!, !)` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + = note: this pattern matches no values because `(!, !)` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:79:9 | -LL ~ match tuple_never { -LL + _ => todo!(), -LL + } +LL | (_, _) => {} + | ^^^^^^ | + = note: this pattern matches no values because `(!, !)` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:87:9 + --> $DIR/empty-types.rs:83:9 | LL | _ => {} | ^ | = note: this pattern matches no values because `!` is uninhabited -error[E0004]: non-exhaustive patterns: `Ok(_)` and `Err(!)` not covered - --> $DIR/empty-types.rs:91:11 +error[E0004]: non-exhaustive patterns: `Ok(_)` not covered + --> $DIR/empty-types.rs:87:11 | LL | match res_u32_never {} - | ^^^^^^^^^^^^^ patterns `Ok(_)` and `Err(!)` not covered + | ^^^^^^^^^^^^^ pattern `Ok(_)` not covered | note: `Result<u32, !>` defined here --> $SRC_DIR/core/src/result.rs:LL:COL - ::: $SRC_DIR/core/src/result.rs:LL:COL - | - = note: not covered ::: $SRC_DIR/core/src/result.rs:LL:COL | = note: not covered = note: the matched value is of type `Result<u32, !>` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ match res_u32_never { -LL + Ok(_) | Err(!) => todo!(), +LL + Ok(_) => todo!(), LL + } | -error[E0004]: non-exhaustive patterns: `Err(!)` not covered - --> $DIR/empty-types.rs:93:11 +error: unreachable pattern + --> $DIR/empty-types.rs:94:9 | -LL | match res_u32_never { - | ^^^^^^^^^^^^^ pattern `Err(!)` not covered +LL | Err(_) => {} + | ^^^^^^ | -note: `Result<u32, !>` defined here - --> $SRC_DIR/core/src/result.rs:LL:COL - ::: $SRC_DIR/core/src/result.rs:LL:COL - | - = note: not covered - = note: the matched value is of type `Result<u32, !>` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + = note: this pattern matches no values because `!` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:99:9 | -LL ~ Ok(_) => {}, -LL + Err(!) +LL | Err(_) => {} + | ^^^^^^ | + = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: `Ok(1_u32..=u32::MAX)` not covered - --> $DIR/empty-types.rs:101:11 + --> $DIR/empty-types.rs:96:11 | LL | match res_u32_never { | ^^^^^^^^^^^^^ pattern `Ok(1_u32..=u32::MAX)` not covered @@ -138,21 +129,7 @@ LL ~ Ok(1_u32..=u32::MAX) => todo!() | error[E0005]: refutable pattern in local binding - --> $DIR/empty-types.rs:106:9 - | -LL | let Ok(_x) = res_u32_never; - | ^^^^^^ pattern `Err(!)` not covered - | - = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant - = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html - = note: the matched value is of type `Result<u32, !>` -help: you might want to use `let else` to handle the variant that isn't matched - | -LL | let Ok(_x) = res_u32_never else { todo!() }; - | ++++++++++++++++ - -error[E0005]: refutable pattern in local binding - --> $DIR/empty-types.rs:108:9 + --> $DIR/empty-types.rs:102:9 | LL | let Ok(_x) = res_u32_never.as_ref(); | ^^^^^^ pattern `Err(_)` not covered @@ -166,7 +143,7 @@ LL | let Ok(_x) = res_u32_never.as_ref() else { todo!() }; | ++++++++++++++++ error[E0005]: refutable pattern in local binding - --> $DIR/empty-types.rs:112:9 + --> $DIR/empty-types.rs:106:9 | LL | let Ok(_x) = &res_u32_never; | ^^^^^^ pattern `&Err(!)` not covered @@ -179,47 +156,56 @@ help: you might want to use `let else` to handle the variant that isn't matched LL | let Ok(_x) = &res_u32_never else { todo!() }; | ++++++++++++++++ -error[E0004]: non-exhaustive patterns: `Ok(!)` and `Err(!)` not covered - --> $DIR/empty-types.rs:116:11 +error: unreachable pattern + --> $DIR/empty-types.rs:112:9 | -LL | match result_never {} - | ^^^^^^^^^^^^ patterns `Ok(!)` and `Err(!)` not covered +LL | _ => {} + | ^ | -note: `Result<!, !>` defined here - --> $SRC_DIR/core/src/result.rs:LL:COL - ::: $SRC_DIR/core/src/result.rs:LL:COL + = note: this pattern matches no values because `Result<!, !>` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:115:9 | - = note: not covered - ::: $SRC_DIR/core/src/result.rs:LL:COL +LL | Ok(_) => {} + | ^^^^^ | - = note: not covered - = note: the matched value is of type `Result<!, !>` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms + = note: this pattern matches no values because `Result<!, !>` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:118:9 | -LL ~ match result_never { -LL + Ok(!) | Err(!), -LL + } +LL | Ok(_) => {} + | ^^^^^ | + = note: this pattern matches no values because `Result<!, !>` is uninhabited -error[E0004]: non-exhaustive patterns: `Err(!)` not covered - --> $DIR/empty-types.rs:121:11 +error: unreachable pattern + --> $DIR/empty-types.rs:119:9 | -LL | match result_never { - | ^^^^^^^^^^^^ pattern `Err(!)` not covered +LL | _ => {} + | ^ | -note: `Result<!, !>` defined here - --> $SRC_DIR/core/src/result.rs:LL:COL - ::: $SRC_DIR/core/src/result.rs:LL:COL + = note: this pattern matches no values because `Result<!, !>` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:122:9 | - = note: not covered - = note: the matched value is of type `Result<!, !>` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown +LL | Ok(_) => {} + | ^^^^^ | -LL | Ok(_) => {}, Err(!) - | ++++++++ + = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:140:13 + --> $DIR/empty-types.rs:123:9 + | +LL | Err(_) => {} + | ^^^^^^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:132:13 | LL | _ => {} | ^ @@ -227,33 +213,31 @@ LL | _ => {} = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:143:13 + --> $DIR/empty-types.rs:135:13 | LL | _ if false => {} | ^ | = note: this pattern matches no values because `Void` is uninhabited -error[E0004]: non-exhaustive patterns: `Some(!)` not covered - --> $DIR/empty-types.rs:146:15 - | -LL | match opt_void { - | ^^^^^^^^ pattern `Some(!)` not covered +error: unreachable pattern + --> $DIR/empty-types.rs:143:13 | -note: `Option<Void>` defined here - --> $SRC_DIR/core/src/option.rs:LL:COL - ::: $SRC_DIR/core/src/option.rs:LL:COL +LL | Some(_) => {} + | ^^^^^^^ | - = note: not covered - = note: the matched value is of type `Option<Void>` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown - | -LL ~ None => {}, -LL + Some(!) + = note: this pattern matches no values because `Void` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:147:13 | +LL | None => {} + | ---- matches all the values already +LL | _ => {} + | ^ unreachable pattern error[E0004]: non-exhaustive patterns: `Some(!)` not covered - --> $DIR/empty-types.rs:165:15 + --> $DIR/empty-types.rs:156:15 | LL | match *ref_opt_void { | ^^^^^^^^^^^^^ pattern `Some(!)` not covered @@ -264,6 +248,7 @@ note: `Option<Void>` defined here | = note: not covered = note: the matched value is of type `Option<Void>` + = note: `Void` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ None => {}, @@ -271,7 +256,7 @@ LL + Some(!) | error: unreachable pattern - --> $DIR/empty-types.rs:208:13 + --> $DIR/empty-types.rs:199:13 | LL | _ => {} | ^ @@ -279,7 +264,7 @@ LL | _ => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:213:13 + --> $DIR/empty-types.rs:204:13 | LL | _ => {} | ^ @@ -287,7 +272,7 @@ LL | _ => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:218:13 + --> $DIR/empty-types.rs:209:13 | LL | _ => {} | ^ @@ -295,7 +280,7 @@ LL | _ => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:223:13 + --> $DIR/empty-types.rs:214:13 | LL | _ => {} | ^ @@ -303,7 +288,7 @@ LL | _ => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:229:13 + --> $DIR/empty-types.rs:220:13 | LL | _ => {} | ^ @@ -311,15 +296,39 @@ LL | _ => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:288:9 + --> $DIR/empty-types.rs:279:9 | LL | _ => {} | ^ | = note: this pattern matches no values because `!` is uninhabited +error: unreachable pattern + --> $DIR/empty-types.rs:282:9 + | +LL | (_, _) => {} + | ^^^^^^ + | + = note: this pattern matches no values because `(!, !)` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:285:9 + | +LL | Ok(_) => {} + | ^^^^^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:286:9 + | +LL | Err(_) => {} + | ^^^^^^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited + error[E0004]: non-exhaustive patterns: type `(u32, !)` is non-empty - --> $DIR/empty-types.rs:316:11 + --> $DIR/empty-types.rs:307:11 | LL | match *x {} | ^^ @@ -333,7 +342,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: type `(!, !)` is non-empty - --> $DIR/empty-types.rs:318:11 + --> $DIR/empty-types.rs:309:11 | LL | match *x {} | ^^ @@ -347,7 +356,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: `Ok(!)` and `Err(!)` not covered - --> $DIR/empty-types.rs:320:11 + --> $DIR/empty-types.rs:311:11 | LL | match *x {} | ^^ patterns `Ok(!)` and `Err(!)` not covered @@ -369,7 +378,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: type `[!; 3]` is non-empty - --> $DIR/empty-types.rs:322:11 + --> $DIR/empty-types.rs:313:11 | LL | match *x {} | ^^ @@ -383,7 +392,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: type `&[!]` is non-empty - --> $DIR/empty-types.rs:327:11 + --> $DIR/empty-types.rs:318:11 | LL | match slice_never {} | ^^^^^^^^^^^ @@ -397,12 +406,13 @@ LL + } | error[E0004]: non-exhaustive patterns: `&[!, ..]` not covered - --> $DIR/empty-types.rs:329:11 + --> $DIR/empty-types.rs:320:11 | LL | match slice_never { | ^^^^^^^^^^^ pattern `&[!, ..]` not covered | = note: the matched value is of type `&[!]` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ [] => {}, @@ -410,7 +420,7 @@ LL + &[!, ..] | error[E0004]: non-exhaustive patterns: `&[]`, `&[!]` and `&[!, !]` not covered - --> $DIR/empty-types.rs:338:11 + --> $DIR/empty-types.rs:329:11 | LL | match slice_never { | ^^^^^^^^^^^ patterns `&[]`, `&[!]` and `&[!, !]` not covered @@ -423,7 +433,7 @@ LL + &[] | &[!] | &[!, !] => todo!() | error[E0004]: non-exhaustive patterns: `&[]` and `&[!, ..]` not covered - --> $DIR/empty-types.rs:352:11 + --> $DIR/empty-types.rs:343:11 | LL | match slice_never { | ^^^^^^^^^^^ patterns `&[]` and `&[!, ..]` not covered @@ -437,7 +447,7 @@ LL + &[] | &[!, ..] => todo!() | error[E0004]: non-exhaustive patterns: type `[!]` is non-empty - --> $DIR/empty-types.rs:359:11 + --> $DIR/empty-types.rs:350:11 | LL | match *slice_never {} | ^^^^^^^^^^^^ @@ -450,22 +460,32 @@ LL + _ => todo!(), LL + } | -error[E0004]: non-exhaustive patterns: type `[!; 3]` is non-empty - --> $DIR/empty-types.rs:366:11 +error: unreachable pattern + --> $DIR/empty-types.rs:359:9 | -LL | match array_3_never {} - | ^^^^^^^^^^^^^ +LL | _ => {} + | ^ | - = note: the matched value is of type `[!; 3]` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + = note: this pattern matches no values because `[!; 3]` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:362:9 | -LL ~ match array_3_never { -LL + _ => todo!(), -LL + } +LL | [_, _, _] => {} + | ^^^^^^^^^ | + = note: this pattern matches no values because `[!; 3]` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:365:9 + | +LL | [_, ..] => {} + | ^^^^^^^ + | + = note: this pattern matches no values because `[!; 3]` is uninhabited error[E0004]: non-exhaustive patterns: type `[!; 0]` is non-empty - --> $DIR/empty-types.rs:389:11 + --> $DIR/empty-types.rs:379:11 | LL | match array_0_never {} | ^^^^^^^^^^^^^ @@ -479,7 +499,7 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:396:9 + --> $DIR/empty-types.rs:386:9 | LL | [] => {} | -- matches all the values already @@ -487,7 +507,7 @@ LL | _ => {} | ^ unreachable pattern error[E0004]: non-exhaustive patterns: `[]` not covered - --> $DIR/empty-types.rs:398:11 + --> $DIR/empty-types.rs:388:11 | LL | match array_0_never { | ^^^^^^^^^^^^^ pattern `[]` not covered @@ -500,8 +520,42 @@ LL ~ [..] if false => {}, LL + [] => todo!() | +error: unreachable pattern + --> $DIR/empty-types.rs:407:9 + | +LL | Some(_) => {} + | ^^^^^^^ + | + = note: this pattern matches no values because `!` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:412:9 + | +LL | Some(_a) => {} + | ^^^^^^^^ + | + = note: this pattern matches no values because `!` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:417:9 + | +LL | None => {} + | ---- matches all the values already +LL | // !useful, !reachable +LL | _ => {} + | ^ unreachable pattern + +error: unreachable pattern + --> $DIR/empty-types.rs:422:9 + | +LL | None => {} + | ---- matches all the values already +LL | // !useful, !reachable +LL | _a => {} + | ^^ unreachable pattern + error[E0004]: non-exhaustive patterns: `&Some(!)` not covered - --> $DIR/empty-types.rs:452:11 + --> $DIR/empty-types.rs:442:11 | LL | match ref_opt_never { | ^^^^^^^^^^^^^ pattern `&Some(!)` not covered @@ -512,6 +566,7 @@ note: `Option<!>` defined here | = note: not covered = note: the matched value is of type `&Option<!>` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ &None => {}, @@ -519,7 +574,7 @@ LL + &Some(!) | error[E0004]: non-exhaustive patterns: `Some(!)` not covered - --> $DIR/empty-types.rs:493:11 + --> $DIR/empty-types.rs:483:11 | LL | match *ref_opt_never { | ^^^^^^^^^^^^^^ pattern `Some(!)` not covered @@ -530,6 +585,7 @@ note: `Option<!>` defined here | = note: not covered = note: the matched value is of type `Option<!>` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ None => {}, @@ -537,7 +593,7 @@ LL + Some(!) | error[E0004]: non-exhaustive patterns: `Err(!)` not covered - --> $DIR/empty-types.rs:541:11 + --> $DIR/empty-types.rs:531:11 | LL | match *ref_res_never { | ^^^^^^^^^^^^^^ pattern `Err(!)` not covered @@ -548,6 +604,7 @@ note: `Result<!, !>` defined here | = note: not covered = note: the matched value is of type `Result<!, !>` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ Ok(_) => {}, @@ -555,7 +612,7 @@ LL + Err(!) | error[E0004]: non-exhaustive patterns: `Err(!)` not covered - --> $DIR/empty-types.rs:552:11 + --> $DIR/empty-types.rs:542:11 | LL | match *ref_res_never { | ^^^^^^^^^^^^^^ pattern `Err(!)` not covered @@ -566,6 +623,7 @@ note: `Result<!, !>` defined here | = note: not covered = note: the matched value is of type `Result<!, !>` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ Ok(_a) => {}, @@ -573,7 +631,7 @@ LL + Err(!) | error[E0004]: non-exhaustive patterns: type `(u32, !)` is non-empty - --> $DIR/empty-types.rs:571:11 + --> $DIR/empty-types.rs:561:11 | LL | match *ref_tuple_half_never {} | ^^^^^^^^^^^^^^^^^^^^^ @@ -587,7 +645,7 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:604:9 + --> $DIR/empty-types.rs:594:9 | LL | _ => {} | ^ @@ -595,7 +653,7 @@ LL | _ => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:607:9 + --> $DIR/empty-types.rs:597:9 | LL | _x => {} | ^^ @@ -603,7 +661,7 @@ LL | _x => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:610:9 + --> $DIR/empty-types.rs:600:9 | LL | _ if false => {} | ^ @@ -611,7 +669,7 @@ LL | _ if false => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:613:9 + --> $DIR/empty-types.rs:603:9 | LL | _x if false => {} | ^^ @@ -619,12 +677,13 @@ LL | _x if false => {} = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: `&!` not covered - --> $DIR/empty-types.rs:638:11 + --> $DIR/empty-types.rs:628:11 | LL | match ref_never { | ^^^^^^^^^ pattern `&!` not covered | = note: the matched value is of type `&!` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required = note: references are always considered inhabited = note: match arms with guards don't count towards exhaustivity help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown @@ -634,7 +693,7 @@ LL + &! | error[E0004]: non-exhaustive patterns: `Ok(!)` not covered - --> $DIR/empty-types.rs:654:11 + --> $DIR/empty-types.rs:644:11 | LL | match *ref_result_never { | ^^^^^^^^^^^^^^^^^ pattern `Ok(!)` not covered @@ -645,6 +704,7 @@ note: `Result<!, !>` defined here | = note: not covered = note: the matched value is of type `Result<!, !>` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ Err(_) => {}, @@ -652,7 +712,7 @@ LL + Ok(!) | error[E0004]: non-exhaustive patterns: `Some(!)` not covered - --> $DIR/empty-types.rs:674:11 + --> $DIR/empty-types.rs:664:11 | LL | match *x { | ^^ pattern `Some(!)` not covered @@ -663,13 +723,14 @@ note: `Option<Result<!, !>>` defined here | = note: not covered = note: the matched value is of type `Option<Result<!, !>>` + = note: `Result<!, !>` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ None => {}, LL + Some(!) | -error: aborting due to 49 previous errors; 1 warning emitted +error: aborting due to 64 previous errors; 1 warning emitted Some errors have detailed explanations: E0004, E0005. For more information about an error, try `rustc --explain E0004`. diff --git a/tests/ui/pattern/usefulness/empty-types.normal.stderr b/tests/ui/pattern/usefulness/empty-types.normal.stderr index 78db9ee349b4f..c3421cd592edb 100644 --- a/tests/ui/pattern/usefulness/empty-types.normal.stderr +++ b/tests/ui/pattern/usefulness/empty-types.normal.stderr @@ -1,18 +1,18 @@ error: unreachable pattern - --> $DIR/empty-types.rs:51:9 + --> $DIR/empty-types.rs:49:9 | LL | _ => {} | ^ | = note: this pattern matches no values because `!` is uninhabited note: the lint level is defined here - --> $DIR/empty-types.rs:17:9 + --> $DIR/empty-types.rs:15:9 | LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:54:9 + --> $DIR/empty-types.rs:52:9 | LL | _x => {} | ^^ @@ -20,7 +20,7 @@ LL | _x => {} = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: type `&!` is non-empty - --> $DIR/empty-types.rs:58:11 + --> $DIR/empty-types.rs:56:11 | LL | match ref_never {} | ^^^^^^^^^ @@ -34,84 +34,75 @@ LL + _ => todo!(), LL + } | -error[E0004]: non-exhaustive patterns: type `(u32, !)` is non-empty - --> $DIR/empty-types.rs:70:11 - | -LL | match tuple_half_never {} - | ^^^^^^^^^^^^^^^^ - | - = note: the matched value is of type `(u32, !)` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown +error: unreachable pattern + --> $DIR/empty-types.rs:70:9 | -LL ~ match tuple_half_never { -LL + _ => todo!(), -LL + } +LL | (_, _) => {} + | ^^^^^^ | + = note: this pattern matches no values because `(u32, !)` is uninhabited -error[E0004]: non-exhaustive patterns: type `(!, !)` is non-empty - --> $DIR/empty-types.rs:77:11 +error: unreachable pattern + --> $DIR/empty-types.rs:76:9 | -LL | match tuple_never {} - | ^^^^^^^^^^^ +LL | _ => {} + | ^ | - = note: the matched value is of type `(!, !)` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + = note: this pattern matches no values because `(!, !)` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:79:9 | -LL ~ match tuple_never { -LL + _ => todo!(), -LL + } +LL | (_, _) => {} + | ^^^^^^ | + = note: this pattern matches no values because `(!, !)` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:87:9 + --> $DIR/empty-types.rs:83:9 | LL | _ => {} | ^ | = note: this pattern matches no values because `!` is uninhabited -error[E0004]: non-exhaustive patterns: `Ok(_)` and `Err(_)` not covered - --> $DIR/empty-types.rs:91:11 +error[E0004]: non-exhaustive patterns: `Ok(_)` not covered + --> $DIR/empty-types.rs:87:11 | LL | match res_u32_never {} - | ^^^^^^^^^^^^^ patterns `Ok(_)` and `Err(_)` not covered + | ^^^^^^^^^^^^^ pattern `Ok(_)` not covered | note: `Result<u32, !>` defined here --> $SRC_DIR/core/src/result.rs:LL:COL - ::: $SRC_DIR/core/src/result.rs:LL:COL - | - = note: not covered ::: $SRC_DIR/core/src/result.rs:LL:COL | = note: not covered = note: the matched value is of type `Result<u32, !>` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ match res_u32_never { -LL + Ok(_) | Err(_) => todo!(), +LL + Ok(_) => todo!(), LL + } | -error[E0004]: non-exhaustive patterns: `Err(_)` not covered - --> $DIR/empty-types.rs:93:11 - | -LL | match res_u32_never { - | ^^^^^^^^^^^^^ pattern `Err(_)` not covered +error: unreachable pattern + --> $DIR/empty-types.rs:94:9 | -note: `Result<u32, !>` defined here - --> $SRC_DIR/core/src/result.rs:LL:COL - ::: $SRC_DIR/core/src/result.rs:LL:COL +LL | Err(_) => {} + | ^^^^^^ | - = note: not covered - = note: the matched value is of type `Result<u32, !>` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + = note: this pattern matches no values because `!` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:99:9 | -LL ~ Ok(_) => {}, -LL + Err(_) => todo!() +LL | Err(_) => {} + | ^^^^^^ | + = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: `Ok(1_u32..=u32::MAX)` not covered - --> $DIR/empty-types.rs:101:11 + --> $DIR/empty-types.rs:96:11 | LL | match res_u32_never { | ^^^^^^^^^^^^^ pattern `Ok(1_u32..=u32::MAX)` not covered @@ -129,21 +120,7 @@ LL ~ Ok(1_u32..=u32::MAX) => todo!() | error[E0005]: refutable pattern in local binding - --> $DIR/empty-types.rs:106:9 - | -LL | let Ok(_x) = res_u32_never; - | ^^^^^^ pattern `Err(_)` not covered - | - = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant - = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html - = note: the matched value is of type `Result<u32, !>` -help: you might want to use `let else` to handle the variant that isn't matched - | -LL | let Ok(_x) = res_u32_never else { todo!() }; - | ++++++++++++++++ - -error[E0005]: refutable pattern in local binding - --> $DIR/empty-types.rs:108:9 + --> $DIR/empty-types.rs:102:9 | LL | let Ok(_x) = res_u32_never.as_ref(); | ^^^^^^ pattern `Err(_)` not covered @@ -157,7 +134,7 @@ LL | let Ok(_x) = res_u32_never.as_ref() else { todo!() }; | ++++++++++++++++ error[E0005]: refutable pattern in local binding - --> $DIR/empty-types.rs:112:9 + --> $DIR/empty-types.rs:106:9 | LL | let Ok(_x) = &res_u32_never; | ^^^^^^ pattern `&Err(_)` not covered @@ -170,47 +147,56 @@ help: you might want to use `let else` to handle the variant that isn't matched LL | let Ok(_x) = &res_u32_never else { todo!() }; | ++++++++++++++++ -error[E0004]: non-exhaustive patterns: `Ok(_)` and `Err(_)` not covered - --> $DIR/empty-types.rs:116:11 +error: unreachable pattern + --> $DIR/empty-types.rs:112:9 | -LL | match result_never {} - | ^^^^^^^^^^^^ patterns `Ok(_)` and `Err(_)` not covered +LL | _ => {} + | ^ | -note: `Result<!, !>` defined here - --> $SRC_DIR/core/src/result.rs:LL:COL - ::: $SRC_DIR/core/src/result.rs:LL:COL + = note: this pattern matches no values because `Result<!, !>` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:115:9 | - = note: not covered - ::: $SRC_DIR/core/src/result.rs:LL:COL +LL | Ok(_) => {} + | ^^^^^ | - = note: not covered - = note: the matched value is of type `Result<!, !>` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms + = note: this pattern matches no values because `Result<!, !>` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:118:9 | -LL ~ match result_never { -LL + Ok(_) | Err(_) => todo!(), -LL + } +LL | Ok(_) => {} + | ^^^^^ | + = note: this pattern matches no values because `Result<!, !>` is uninhabited -error[E0004]: non-exhaustive patterns: `Err(_)` not covered - --> $DIR/empty-types.rs:121:11 +error: unreachable pattern + --> $DIR/empty-types.rs:119:9 | -LL | match result_never { - | ^^^^^^^^^^^^ pattern `Err(_)` not covered +LL | _ => {} + | ^ | -note: `Result<!, !>` defined here - --> $SRC_DIR/core/src/result.rs:LL:COL - ::: $SRC_DIR/core/src/result.rs:LL:COL + = note: this pattern matches no values because `Result<!, !>` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:122:9 | - = note: not covered - = note: the matched value is of type `Result<!, !>` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown +LL | Ok(_) => {} + | ^^^^^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:123:9 | -LL | Ok(_) => {}, Err(_) => todo!() - | +++++++++++++++++++ +LL | Err(_) => {} + | ^^^^^^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:140:13 + --> $DIR/empty-types.rs:132:13 | LL | _ => {} | ^ @@ -218,33 +204,31 @@ LL | _ => {} = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:143:13 + --> $DIR/empty-types.rs:135:13 | LL | _ if false => {} | ^ | = note: this pattern matches no values because `Void` is uninhabited -error[E0004]: non-exhaustive patterns: `Some(_)` not covered - --> $DIR/empty-types.rs:146:15 - | -LL | match opt_void { - | ^^^^^^^^ pattern `Some(_)` not covered - | -note: `Option<Void>` defined here - --> $SRC_DIR/core/src/option.rs:LL:COL - ::: $SRC_DIR/core/src/option.rs:LL:COL +error: unreachable pattern + --> $DIR/empty-types.rs:143:13 | - = note: not covered - = note: the matched value is of type `Option<Void>` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown +LL | Some(_) => {} + | ^^^^^^^ | -LL ~ None => {}, -LL + Some(_) => todo!() + = note: this pattern matches no values because `Void` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:147:13 | +LL | None => {} + | ---- matches all the values already +LL | _ => {} + | ^ unreachable pattern error[E0004]: non-exhaustive patterns: `Some(_)` not covered - --> $DIR/empty-types.rs:165:15 + --> $DIR/empty-types.rs:156:15 | LL | match *ref_opt_void { | ^^^^^^^^^^^^^ pattern `Some(_)` not covered @@ -255,6 +239,7 @@ note: `Option<Void>` defined here | = note: not covered = note: the matched value is of type `Option<Void>` + = note: `Void` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ None => {}, @@ -262,7 +247,7 @@ LL + Some(_) => todo!() | error: unreachable pattern - --> $DIR/empty-types.rs:208:13 + --> $DIR/empty-types.rs:199:13 | LL | _ => {} | ^ @@ -270,7 +255,7 @@ LL | _ => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:213:13 + --> $DIR/empty-types.rs:204:13 | LL | _ => {} | ^ @@ -278,7 +263,7 @@ LL | _ => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:218:13 + --> $DIR/empty-types.rs:209:13 | LL | _ => {} | ^ @@ -286,7 +271,7 @@ LL | _ => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:223:13 + --> $DIR/empty-types.rs:214:13 | LL | _ => {} | ^ @@ -294,7 +279,7 @@ LL | _ => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:229:13 + --> $DIR/empty-types.rs:220:13 | LL | _ => {} | ^ @@ -302,15 +287,39 @@ LL | _ => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:288:9 + --> $DIR/empty-types.rs:279:9 | LL | _ => {} | ^ | = note: this pattern matches no values because `!` is uninhabited +error: unreachable pattern + --> $DIR/empty-types.rs:282:9 + | +LL | (_, _) => {} + | ^^^^^^ + | + = note: this pattern matches no values because `(!, !)` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:285:9 + | +LL | Ok(_) => {} + | ^^^^^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:286:9 + | +LL | Err(_) => {} + | ^^^^^^ + | + = note: this pattern matches no values because `Result<!, !>` is uninhabited + error[E0004]: non-exhaustive patterns: type `(u32, !)` is non-empty - --> $DIR/empty-types.rs:316:11 + --> $DIR/empty-types.rs:307:11 | LL | match *x {} | ^^ @@ -324,7 +333,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: type `(!, !)` is non-empty - --> $DIR/empty-types.rs:318:11 + --> $DIR/empty-types.rs:309:11 | LL | match *x {} | ^^ @@ -338,7 +347,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: `Ok(_)` and `Err(_)` not covered - --> $DIR/empty-types.rs:320:11 + --> $DIR/empty-types.rs:311:11 | LL | match *x {} | ^^ patterns `Ok(_)` and `Err(_)` not covered @@ -360,7 +369,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: type `[!; 3]` is non-empty - --> $DIR/empty-types.rs:322:11 + --> $DIR/empty-types.rs:313:11 | LL | match *x {} | ^^ @@ -374,7 +383,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: type `&[!]` is non-empty - --> $DIR/empty-types.rs:327:11 + --> $DIR/empty-types.rs:318:11 | LL | match slice_never {} | ^^^^^^^^^^^ @@ -388,12 +397,13 @@ LL + } | error[E0004]: non-exhaustive patterns: `&[_, ..]` not covered - --> $DIR/empty-types.rs:329:11 + --> $DIR/empty-types.rs:320:11 | LL | match slice_never { | ^^^^^^^^^^^ pattern `&[_, ..]` not covered | = note: the matched value is of type `&[!]` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ [] => {}, @@ -401,7 +411,7 @@ LL + &[_, ..] => todo!() | error[E0004]: non-exhaustive patterns: `&[]`, `&[_]` and `&[_, _]` not covered - --> $DIR/empty-types.rs:338:11 + --> $DIR/empty-types.rs:329:11 | LL | match slice_never { | ^^^^^^^^^^^ patterns `&[]`, `&[_]` and `&[_, _]` not covered @@ -414,7 +424,7 @@ LL + &[] | &[_] | &[_, _] => todo!() | error[E0004]: non-exhaustive patterns: `&[]` and `&[_, ..]` not covered - --> $DIR/empty-types.rs:352:11 + --> $DIR/empty-types.rs:343:11 | LL | match slice_never { | ^^^^^^^^^^^ patterns `&[]` and `&[_, ..]` not covered @@ -428,7 +438,7 @@ LL + &[] | &[_, ..] => todo!() | error[E0004]: non-exhaustive patterns: type `[!]` is non-empty - --> $DIR/empty-types.rs:359:11 + --> $DIR/empty-types.rs:350:11 | LL | match *slice_never {} | ^^^^^^^^^^^^ @@ -441,22 +451,32 @@ LL + _ => todo!(), LL + } | -error[E0004]: non-exhaustive patterns: type `[!; 3]` is non-empty - --> $DIR/empty-types.rs:366:11 +error: unreachable pattern + --> $DIR/empty-types.rs:359:9 | -LL | match array_3_never {} - | ^^^^^^^^^^^^^ +LL | _ => {} + | ^ | - = note: the matched value is of type `[!; 3]` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + = note: this pattern matches no values because `[!; 3]` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:362:9 | -LL ~ match array_3_never { -LL + _ => todo!(), -LL + } +LL | [_, _, _] => {} + | ^^^^^^^^^ + | + = note: this pattern matches no values because `[!; 3]` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:365:9 + | +LL | [_, ..] => {} + | ^^^^^^^ | + = note: this pattern matches no values because `[!; 3]` is uninhabited error[E0004]: non-exhaustive patterns: type `[!; 0]` is non-empty - --> $DIR/empty-types.rs:389:11 + --> $DIR/empty-types.rs:379:11 | LL | match array_0_never {} | ^^^^^^^^^^^^^ @@ -470,7 +490,7 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:396:9 + --> $DIR/empty-types.rs:386:9 | LL | [] => {} | -- matches all the values already @@ -478,7 +498,7 @@ LL | _ => {} | ^ unreachable pattern error[E0004]: non-exhaustive patterns: `[]` not covered - --> $DIR/empty-types.rs:398:11 + --> $DIR/empty-types.rs:388:11 | LL | match array_0_never { | ^^^^^^^^^^^^^ pattern `[]` not covered @@ -491,8 +511,42 @@ LL ~ [..] if false => {}, LL + [] => todo!() | +error: unreachable pattern + --> $DIR/empty-types.rs:407:9 + | +LL | Some(_) => {} + | ^^^^^^^ + | + = note: this pattern matches no values because `!` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:412:9 + | +LL | Some(_a) => {} + | ^^^^^^^^ + | + = note: this pattern matches no values because `!` is uninhabited + +error: unreachable pattern + --> $DIR/empty-types.rs:417:9 + | +LL | None => {} + | ---- matches all the values already +LL | // !useful, !reachable +LL | _ => {} + | ^ unreachable pattern + +error: unreachable pattern + --> $DIR/empty-types.rs:422:9 + | +LL | None => {} + | ---- matches all the values already +LL | // !useful, !reachable +LL | _a => {} + | ^^ unreachable pattern + error[E0004]: non-exhaustive patterns: `&Some(_)` not covered - --> $DIR/empty-types.rs:452:11 + --> $DIR/empty-types.rs:442:11 | LL | match ref_opt_never { | ^^^^^^^^^^^^^ pattern `&Some(_)` not covered @@ -503,6 +557,7 @@ note: `Option<!>` defined here | = note: not covered = note: the matched value is of type `&Option<!>` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ &None => {}, @@ -510,7 +565,7 @@ LL + &Some(_) => todo!() | error[E0004]: non-exhaustive patterns: `Some(_)` not covered - --> $DIR/empty-types.rs:493:11 + --> $DIR/empty-types.rs:483:11 | LL | match *ref_opt_never { | ^^^^^^^^^^^^^^ pattern `Some(_)` not covered @@ -521,6 +576,7 @@ note: `Option<!>` defined here | = note: not covered = note: the matched value is of type `Option<!>` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ None => {}, @@ -528,7 +584,7 @@ LL + Some(_) => todo!() | error[E0004]: non-exhaustive patterns: `Err(_)` not covered - --> $DIR/empty-types.rs:541:11 + --> $DIR/empty-types.rs:531:11 | LL | match *ref_res_never { | ^^^^^^^^^^^^^^ pattern `Err(_)` not covered @@ -539,6 +595,7 @@ note: `Result<!, !>` defined here | = note: not covered = note: the matched value is of type `Result<!, !>` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ Ok(_) => {}, @@ -546,7 +603,7 @@ LL + Err(_) => todo!() | error[E0004]: non-exhaustive patterns: `Err(_)` not covered - --> $DIR/empty-types.rs:552:11 + --> $DIR/empty-types.rs:542:11 | LL | match *ref_res_never { | ^^^^^^^^^^^^^^ pattern `Err(_)` not covered @@ -557,6 +614,7 @@ note: `Result<!, !>` defined here | = note: not covered = note: the matched value is of type `Result<!, !>` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ Ok(_a) => {}, @@ -564,7 +622,7 @@ LL + Err(_) => todo!() | error[E0004]: non-exhaustive patterns: type `(u32, !)` is non-empty - --> $DIR/empty-types.rs:571:11 + --> $DIR/empty-types.rs:561:11 | LL | match *ref_tuple_half_never {} | ^^^^^^^^^^^^^^^^^^^^^ @@ -578,7 +636,7 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:604:9 + --> $DIR/empty-types.rs:594:9 | LL | _ => {} | ^ @@ -586,7 +644,7 @@ LL | _ => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:607:9 + --> $DIR/empty-types.rs:597:9 | LL | _x => {} | ^^ @@ -594,7 +652,7 @@ LL | _x => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:610:9 + --> $DIR/empty-types.rs:600:9 | LL | _ if false => {} | ^ @@ -602,7 +660,7 @@ LL | _ if false => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/empty-types.rs:613:9 + --> $DIR/empty-types.rs:603:9 | LL | _x if false => {} | ^^ @@ -610,12 +668,13 @@ LL | _x if false => {} = note: this pattern matches no values because `!` is uninhabited error[E0004]: non-exhaustive patterns: `&_` not covered - --> $DIR/empty-types.rs:638:11 + --> $DIR/empty-types.rs:628:11 | LL | match ref_never { | ^^^^^^^^^ pattern `&_` not covered | = note: the matched value is of type `&!` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required = note: references are always considered inhabited = note: match arms with guards don't count towards exhaustivity help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown @@ -625,7 +684,7 @@ LL + &_ => todo!() | error[E0004]: non-exhaustive patterns: `Ok(_)` not covered - --> $DIR/empty-types.rs:654:11 + --> $DIR/empty-types.rs:644:11 | LL | match *ref_result_never { | ^^^^^^^^^^^^^^^^^ pattern `Ok(_)` not covered @@ -636,6 +695,7 @@ note: `Result<!, !>` defined here | = note: not covered = note: the matched value is of type `Result<!, !>` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ Err(_) => {}, @@ -643,7 +703,7 @@ LL + Ok(_) => todo!() | error[E0004]: non-exhaustive patterns: `Some(_)` not covered - --> $DIR/empty-types.rs:674:11 + --> $DIR/empty-types.rs:664:11 | LL | match *x { | ^^ pattern `Some(_)` not covered @@ -654,13 +714,14 @@ note: `Option<Result<!, !>>` defined here | = note: not covered = note: the matched value is of type `Option<Result<!, !>>` + = note: `Result<!, !>` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ None => {}, LL + Some(_) => todo!() | -error: aborting due to 49 previous errors +error: aborting due to 64 previous errors Some errors have detailed explanations: E0004, E0005. For more information about an error, try `rustc --explain E0004`. diff --git a/tests/ui/pattern/usefulness/empty-types.rs b/tests/ui/pattern/usefulness/empty-types.rs index 46024b1caebc7..639c48cea12c5 100644 --- a/tests/ui/pattern/usefulness/empty-types.rs +++ b/tests/ui/pattern/usefulness/empty-types.rs @@ -1,4 +1,4 @@ -//@ revisions: normal min_exh_pats exhaustive_patterns never_pats +//@ revisions: normal exhaustive_patterns never_pats // // This tests correct handling of empty types in exhaustiveness checking. // @@ -9,7 +9,6 @@ // This feature is useful to avoid `!` falling back to `()` all the time. #![feature(never_type_fallback)] #![cfg_attr(exhaustive_patterns, feature(exhaustive_patterns))] -#![cfg_attr(min_exh_pats, feature(min_exhaustive_patterns))] #![cfg_attr(never_pats, feature(never_patterns))] //[never_pats]~^ WARN the feature `never_patterns` is incomplete #![allow(dead_code, unreachable_code)] @@ -67,19 +66,17 @@ fn basic(x: NeverBundle) { let tuple_half_never: (u32, !) = x.tuple_half_never; match tuple_half_never {} - //[normal,never_pats]~^ ERROR non-empty match tuple_half_never { - (_, _) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + (_, _) => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern } let tuple_never: (!, !) = x.tuple_never; match tuple_never {} - //[normal,never_pats]~^ ERROR non-empty match tuple_never { - _ => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + _ => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern } match tuple_never { - (_, _) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + (_, _) => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern } match tuple_never.0 {} match tuple_never.0 { @@ -90,44 +87,40 @@ fn basic(x: NeverBundle) { match res_u32_never {} //~^ ERROR non-exhaustive match res_u32_never { - //[normal,never_pats]~^ ERROR non-exhaustive Ok(_) => {} } match res_u32_never { Ok(_) => {} - Err(_) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + Err(_) => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern } match res_u32_never { //~^ ERROR non-exhaustive Ok(0) => {} - Err(_) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + Err(_) => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern } let Ok(_x) = res_u32_never; - //[normal,never_pats]~^ ERROR refutable let Ok(_x) = res_u32_never.as_ref(); //~^ ERROR refutable // Non-obvious difference: here there's an implicit dereference in the patterns, which makes the // inner place !known_valid. `exhaustive_patterns` ignores this. let Ok(_x) = &res_u32_never; - //[normal,min_exh_pats,never_pats]~^ ERROR refutable + //[normal,never_pats]~^ ERROR refutable let result_never: Result<!, !> = x.result_never; match result_never {} - //[normal,never_pats]~^ ERROR non-exhaustive match result_never { - _ => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + _ => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern } match result_never { - //[normal,never_pats]~^ ERROR non-exhaustive - Ok(_) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + Ok(_) => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern } match result_never { - Ok(_) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern - _ => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + Ok(_) => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern + _ => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern } match result_never { - Ok(_) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern - Err(_) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + Ok(_) => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern + Err(_) => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern } } @@ -143,16 +136,15 @@ fn void_same_as_never(x: NeverBundle) { } let opt_void: Option<Void> = None; match opt_void { - //[normal,never_pats]~^ ERROR non-exhaustive None => {} } match opt_void { None => {} - Some(_) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + Some(_) => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern } match opt_void { None => {} - _ => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + _ => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern } let ref_void: &Void = &x.void; @@ -162,7 +154,7 @@ fn void_same_as_never(x: NeverBundle) { } let ref_opt_void: &Option<Void> = &None; match *ref_opt_void { - //[normal,min_exh_pats,never_pats]~^ ERROR non-exhaustive + //[normal,never_pats]~^ ERROR non-exhaustive None => {} } match *ref_opt_void { @@ -287,11 +279,11 @@ fn nested_validity_tracking(bundle: NeverBundle) { _ => {} //~ ERROR unreachable pattern } match tuple_never { - (_, _) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + (_, _) => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern } match result_never { - Ok(_) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern - Err(_) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + Ok(_) => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern + Err(_) => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern } // These should be considered !known_valid and not warn unreachable. @@ -312,13 +304,13 @@ fn invalid_empty_match(bundle: NeverBundle) { match *x {} let x: &(u32, !) = &bundle.tuple_half_never; - match *x {} //[normal,min_exh_pats,never_pats]~ ERROR non-exhaustive + match *x {} //[normal,never_pats]~ ERROR non-exhaustive let x: &(!, !) = &bundle.tuple_never; - match *x {} //[normal,min_exh_pats,never_pats]~ ERROR non-exhaustive + match *x {} //[normal,never_pats]~ ERROR non-exhaustive let x: &Result<!, !> = &bundle.result_never; - match *x {} //[normal,min_exh_pats,never_pats]~ ERROR non-exhaustive + match *x {} //[normal,never_pats]~ ERROR non-exhaustive let x: &[!; 3] = &bundle.array_3_never; - match *x {} //[normal,min_exh_pats,never_pats]~ ERROR non-exhaustive + match *x {} //[normal,never_pats]~ ERROR non-exhaustive } fn arrays_and_slices(x: NeverBundle) { @@ -326,7 +318,7 @@ fn arrays_and_slices(x: NeverBundle) { match slice_never {} //~^ ERROR non-empty match slice_never { - //[normal,min_exh_pats,never_pats]~^ ERROR not covered + //[normal,never_pats]~^ ERROR not covered [] => {} } match slice_never { @@ -335,7 +327,7 @@ fn arrays_and_slices(x: NeverBundle) { [_, _, ..] => {} } match slice_never { - //[normal,min_exh_pats]~^ ERROR `&[]`, `&[_]` and `&[_, _]` not covered + //[normal]~^ ERROR `&[]`, `&[_]` and `&[_, _]` not covered //[exhaustive_patterns]~^^ ERROR `&[]` not covered //[never_pats]~^^^ ERROR `&[]`, `&[!]` and `&[!, !]` not covered [_, _, _, ..] => {} @@ -349,7 +341,7 @@ fn arrays_and_slices(x: NeverBundle) { _x => {} } match slice_never { - //[normal,min_exh_pats]~^ ERROR `&[]` and `&[_, ..]` not covered + //[normal]~^ ERROR `&[]` and `&[_, ..]` not covered //[exhaustive_patterns]~^^ ERROR `&[]` not covered //[never_pats]~^^^ ERROR `&[]` and `&[!, ..]` not covered &[..] if false => {} @@ -363,15 +355,14 @@ fn arrays_and_slices(x: NeverBundle) { let array_3_never: [!; 3] = x.array_3_never; match array_3_never {} - //[normal,never_pats]~^ ERROR non-empty match array_3_never { - _ => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + _ => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern } match array_3_never { - [_, _, _] => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + [_, _, _] => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern } match array_3_never { - [_, ..] => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + [_, ..] => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern } let ref_array_3_never: &[!; 3] = &array_3_never; @@ -413,22 +404,22 @@ fn bindings(x: NeverBundle) { match opt_never { None => {} // !useful, !reachable - Some(_) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + Some(_) => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern } match opt_never { None => {} // !useful, !reachable - Some(_a) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + Some(_a) => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern } match opt_never { None => {} // !useful, !reachable - _ => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + _ => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern } match opt_never { None => {} // !useful, !reachable - _a => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + _a => {} //[exhaustive_patterns,normal,never_pats]~ ERROR unreachable pattern } // The scrutinee is known_valid, but under the `&` isn't anymore. @@ -449,7 +440,7 @@ fn bindings(x: NeverBundle) { &_a => {} } match ref_opt_never { - //[normal,min_exh_pats,never_pats]~^ ERROR non-exhaustive + //[normal,never_pats]~^ ERROR non-exhaustive &None => {} } match ref_opt_never { @@ -490,7 +481,7 @@ fn bindings(x: NeverBundle) { ref _a => {} } match *ref_opt_never { - //[normal,min_exh_pats,never_pats]~^ ERROR non-exhaustive + //[normal,never_pats]~^ ERROR non-exhaustive None => {} } match *ref_opt_never { @@ -538,7 +529,7 @@ fn bindings(x: NeverBundle) { let ref_res_never: &Result<!, !> = &x.result_never; match *ref_res_never { - //[normal,min_exh_pats,never_pats]~^ ERROR non-exhaustive + //[normal,never_pats]~^ ERROR non-exhaustive // useful, reachable Ok(_) => {} } @@ -549,7 +540,7 @@ fn bindings(x: NeverBundle) { _ => {} } match *ref_res_never { - //[normal,min_exh_pats,never_pats]~^ ERROR non-exhaustive + //[normal,never_pats]~^ ERROR non-exhaustive // useful, !reachable Ok(_a) => {} } @@ -568,7 +559,7 @@ fn bindings(x: NeverBundle) { let ref_tuple_half_never: &(u32, !) = &x.tuple_half_never; match *ref_tuple_half_never {} - //[normal,min_exh_pats,never_pats]~^ ERROR non-empty + //[normal,never_pats]~^ ERROR non-empty match *ref_tuple_half_never { // useful, reachable (_, _) => {} @@ -635,7 +626,7 @@ fn guards_and_validity(x: NeverBundle) { _a if false => {} } match ref_never { - //[normal,min_exh_pats,never_pats]~^ ERROR non-exhaustive + //[normal,never_pats]~^ ERROR non-exhaustive // useful, !reachable &_a if false => {} } @@ -651,7 +642,7 @@ fn guards_and_validity(x: NeverBundle) { Err(_) => {} } match *ref_result_never { - //[normal,min_exh_pats]~^ ERROR `Ok(_)` not covered + //[normal]~^ ERROR `Ok(_)` not covered //[never_pats]~^^ ERROR `Ok(!)` not covered // useful, reachable Ok(_) if false => {} @@ -671,7 +662,7 @@ fn diagnostics_subtlety(x: NeverBundle) { // Regression test for diagnostics: don't report `Some(Ok(_))` and `Some(Err(_))`. let x: &Option<Result<!, !>> = &None; match *x { - //[normal,min_exh_pats]~^ ERROR `Some(_)` not covered + //[normal]~^ ERROR `Some(_)` not covered //[never_pats]~^^ ERROR `Some(!)` not covered None => {} } diff --git a/tests/ui/pattern/usefulness/explain-unreachable-pats.rs b/tests/ui/pattern/usefulness/explain-unreachable-pats.rs index 98f781b6a09f7..44d194055d9bd 100644 --- a/tests/ui/pattern/usefulness/explain-unreachable-pats.rs +++ b/tests/ui/pattern/usefulness/explain-unreachable-pats.rs @@ -1,5 +1,4 @@ #![feature(never_type)] -#![feature(min_exhaustive_patterns)] #![deny(unreachable_patterns)] //~^ NOTE lint level is defined here diff --git a/tests/ui/pattern/usefulness/explain-unreachable-pats.stderr b/tests/ui/pattern/usefulness/explain-unreachable-pats.stderr index e2eecf4a9f386..105d4f73f660a 100644 --- a/tests/ui/pattern/usefulness/explain-unreachable-pats.stderr +++ b/tests/ui/pattern/usefulness/explain-unreachable-pats.stderr @@ -1,5 +1,5 @@ error: unreachable pattern - --> $DIR/explain-unreachable-pats.rs:11:9 + --> $DIR/explain-unreachable-pats.rs:10:9 | LL | (1 | 2,) => {} | -------- matches all the values already @@ -8,19 +8,19 @@ LL | (2,) => {} | ^^^^ unreachable pattern | note: the lint level is defined here - --> $DIR/explain-unreachable-pats.rs:3:9 + --> $DIR/explain-unreachable-pats.rs:2:9 | LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ error: unreachable pattern - --> $DIR/explain-unreachable-pats.rs:22:9 + --> $DIR/explain-unreachable-pats.rs:21:9 | LL | (1 | 2,) => {} | ^^^^^^^^ unreachable pattern | note: these patterns collectively make the last one unreachable - --> $DIR/explain-unreachable-pats.rs:22:9 + --> $DIR/explain-unreachable-pats.rs:21:9 | LL | (1,) => {} | ---- matches some of the same values @@ -32,7 +32,7 @@ LL | (1 | 2,) => {} | ^^^^^^^^ collectively making this unreachable error: unreachable pattern - --> $DIR/explain-unreachable-pats.rs:33:9 + --> $DIR/explain-unreachable-pats.rs:32:9 | LL | Err(_) => {} | ^^^^^^ @@ -40,7 +40,7 @@ LL | Err(_) => {} = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/explain-unreachable-pats.rs:46:9 + --> $DIR/explain-unreachable-pats.rs:45:9 | LL | (Err(_), Err(_)) => {} | ^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | (Err(_), Err(_)) => {} = note: this pattern matches no values because `Void2` is uninhabited error: unreachable pattern - --> $DIR/explain-unreachable-pats.rs:52:9 + --> $DIR/explain-unreachable-pats.rs:51:9 | LL | (Err(_), Err(_)) => {} | ^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | (Err(_), Err(_)) => {} = note: this pattern matches no values because `Void1` is uninhabited error: unreachable pattern - --> $DIR/explain-unreachable-pats.rs:61:11 + --> $DIR/explain-unreachable-pats.rs:60:11 | LL | if let (0 | - matches all the values already @@ -65,13 +65,13 @@ LL | | 0, _) = (0, 0) {} | ^ unreachable pattern error: unreachable pattern - --> $DIR/explain-unreachable-pats.rs:71:9 + --> $DIR/explain-unreachable-pats.rs:70:9 | LL | (_, true) => {} | ^^^^^^^^^ unreachable pattern | note: these patterns collectively make the last one unreachable - --> $DIR/explain-unreachable-pats.rs:71:9 + --> $DIR/explain-unreachable-pats.rs:70:9 | LL | (true, _) => {} | --------- matches some of the same values @@ -83,7 +83,7 @@ LL | (_, true) => {} | ^^^^^^^^^ collectively making this unreachable error: unreachable pattern - --> $DIR/explain-unreachable-pats.rs:84:9 + --> $DIR/explain-unreachable-pats.rs:83:9 | LL | (true, _) => {} | --------- matches all the values already @@ -92,7 +92,7 @@ LL | (true, true) => {} | ^^^^^^^^^^^^ unreachable pattern error: unreachable pattern - --> $DIR/explain-unreachable-pats.rs:96:9 + --> $DIR/explain-unreachable-pats.rs:95:9 | LL | (_, true, 0..10) => {} | ---------------- matches all the values already diff --git a/tests/ui/pattern/usefulness/impl-trait.rs b/tests/ui/pattern/usefulness/impl-trait.rs index 1fec9a2633eec..c1cc279f74ce9 100644 --- a/tests/ui/pattern/usefulness/impl-trait.rs +++ b/tests/ui/pattern/usefulness/impl-trait.rs @@ -1,5 +1,4 @@ #![feature(never_type)] -#![feature(min_exhaustive_patterns)] #![feature(type_alias_impl_trait)] #![feature(non_exhaustive_omitted_patterns_lint)] #![deny(unreachable_patterns)] diff --git a/tests/ui/pattern/usefulness/impl-trait.stderr b/tests/ui/pattern/usefulness/impl-trait.stderr index c079f5a259dde..92932e4853881 100644 --- a/tests/ui/pattern/usefulness/impl-trait.stderr +++ b/tests/ui/pattern/usefulness/impl-trait.stderr @@ -1,18 +1,18 @@ error: unreachable pattern - --> $DIR/impl-trait.rs:17:13 + --> $DIR/impl-trait.rs:16:13 | LL | _ => {} | ^ | = note: this pattern matches no values because `Void` is uninhabited note: the lint level is defined here - --> $DIR/impl-trait.rs:5:9 + --> $DIR/impl-trait.rs:4:9 | LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ error: unreachable pattern - --> $DIR/impl-trait.rs:31:13 + --> $DIR/impl-trait.rs:30:13 | LL | _ => {} | ^ @@ -20,7 +20,7 @@ LL | _ => {} = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern - --> $DIR/impl-trait.rs:45:13 + --> $DIR/impl-trait.rs:44:13 | LL | Some(_) => {} | ^^^^^^^ @@ -28,7 +28,7 @@ LL | Some(_) => {} = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern - --> $DIR/impl-trait.rs:49:13 + --> $DIR/impl-trait.rs:48:13 | LL | None => {} | ---- matches all the values already @@ -36,7 +36,7 @@ LL | _ => {} | ^ unreachable pattern error: unreachable pattern - --> $DIR/impl-trait.rs:59:13 + --> $DIR/impl-trait.rs:58:13 | LL | Some(_) => {} | ^^^^^^^ @@ -44,7 +44,7 @@ LL | Some(_) => {} = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern - --> $DIR/impl-trait.rs:63:13 + --> $DIR/impl-trait.rs:62:13 | LL | None => {} | ---- matches all the values already @@ -52,7 +52,7 @@ LL | _ => {} | ^ unreachable pattern error: unreachable pattern - --> $DIR/impl-trait.rs:76:9 + --> $DIR/impl-trait.rs:75:9 | LL | _ => {} | ^ @@ -60,7 +60,7 @@ LL | _ => {} = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern - --> $DIR/impl-trait.rs:86:9 + --> $DIR/impl-trait.rs:85:9 | LL | _ => {} | - matches any value @@ -68,7 +68,7 @@ LL | Some((a, b)) => {} | ^^^^^^^^^^^^ unreachable pattern error: unreachable pattern - --> $DIR/impl-trait.rs:94:13 + --> $DIR/impl-trait.rs:93:13 | LL | _ => {} | ^ @@ -76,7 +76,7 @@ LL | _ => {} = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern - --> $DIR/impl-trait.rs:105:9 + --> $DIR/impl-trait.rs:104:9 | LL | Some((a, b)) => {} | ------------ matches all the values already @@ -84,7 +84,7 @@ LL | Some((mut x, mut y)) => { | ^^^^^^^^^^^^^^^^^^^^ unreachable pattern error: unreachable pattern - --> $DIR/impl-trait.rs:124:13 + --> $DIR/impl-trait.rs:123:13 | LL | _ => {} | - matches any value @@ -92,7 +92,7 @@ LL | Rec { n: 0, w: Some(Rec { n: 0, w: _ }) } => {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unreachable pattern error: unreachable pattern - --> $DIR/impl-trait.rs:138:13 + --> $DIR/impl-trait.rs:137:13 | LL | _ => {} | ^ @@ -100,7 +100,7 @@ LL | _ => {} = note: this pattern matches no values because `SecretelyVoid` is uninhabited error: unreachable pattern - --> $DIR/impl-trait.rs:151:13 + --> $DIR/impl-trait.rs:150:13 | LL | _ => {} | ^ @@ -108,7 +108,7 @@ LL | _ => {} = note: this pattern matches no values because `SecretelyDoubleVoid` is uninhabited error[E0004]: non-exhaustive patterns: type `impl Copy` is non-empty - --> $DIR/impl-trait.rs:23:11 + --> $DIR/impl-trait.rs:22:11 | LL | match return_never_rpit(x) {} | ^^^^^^^^^^^^^^^^^^^^ @@ -122,7 +122,7 @@ LL + } | error[E0004]: non-exhaustive patterns: type `T` is non-empty - --> $DIR/impl-trait.rs:37:11 + --> $DIR/impl-trait.rs:36:11 | LL | match return_never_tait(x) {} | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/pattern/usefulness/match-privately-empty.exhaustive_patterns.stderr b/tests/ui/pattern/usefulness/match-privately-empty.exhaustive_patterns.stderr index 261a4b3353f23..463e104f970c4 100644 --- a/tests/ui/pattern/usefulness/match-privately-empty.exhaustive_patterns.stderr +++ b/tests/ui/pattern/usefulness/match-privately-empty.exhaustive_patterns.stderr @@ -1,5 +1,5 @@ error[E0004]: non-exhaustive patterns: `Some(Private { misc: true, .. })` not covered - --> $DIR/match-privately-empty.rs:15:11 + --> $DIR/match-privately-empty.rs:14:11 | LL | match private::DATA { | ^^^^^^^^^^^^^ pattern `Some(Private { misc: true, .. })` not covered diff --git a/tests/ui/pattern/usefulness/match-privately-empty.normal.stderr b/tests/ui/pattern/usefulness/match-privately-empty.normal.stderr new file mode 100644 index 0000000000000..463e104f970c4 --- /dev/null +++ b/tests/ui/pattern/usefulness/match-privately-empty.normal.stderr @@ -0,0 +1,21 @@ +error[E0004]: non-exhaustive patterns: `Some(Private { misc: true, .. })` not covered + --> $DIR/match-privately-empty.rs:14:11 + | +LL | match private::DATA { + | ^^^^^^^^^^^^^ pattern `Some(Private { misc: true, .. })` not covered + | +note: `Option<Private>` defined here + --> $SRC_DIR/core/src/option.rs:LL:COL + ::: $SRC_DIR/core/src/option.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Option<Private>` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ Some(private::Private { misc: false, .. }) => {}, +LL + Some(Private { misc: true, .. }) => todo!() + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0004`. diff --git a/tests/ui/pattern/usefulness/match-privately-empty.rs b/tests/ui/pattern/usefulness/match-privately-empty.rs index 7e1d0dc48f2c2..bfea15af18011 100644 --- a/tests/ui/pattern/usefulness/match-privately-empty.rs +++ b/tests/ui/pattern/usefulness/match-privately-empty.rs @@ -1,6 +1,5 @@ -//@ revisions: min_exhaustive_patterns exhaustive_patterns +//@ revisions: normal exhaustive_patterns #![cfg_attr(exhaustive_patterns, feature(exhaustive_patterns))] -#![cfg_attr(min_exhaustive_patterns, feature(min_exhaustive_patterns))] #![feature(never_type)] mod private { diff --git a/tests/ui/pattern/usefulness/slice_of_empty.exhaustive_patterns.stderr b/tests/ui/pattern/usefulness/slice_of_empty.exhaustive_patterns.stderr index e5e581447e66c..c4fcd67cfdbdc 100644 --- a/tests/ui/pattern/usefulness/slice_of_empty.exhaustive_patterns.stderr +++ b/tests/ui/pattern/usefulness/slice_of_empty.exhaustive_patterns.stderr @@ -1,5 +1,5 @@ error[E0004]: non-exhaustive patterns: `&[]` not covered - --> $DIR/slice_of_empty.rs:21:11 + --> $DIR/slice_of_empty.rs:20:11 | LL | match nevers { | ^^^^^^ pattern `&[]` not covered diff --git a/tests/ui/pattern/usefulness/slice_of_empty.normal.stderr b/tests/ui/pattern/usefulness/slice_of_empty.normal.stderr new file mode 100644 index 0000000000000..c9afd1bfc9016 --- /dev/null +++ b/tests/ui/pattern/usefulness/slice_of_empty.normal.stderr @@ -0,0 +1,30 @@ +error[E0004]: non-exhaustive patterns: `&[_, ..]` not covered + --> $DIR/slice_of_empty.rs:9:11 + | +LL | match nevers { + | ^^^^^^ pattern `&[_, ..]` not covered + | + = note: the matched value is of type `&[!]` + = note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ &[] => (), +LL ~ &[_, ..] => todo!(), + | + +error[E0004]: non-exhaustive patterns: `&[]` and `&[_, _, ..]` not covered + --> $DIR/slice_of_empty.rs:20:11 + | +LL | match nevers { + | ^^^^^^ patterns `&[]` and `&[_, _, ..]` not covered + | + = note: the matched value is of type `&[!]` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms + | +LL ~ &[_] => (), +LL ~ &[] | &[_, _, ..] => todo!(), + | + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0004`. diff --git a/tests/ui/pattern/usefulness/slice_of_empty.rs b/tests/ui/pattern/usefulness/slice_of_empty.rs index 785fccaabf7eb..e186ba5134d5f 100644 --- a/tests/ui/pattern/usefulness/slice_of_empty.rs +++ b/tests/ui/pattern/usefulness/slice_of_empty.rs @@ -1,6 +1,5 @@ -//@ revisions: min_exhaustive_patterns exhaustive_patterns +//@ revisions: normal exhaustive_patterns #![cfg_attr(exhaustive_patterns, feature(exhaustive_patterns))] -#![cfg_attr(min_exhaustive_patterns, feature(min_exhaustive_patterns))] #![feature(never_type)] #![deny(unreachable_patterns)] @@ -8,7 +7,7 @@ fn main() {} fn foo(nevers: &[!]) { match nevers { - //[min_exhaustive_patterns]~^ ERROR non-exhaustive patterns: `&[_, ..]` not covered + //[normal]~^ ERROR non-exhaustive patterns: `&[_, ..]` not covered &[] => (), }; @@ -20,7 +19,7 @@ fn foo(nevers: &[!]) { match nevers { //[exhaustive_patterns]~^ ERROR non-exhaustive patterns: `&[]` not covered - //[min_exhaustive_patterns]~^^ ERROR non-exhaustive patterns: `&[]` and `&[_, _, ..]` not covered + //[normal]~^^ ERROR non-exhaustive patterns: `&[]` and `&[_, _, ..]` not covered &[_] => (), }; } diff --git a/tests/ui/pattern/usefulness/uninhabited.rs b/tests/ui/pattern/usefulness/uninhabited.rs index 72e602ee8d2d7..5c774b7874a66 100644 --- a/tests/ui/pattern/usefulness/uninhabited.rs +++ b/tests/ui/pattern/usefulness/uninhabited.rs @@ -5,7 +5,6 @@ // `Ty::is_inhabited_from` function. #![feature(never_type)] #![feature(never_type_fallback)] -#![feature(min_exhaustive_patterns)] #![deny(unreachable_patterns)] macro_rules! assert_empty { diff --git a/tests/ui/reachable/unreachable-loop-patterns.rs b/tests/ui/reachable/unreachable-loop-patterns.rs index 4294a18ba440f..d074e3a6ece4b 100644 --- a/tests/ui/reachable/unreachable-loop-patterns.rs +++ b/tests/ui/reachable/unreachable-loop-patterns.rs @@ -1,6 +1,4 @@ #![feature(never_type, never_type_fallback)] -#![feature(min_exhaustive_patterns)] - #![allow(unreachable_code)] #![deny(unreachable_patterns)] diff --git a/tests/ui/reachable/unreachable-loop-patterns.stderr b/tests/ui/reachable/unreachable-loop-patterns.stderr index bdd9b5ee41151..9b7c2ba4acdcc 100644 --- a/tests/ui/reachable/unreachable-loop-patterns.stderr +++ b/tests/ui/reachable/unreachable-loop-patterns.stderr @@ -1,12 +1,12 @@ error: unreachable pattern - --> $DIR/unreachable-loop-patterns.rs:18:9 + --> $DIR/unreachable-loop-patterns.rs:16:9 | LL | for _ in unimplemented!() as Void {} | ^ | = note: this pattern matches no values because `Void` is uninhabited note: the lint level is defined here - --> $DIR/unreachable-loop-patterns.rs:5:9 + --> $DIR/unreachable-loop-patterns.rs:3:9 | LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/check.rs b/tests/ui/rfcs/rfc-0000-never_patterns/check.rs index dc13dd05fa6a2..77f79003edc86 100644 --- a/tests/ui/rfcs/rfc-0000-never_patterns/check.rs +++ b/tests/ui/rfcs/rfc-0000-never_patterns/check.rs @@ -11,22 +11,22 @@ macro_rules! never { } fn no_arms_or_guards(x: Void) { - match None::<Void> { + match &None::<Void> { Some(!) => {} //~^ ERROR a never pattern is always unreachable None => {} } - match None::<Void> { //~ ERROR: `Some(!)` not covered + match &None::<Void> { //~ ERROR: `&Some(!)` not covered Some(!) if true, //~^ ERROR guard on a never pattern None => {} } - match None::<Void> { //~ ERROR: `Some(!)` not covered + match &None::<Void> { //~ ERROR: `&Some(!)` not covered Some(!) if true => {} //~^ ERROR a never pattern is always unreachable None => {} } - match None::<Void> { + match &None::<Void> { Some(never!()) => {} //~^ ERROR a never pattern is always unreachable None => {} diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/check.stderr b/tests/ui/rfcs/rfc-0000-never_patterns/check.stderr index fbf7aa02ac2b9..4622ea59b5471 100644 --- a/tests/ui/rfcs/rfc-0000-never_patterns/check.stderr +++ b/tests/ui/rfcs/rfc-0000-never_patterns/check.stderr @@ -31,40 +31,42 @@ LL | Some(never!()) => {} | this will never be executed | help: remove this expression -error[E0004]: non-exhaustive patterns: `Some(!)` not covered +error[E0004]: non-exhaustive patterns: `&Some(!)` not covered --> $DIR/check.rs:19:11 | -LL | match None::<Void> { - | ^^^^^^^^^^^^ pattern `Some(!)` not covered +LL | match &None::<Void> { + | ^^^^^^^^^^^^^ pattern `&Some(!)` not covered | note: `Option<Void>` defined here --> $SRC_DIR/core/src/option.rs:LL:COL ::: $SRC_DIR/core/src/option.rs:LL:COL | = note: not covered - = note: the matched value is of type `Option<Void>` + = note: the matched value is of type `&Option<Void>` + = note: `Void` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ None => {}, -LL + Some(!) +LL + &Some(!) | -error[E0004]: non-exhaustive patterns: `Some(!)` not covered +error[E0004]: non-exhaustive patterns: `&Some(!)` not covered --> $DIR/check.rs:24:11 | -LL | match None::<Void> { - | ^^^^^^^^^^^^ pattern `Some(!)` not covered +LL | match &None::<Void> { + | ^^^^^^^^^^^^^ pattern `&Some(!)` not covered | note: `Option<Void>` defined here --> $SRC_DIR/core/src/option.rs:LL:COL ::: $SRC_DIR/core/src/option.rs:LL:COL | = note: not covered - = note: the matched value is of type `Option<Void>` + = note: the matched value is of type `&Option<Void>` + = note: `Void` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ None => {}, -LL + Some(!) +LL + &Some(!) | error: aborting due to 6 previous errors diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/typeck.fail.stderr b/tests/ui/rfcs/rfc-0000-never_patterns/typeck.fail.stderr index 013a8b53a5509..9e2ae2846d51c 100644 --- a/tests/ui/rfcs/rfc-0000-never_patterns/typeck.fail.stderr +++ b/tests/ui/rfcs/rfc-0000-never_patterns/typeck.fail.stderr @@ -1,5 +1,5 @@ error: mismatched types - --> $DIR/typeck.rs:25:9 + --> $DIR/typeck.rs:24:9 | LL | !, | ^ a never pattern must be used on an uninhabited type @@ -7,7 +7,7 @@ LL | !, = note: the matched value is of type `()` error: mismatched types - --> $DIR/typeck.rs:29:9 + --> $DIR/typeck.rs:28:9 | LL | !, | ^ a never pattern must be used on an uninhabited type @@ -15,7 +15,7 @@ LL | !, = note: the matched value is of type `(i32, bool)` error: mismatched types - --> $DIR/typeck.rs:33:13 + --> $DIR/typeck.rs:32:13 | LL | (_, !), | ^ a never pattern must be used on an uninhabited type @@ -23,7 +23,7 @@ LL | (_, !), = note: the matched value is of type `bool` error: mismatched types - --> $DIR/typeck.rs:38:14 + --> $DIR/typeck.rs:37:14 | LL | Some(!), | ^ a never pattern must be used on an uninhabited type @@ -31,7 +31,7 @@ LL | Some(!), = note: the matched value is of type `i32` error: mismatched types - --> $DIR/typeck.rs:45:9 + --> $DIR/typeck.rs:44:9 | LL | !, | ^ a never pattern must be used on an uninhabited type @@ -39,7 +39,7 @@ LL | !, = note: the matched value is of type `()` error: mismatched types - --> $DIR/typeck.rs:52:9 + --> $DIR/typeck.rs:51:9 | LL | !, | ^ a never pattern must be used on an uninhabited type @@ -47,7 +47,7 @@ LL | !, = note: the matched value is of type `Option<Void>` error: mismatched types - --> $DIR/typeck.rs:57:9 + --> $DIR/typeck.rs:56:9 | LL | !, | ^ a never pattern must be used on an uninhabited type @@ -55,7 +55,7 @@ LL | !, = note: the matched value is of type `[Void]` error: mismatched types - --> $DIR/typeck.rs:63:9 + --> $DIR/typeck.rs:62:9 | LL | !, | ^ a never pattern must be used on an uninhabited type diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/typeck.rs b/tests/ui/rfcs/rfc-0000-never_patterns/typeck.rs index 8300f953dc162..bf74b282f6cdf 100644 --- a/tests/ui/rfcs/rfc-0000-never_patterns/typeck.rs +++ b/tests/ui/rfcs/rfc-0000-never_patterns/typeck.rs @@ -2,7 +2,6 @@ //@[pass] check-pass //@[fail] check-fail #![feature(never_patterns)] -#![feature(min_exhaustive_patterns)] #![allow(incomplete_features)] #[derive(Copy, Clone)] diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/unreachable.exh_pats.stderr b/tests/ui/rfcs/rfc-0000-never_patterns/unreachable.exh_pats.stderr index a875041d89c57..d78f4a5f6ebb5 100644 --- a/tests/ui/rfcs/rfc-0000-never_patterns/unreachable.exh_pats.stderr +++ b/tests/ui/rfcs/rfc-0000-never_patterns/unreachable.exh_pats.stderr @@ -1,18 +1,18 @@ error: unreachable pattern - --> $DIR/unreachable.rs:17:9 + --> $DIR/unreachable.rs:16:9 | LL | Err(!), | ^^^^^^ | = note: this pattern matches no values because `Void` is uninhabited note: the lint level is defined here - --> $DIR/unreachable.rs:7:9 + --> $DIR/unreachable.rs:6:9 | LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ error: unreachable pattern - --> $DIR/unreachable.rs:20:19 + --> $DIR/unreachable.rs:19:19 | LL | let (Ok(_x) | Err(!)) = res_void; | ^^^^^^ @@ -20,7 +20,7 @@ LL | let (Ok(_x) | Err(!)) = res_void; = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern - --> $DIR/unreachable.rs:22:12 + --> $DIR/unreachable.rs:21:12 | LL | if let Err(!) = res_void {} | ^^^^^^ @@ -28,7 +28,7 @@ LL | if let Err(!) = res_void {} = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern - --> $DIR/unreachable.rs:24:24 + --> $DIR/unreachable.rs:23:24 | LL | if let (Ok(true) | Err(!)) = res_void {} | ^^^^^^ @@ -36,7 +36,7 @@ LL | if let (Ok(true) | Err(!)) = res_void {} = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern - --> $DIR/unreachable.rs:26:23 + --> $DIR/unreachable.rs:25:23 | LL | for (Ok(mut _x) | Err(!)) in [res_void] {} | ^^^^^^ @@ -44,7 +44,7 @@ LL | for (Ok(mut _x) | Err(!)) in [res_void] {} = note: this pattern matches no values because `Void` is uninhabited error: unreachable pattern - --> $DIR/unreachable.rs:30:18 + --> $DIR/unreachable.rs:29:18 | LL | fn foo((Ok(_x) | Err(!)): Result<bool, Void>) {} | ^^^^^^ diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/unreachable.normal.stderr b/tests/ui/rfcs/rfc-0000-never_patterns/unreachable.normal.stderr new file mode 100644 index 0000000000000..a3bf8e80ecec7 --- /dev/null +++ b/tests/ui/rfcs/rfc-0000-never_patterns/unreachable.normal.stderr @@ -0,0 +1,44 @@ +error: unreachable pattern + --> $DIR/unreachable.rs:16:9 + | +LL | Err(!), + | ^^^^^^ + | +note: the lint level is defined here + --> $DIR/unreachable.rs:6:9 + | +LL | #![deny(unreachable_patterns)] + | ^^^^^^^^^^^^^^^^^^^^ + +error: unreachable pattern + --> $DIR/unreachable.rs:19:19 + | +LL | let (Ok(_x) | Err(!)) = res_void; + | ^^^^^^ + +error: unreachable pattern + --> $DIR/unreachable.rs:21:12 + | +LL | if let Err(!) = res_void {} + | ^^^^^^ + +error: unreachable pattern + --> $DIR/unreachable.rs:23:24 + | +LL | if let (Ok(true) | Err(!)) = res_void {} + | ^^^^^^ + +error: unreachable pattern + --> $DIR/unreachable.rs:25:23 + | +LL | for (Ok(mut _x) | Err(!)) in [res_void] {} + | ^^^^^^ + +error: unreachable pattern + --> $DIR/unreachable.rs:29:18 + | +LL | fn foo((Ok(_x) | Err(!)): Result<bool, Void>) {} + | ^^^^^^ + +error: aborting due to 6 previous errors + diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/unreachable.rs b/tests/ui/rfcs/rfc-0000-never_patterns/unreachable.rs index 4d20c67cf0f86..f68da4aa17316 100644 --- a/tests/ui/rfcs/rfc-0000-never_patterns/unreachable.rs +++ b/tests/ui/rfcs/rfc-0000-never_patterns/unreachable.rs @@ -1,8 +1,5 @@ -//@ revisions: normal exh_pats -//@[normal] check-pass #![feature(never_patterns)] #![allow(incomplete_features)] -#![cfg_attr(exh_pats, feature(min_exhaustive_patterns))] #![allow(dead_code, unreachable_code)] #![deny(unreachable_patterns)] @@ -15,17 +12,17 @@ fn main() { match res_void { Ok(_x) => {} Err(!), - //[exh_pats]~^ ERROR unreachable + //~^ ERROR unreachable } let (Ok(_x) | Err(!)) = res_void; - //[exh_pats]~^ ERROR unreachable + //~^ ERROR unreachable if let Err(!) = res_void {} - //[exh_pats]~^ ERROR unreachable + //~^ ERROR unreachable if let (Ok(true) | Err(!)) = res_void {} - //[exh_pats]~^ ERROR unreachable + //~^ ERROR unreachable for (Ok(mut _x) | Err(!)) in [res_void] {} - //[exh_pats]~^ ERROR unreachable + //~^ ERROR unreachable } fn foo((Ok(_x) | Err(!)): Result<bool, Void>) {} -//[exh_pats]~^ ERROR unreachable +//~^ ERROR unreachable diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/unreachable.stderr b/tests/ui/rfcs/rfc-0000-never_patterns/unreachable.stderr new file mode 100644 index 0000000000000..79b640d9f419f --- /dev/null +++ b/tests/ui/rfcs/rfc-0000-never_patterns/unreachable.stderr @@ -0,0 +1,55 @@ +error: unreachable pattern + --> $DIR/unreachable.rs:14:9 + | +LL | Err(!), + | ^^^^^^ + | + = note: this pattern matches no values because `Void` is uninhabited +note: the lint level is defined here + --> $DIR/unreachable.rs:4:9 + | +LL | #![deny(unreachable_patterns)] + | ^^^^^^^^^^^^^^^^^^^^ + +error: unreachable pattern + --> $DIR/unreachable.rs:17:19 + | +LL | let (Ok(_x) | Err(!)) = res_void; + | ^^^^^^ + | + = note: this pattern matches no values because `Void` is uninhabited + +error: unreachable pattern + --> $DIR/unreachable.rs:19:12 + | +LL | if let Err(!) = res_void {} + | ^^^^^^ + | + = note: this pattern matches no values because `Void` is uninhabited + +error: unreachable pattern + --> $DIR/unreachable.rs:21:24 + | +LL | if let (Ok(true) | Err(!)) = res_void {} + | ^^^^^^ + | + = note: this pattern matches no values because `Void` is uninhabited + +error: unreachable pattern + --> $DIR/unreachable.rs:23:23 + | +LL | for (Ok(mut _x) | Err(!)) in [res_void] {} + | ^^^^^^ + | + = note: this pattern matches no values because `Void` is uninhabited + +error: unreachable pattern + --> $DIR/unreachable.rs:27:18 + | +LL | fn foo((Ok(_x) | Err(!)): Result<bool, Void>) {} + | ^^^^^^ + | + = note: this pattern matches no values because `Void` is uninhabited + +error: aborting due to 6 previous errors + diff --git a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/indirect_match_same_crate.rs b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/indirect_match_same_crate.rs index 8f090fe886a00..d81896eba1956 100644 --- a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/indirect_match_same_crate.rs +++ b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/indirect_match_same_crate.rs @@ -1,3 +1,4 @@ +//@ check-pass #![feature(never_type)] #[non_exhaustive] @@ -28,24 +29,24 @@ pub struct IndirectUninhabitedVariants(UninhabitedVariants); struct A; // This test checks that an empty match on a non-exhaustive uninhabited type through a level of -// indirection from the defining crate will not compile without `#![feature(exhaustive_patterns)]`. +// indirection from the defining crate compiles. fn cannot_empty_match_on_empty_enum_to_anything(x: IndirectUninhabitedEnum) -> A { - match x {} //~ ERROR non-exhaustive patterns + match x {} } fn cannot_empty_match_on_empty_struct_to_anything(x: IndirectUninhabitedStruct) -> A { - match x {} //~ ERROR non-exhaustive patterns + match x {} } fn cannot_empty_match_on_empty_tuple_struct_to_anything(x: IndirectUninhabitedTupleStruct) -> A { - match x {} //~ ERROR non-exhaustive patterns + match x {} } fn cannot_empty_match_on_enum_with_empty_variants_struct_to_anything( x: IndirectUninhabitedVariants, ) -> A { - match x {} //~ ERROR non-exhaustive patterns + match x {} } fn main() {} diff --git a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/indirect_match_same_crate.stderr b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/indirect_match_same_crate.stderr deleted file mode 100644 index c121905414035..0000000000000 --- a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/indirect_match_same_crate.stderr +++ /dev/null @@ -1,79 +0,0 @@ -error[E0004]: non-exhaustive patterns: type `IndirectUninhabitedEnum` is non-empty - --> $DIR/indirect_match_same_crate.rs:34:11 - | -LL | match x {} - | ^ - | -note: `IndirectUninhabitedEnum` defined here - --> $DIR/indirect_match_same_crate.rs:20:12 - | -LL | pub struct IndirectUninhabitedEnum(UninhabitedEnum); - | ^^^^^^^^^^^^^^^^^^^^^^^ - = note: the matched value is of type `IndirectUninhabitedEnum` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown - | -LL ~ match x { -LL + _ => todo!(), -LL ~ } - | - -error[E0004]: non-exhaustive patterns: type `IndirectUninhabitedStruct` is non-empty - --> $DIR/indirect_match_same_crate.rs:38:11 - | -LL | match x {} - | ^ - | -note: `IndirectUninhabitedStruct` defined here - --> $DIR/indirect_match_same_crate.rs:22:12 - | -LL | pub struct IndirectUninhabitedStruct(UninhabitedStruct); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: the matched value is of type `IndirectUninhabitedStruct` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown - | -LL ~ match x { -LL + _ => todo!(), -LL ~ } - | - -error[E0004]: non-exhaustive patterns: type `IndirectUninhabitedTupleStruct` is non-empty - --> $DIR/indirect_match_same_crate.rs:42:11 - | -LL | match x {} - | ^ - | -note: `IndirectUninhabitedTupleStruct` defined here - --> $DIR/indirect_match_same_crate.rs:24:12 - | -LL | pub struct IndirectUninhabitedTupleStruct(UninhabitedTupleStruct); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: the matched value is of type `IndirectUninhabitedTupleStruct` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown - | -LL ~ match x { -LL + _ => todo!(), -LL ~ } - | - -error[E0004]: non-exhaustive patterns: type `IndirectUninhabitedVariants` is non-empty - --> $DIR/indirect_match_same_crate.rs:48:11 - | -LL | match x {} - | ^ - | -note: `IndirectUninhabitedVariants` defined here - --> $DIR/indirect_match_same_crate.rs:26:12 - | -LL | pub struct IndirectUninhabitedVariants(UninhabitedVariants); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: the matched value is of type `IndirectUninhabitedVariants` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown - | -LL ~ match x { -LL + _ => todo!(), -LL ~ } - | - -error: aborting due to 4 previous errors - -For more information about this error, try `rustc --explain E0004`. diff --git a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/indirect_match_with_exhaustive_patterns.rs b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/indirect_match_with_exhaustive_patterns.rs index c40a2676e84ce..dd9a570522a26 100644 --- a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/indirect_match_with_exhaustive_patterns.rs +++ b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/indirect_match_with_exhaustive_patterns.rs @@ -1,6 +1,5 @@ //@ aux-build:uninhabited.rs #![deny(unreachable_patterns)] -#![feature(min_exhaustive_patterns)] #![feature(never_type)] extern crate uninhabited; diff --git a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/indirect_match_with_exhaustive_patterns.stderr b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/indirect_match_with_exhaustive_patterns.stderr index ef97c1fa17f39..745b196a0e3ad 100644 --- a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/indirect_match_with_exhaustive_patterns.stderr +++ b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/indirect_match_with_exhaustive_patterns.stderr @@ -1,5 +1,5 @@ error[E0004]: non-exhaustive patterns: type `IndirectUninhabitedEnum` is non-empty - --> $DIR/indirect_match_with_exhaustive_patterns.rs:23:11 + --> $DIR/indirect_match_with_exhaustive_patterns.rs:22:11 | LL | match x {} | ^ @@ -18,7 +18,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: type `IndirectUninhabitedStruct` is non-empty - --> $DIR/indirect_match_with_exhaustive_patterns.rs:27:11 + --> $DIR/indirect_match_with_exhaustive_patterns.rs:26:11 | LL | match x {} | ^ @@ -37,7 +37,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: type `IndirectUninhabitedTupleStruct` is non-empty - --> $DIR/indirect_match_with_exhaustive_patterns.rs:31:11 + --> $DIR/indirect_match_with_exhaustive_patterns.rs:30:11 | LL | match x {} | ^ @@ -56,7 +56,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: type `IndirectUninhabitedVariants` is non-empty - --> $DIR/indirect_match_with_exhaustive_patterns.rs:37:11 + --> $DIR/indirect_match_with_exhaustive_patterns.rs:36:11 | LL | match x {} | ^ diff --git a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/indirect_match_with_exhaustive_patterns_same_crate.rs b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/indirect_match_with_exhaustive_patterns_same_crate.rs index efaec0ebdbe3b..32f5f504136ab 100644 --- a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/indirect_match_with_exhaustive_patterns_same_crate.rs +++ b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/indirect_match_with_exhaustive_patterns_same_crate.rs @@ -1,7 +1,6 @@ //@ check-pass #![deny(unreachable_patterns)] -#![feature(min_exhaustive_patterns)] #![feature(never_type)] #[non_exhaustive] diff --git a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/match_same_crate.rs b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/match_same_crate.rs index ebbdfba15f3a3..04f7fe26b5ae1 100644 --- a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/match_same_crate.rs +++ b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/match_same_crate.rs @@ -1,3 +1,4 @@ +//@ check-pass #![feature(never_type)] #[non_exhaustive] @@ -27,15 +28,15 @@ fn cannot_empty_match_on_empty_enum_to_anything(x: UninhabitedEnum) -> A { } fn cannot_empty_match_on_empty_struct_to_anything(x: UninhabitedStruct) -> A { - match x {} //~ ERROR non-exhaustive patterns + match x {} } fn cannot_empty_match_on_empty_tuple_struct_to_anything(x: UninhabitedTupleStruct) -> A { - match x {} //~ ERROR non-exhaustive patterns + match x {} } fn cannot_empty_match_on_enum_with_empty_variants_struct_to_anything(x: UninhabitedVariants) -> A { - match x {} //~ ERROR non-exhaustive patterns + match x {} } fn main() {} diff --git a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/match_same_crate.stderr b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/match_same_crate.stderr deleted file mode 100644 index 7a12aca8520d3..0000000000000 --- a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/match_same_crate.stderr +++ /dev/null @@ -1,64 +0,0 @@ -error[E0004]: non-exhaustive patterns: type `UninhabitedStruct` is non-empty - --> $DIR/match_same_crate.rs:30:11 - | -LL | match x {} - | ^ - | -note: `UninhabitedStruct` defined here - --> $DIR/match_same_crate.rs:8:12 - | -LL | pub struct UninhabitedStruct { - | ^^^^^^^^^^^^^^^^^ - = note: the matched value is of type `UninhabitedStruct` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown - | -LL ~ match x { -LL + _ => todo!(), -LL ~ } - | - -error[E0004]: non-exhaustive patterns: type `UninhabitedTupleStruct` is non-empty - --> $DIR/match_same_crate.rs:34:11 - | -LL | match x {} - | ^ - | -note: `UninhabitedTupleStruct` defined here - --> $DIR/match_same_crate.rs:13:12 - | -LL | pub struct UninhabitedTupleStruct(!); - | ^^^^^^^^^^^^^^^^^^^^^^ - = note: the matched value is of type `UninhabitedTupleStruct` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown - | -LL ~ match x { -LL + _ => todo!(), -LL ~ } - | - -error[E0004]: non-exhaustive patterns: `UninhabitedVariants::Tuple(_)` and `UninhabitedVariants::Struct { .. }` not covered - --> $DIR/match_same_crate.rs:38:11 - | -LL | match x {} - | ^ patterns `UninhabitedVariants::Tuple(_)` and `UninhabitedVariants::Struct { .. }` not covered - | -note: `UninhabitedVariants` defined here - --> $DIR/match_same_crate.rs:15:10 - | -LL | pub enum UninhabitedVariants { - | ^^^^^^^^^^^^^^^^^^^ -LL | #[non_exhaustive] Tuple(!), - | ----- not covered -LL | #[non_exhaustive] Struct { x: ! } - | ------ not covered - = note: the matched value is of type `UninhabitedVariants` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms - | -LL ~ match x { -LL + UninhabitedVariants::Tuple(_) | UninhabitedVariants::Struct { .. } => todo!(), -LL ~ } - | - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0004`. diff --git a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/match_with_exhaustive_patterns.rs b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/match_with_exhaustive_patterns.rs index 69b15fca0b721..108cac7099ebf 100644 --- a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/match_with_exhaustive_patterns.rs +++ b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/match_with_exhaustive_patterns.rs @@ -1,6 +1,5 @@ //@ aux-build:uninhabited.rs #![deny(unreachable_patterns)] -#![feature(min_exhaustive_patterns)] #![feature(never_type)] extern crate uninhabited; diff --git a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/match_with_exhaustive_patterns.stderr b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/match_with_exhaustive_patterns.stderr index 19e2546b0da88..0c8b14ab69df0 100644 --- a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/match_with_exhaustive_patterns.stderr +++ b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/match_with_exhaustive_patterns.stderr @@ -1,5 +1,5 @@ error[E0004]: non-exhaustive patterns: type `UninhabitedEnum` is non-empty - --> $DIR/match_with_exhaustive_patterns.rs:22:11 + --> $DIR/match_with_exhaustive_patterns.rs:21:11 | LL | match x {} | ^ @@ -18,7 +18,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: type `UninhabitedStruct` is non-empty - --> $DIR/match_with_exhaustive_patterns.rs:26:11 + --> $DIR/match_with_exhaustive_patterns.rs:25:11 | LL | match x {} | ^ @@ -37,7 +37,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: type `UninhabitedTupleStruct` is non-empty - --> $DIR/match_with_exhaustive_patterns.rs:30:11 + --> $DIR/match_with_exhaustive_patterns.rs:29:11 | LL | match x {} | ^ @@ -56,7 +56,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: `UninhabitedVariants::Tuple(_)` and `UninhabitedVariants::Struct { .. }` not covered - --> $DIR/match_with_exhaustive_patterns.rs:34:11 + --> $DIR/match_with_exhaustive_patterns.rs:33:11 | LL | match x {} | ^ patterns `UninhabitedVariants::Tuple(_)` and `UninhabitedVariants::Struct { .. }` not covered diff --git a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/match_with_exhaustive_patterns_same_crate.rs b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/match_with_exhaustive_patterns_same_crate.rs index bbc5d03d6126c..468703c78e068 100644 --- a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/match_with_exhaustive_patterns_same_crate.rs +++ b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/match_with_exhaustive_patterns_same_crate.rs @@ -1,7 +1,6 @@ //@ check-pass #![deny(unreachable_patterns)] -#![feature(min_exhaustive_patterns)] #![feature(never_type)] #[non_exhaustive] diff --git a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/patterns.rs b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/patterns.rs index 0007614988cda..be55ad51578be 100644 --- a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/patterns.rs +++ b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/patterns.rs @@ -1,7 +1,6 @@ //@ aux-build:uninhabited.rs //@ build-pass (FIXME(62277): could be check-pass?) #![deny(unreachable_patterns)] -#![feature(min_exhaustive_patterns)] extern crate uninhabited; diff --git a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/patterns_same_crate.rs b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/patterns_same_crate.rs index 898be87cccab1..1194d7b858d60 100644 --- a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/patterns_same_crate.rs +++ b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/patterns_same_crate.rs @@ -1,5 +1,4 @@ #![deny(unreachable_patterns)] -#![feature(min_exhaustive_patterns)] #![feature(never_type)] #[non_exhaustive] diff --git a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/patterns_same_crate.stderr b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/patterns_same_crate.stderr index d5192a70ed550..c399bb9083fb1 100644 --- a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/patterns_same_crate.stderr +++ b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/patterns_same_crate.stderr @@ -1,5 +1,5 @@ error: unreachable pattern - --> $DIR/patterns_same_crate.rs:52:9 + --> $DIR/patterns_same_crate.rs:51:9 | LL | Some(_x) => (), | ^^^^^^^^ @@ -12,7 +12,7 @@ LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ error: unreachable pattern - --> $DIR/patterns_same_crate.rs:57:9 + --> $DIR/patterns_same_crate.rs:56:9 | LL | Some(_x) => (), | ^^^^^^^^ @@ -20,7 +20,7 @@ LL | Some(_x) => (), = note: this pattern matches no values because `UninhabitedVariants` is uninhabited error: unreachable pattern - --> $DIR/patterns_same_crate.rs:61:15 + --> $DIR/patterns_same_crate.rs:60:15 | LL | while let PartiallyInhabitedVariants::Struct { x } = partially_inhabited_variant() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -28,7 +28,7 @@ LL | while let PartiallyInhabitedVariants::Struct { x } = partially_inhabite = note: this pattern matches no values because `!` is uninhabited error: unreachable pattern - --> $DIR/patterns_same_crate.rs:65:15 + --> $DIR/patterns_same_crate.rs:64:15 | LL | while let Some(_x) = uninhabited_struct() { | ^^^^^^^^ @@ -36,7 +36,7 @@ LL | while let Some(_x) = uninhabited_struct() { = note: this pattern matches no values because `UninhabitedStruct` is uninhabited error: unreachable pattern - --> $DIR/patterns_same_crate.rs:68:15 + --> $DIR/patterns_same_crate.rs:67:15 | LL | while let Some(_x) = uninhabited_tuple_struct() { | ^^^^^^^^ diff --git a/tests/ui/try-trait/try-operator-custom.rs b/tests/ui/try-trait/try-operator-custom.rs index ab0772dd228b0..936c0b0689add 100644 --- a/tests/ui/try-trait/try-operator-custom.rs +++ b/tests/ui/try-trait/try-operator-custom.rs @@ -31,7 +31,6 @@ impl<U, V> Try for MyResult<U, V> { impl<U, V, W> FromResidual<MyResult<Never, V>> for MyResult<U, W> where V: Into<W> { fn from_residual(x: MyResult<Never, V>) -> Self { match x { - MyResult::Awesome(u) => match u {}, MyResult::Terrible(e) => MyResult::Terrible(e.into()), } } @@ -42,7 +41,6 @@ type ResultResidual<E> = Result<std::convert::Infallible, E>; impl<U, V, W> FromResidual<ResultResidual<V>> for MyResult<U, W> where V: Into<W> { fn from_residual(x: ResultResidual<V>) -> Self { match x { - Ok(v) => match v {} Err(e) => MyResult::Terrible(e.into()), } } @@ -51,7 +49,6 @@ impl<U, V, W> FromResidual<ResultResidual<V>> for MyResult<U, W> where V: Into<W impl<U, V, W> FromResidual<MyResult<Never, V>> for Result<U, W> where V: Into<W> { fn from_residual(x: MyResult<Never, V>) -> Self { match x { - MyResult::Awesome(u) => match u {}, MyResult::Terrible(e) => Err(e.into()), } } diff --git a/tests/ui/uninhabited/exhaustive-wo-nevertype-issue-51221.rs b/tests/ui/uninhabited/exhaustive-wo-nevertype-issue-51221.rs index 3130fb3fe9e67..722d9b4ed2929 100644 --- a/tests/ui/uninhabited/exhaustive-wo-nevertype-issue-51221.rs +++ b/tests/ui/uninhabited/exhaustive-wo-nevertype-issue-51221.rs @@ -1,7 +1,5 @@ //@ check-pass -#![feature(min_exhaustive_patterns)] - enum Void {} fn main() { let a: Option<Void> = None; diff --git a/tests/ui/uninhabited/uninhabited-irrefutable.exhaustive_patterns.stderr b/tests/ui/uninhabited/uninhabited-irrefutable.exhaustive_patterns.stderr index bc1a9fa41915a..50f33607c06f5 100644 --- a/tests/ui/uninhabited/uninhabited-irrefutable.exhaustive_patterns.stderr +++ b/tests/ui/uninhabited/uninhabited-irrefutable.exhaustive_patterns.stderr @@ -1,5 +1,5 @@ error[E0005]: refutable pattern in local binding - --> $DIR/uninhabited-irrefutable.rs:31:9 + --> $DIR/uninhabited-irrefutable.rs:30:9 | LL | let Foo::D(_y, _z) = x; | ^^^^^^^^^^^^^^ pattern `Foo::A(_)` not covered @@ -7,7 +7,7 @@ LL | let Foo::D(_y, _z) = x; = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html note: `Foo` defined here - --> $DIR/uninhabited-irrefutable.rs:20:6 + --> $DIR/uninhabited-irrefutable.rs:19:6 | LL | enum Foo { | ^^^ diff --git a/tests/ui/uninhabited/uninhabited-irrefutable.normal.stderr b/tests/ui/uninhabited/uninhabited-irrefutable.normal.stderr new file mode 100644 index 0000000000000..50f33607c06f5 --- /dev/null +++ b/tests/ui/uninhabited/uninhabited-irrefutable.normal.stderr @@ -0,0 +1,26 @@ +error[E0005]: refutable pattern in local binding + --> $DIR/uninhabited-irrefutable.rs:30:9 + | +LL | let Foo::D(_y, _z) = x; + | ^^^^^^^^^^^^^^ pattern `Foo::A(_)` not covered + | + = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant + = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html +note: `Foo` defined here + --> $DIR/uninhabited-irrefutable.rs:19:6 + | +LL | enum Foo { + | ^^^ +LL | +LL | A(foo::SecretlyEmpty), + | - not covered + = note: pattern `Foo::A(_)` is currently uninhabited, but this variant contains private fields which may become inhabited in the future + = note: the matched value is of type `Foo` +help: you might want to use `let else` to handle the variant that isn't matched + | +LL | let Foo::D(_y, _z) = x else { todo!() }; + | ++++++++++++++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0005`. diff --git a/tests/ui/uninhabited/uninhabited-irrefutable.rs b/tests/ui/uninhabited/uninhabited-irrefutable.rs index c1f4e5f8e27f1..cbaa989600331 100644 --- a/tests/ui/uninhabited/uninhabited-irrefutable.rs +++ b/tests/ui/uninhabited/uninhabited-irrefutable.rs @@ -1,6 +1,5 @@ -//@ revisions: min_exhaustive_patterns exhaustive_patterns +//@ revisions: normal exhaustive_patterns #![cfg_attr(exhaustive_patterns, feature(exhaustive_patterns))] -#![cfg_attr(min_exhaustive_patterns, feature(min_exhaustive_patterns))] #![feature(never_type)] mod foo { diff --git a/tests/ui/uninhabited/uninhabited-matches-feature-gated.rs b/tests/ui/uninhabited/uninhabited-matches-feature-gated.rs index e804afcf9ed99..1b158dd48e984 100644 --- a/tests/ui/uninhabited/uninhabited-matches-feature-gated.rs +++ b/tests/ui/uninhabited/uninhabited-matches-feature-gated.rs @@ -15,10 +15,10 @@ fn main() { let _ = match x {}; //~ ERROR non-exhaustive let x: (Void,) = unsafe { zeroed() }; - let _ = match x {}; //~ ERROR non-exhaustive + let _ = match x {}; let x: [Void; 1] = unsafe { zeroed() }; - let _ = match x {}; //~ ERROR non-exhaustive + let _ = match x {}; let x: &[Void] = unsafe { zeroed() }; let _ = match x { //~ ERROR non-exhaustive @@ -29,11 +29,10 @@ fn main() { let _ = match x {}; // okay let x: Result<u32, Void> = Ok(23); - let _ = match x { //~ ERROR non-exhaustive + let _ = match x { Ok(x) => x, }; let x: Result<u32, Void> = Ok(23); let Ok(x) = x; - //~^ ERROR refutable } diff --git a/tests/ui/uninhabited/uninhabited-matches-feature-gated.stderr b/tests/ui/uninhabited/uninhabited-matches-feature-gated.stderr index 466d7f2eadb92..2cd3c9375d0be 100644 --- a/tests/ui/uninhabited/uninhabited-matches-feature-gated.stderr +++ b/tests/ui/uninhabited/uninhabited-matches-feature-gated.stderr @@ -36,34 +36,6 @@ LL + _ => todo!(), LL ~ }; | -error[E0004]: non-exhaustive patterns: type `(Void,)` is non-empty - --> $DIR/uninhabited-matches-feature-gated.rs:18:19 - | -LL | let _ = match x {}; - | ^ - | - = note: the matched value is of type `(Void,)` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown - | -LL ~ let _ = match x { -LL + _ => todo!(), -LL ~ }; - | - -error[E0004]: non-exhaustive patterns: type `[Void; 1]` is non-empty - --> $DIR/uninhabited-matches-feature-gated.rs:21:19 - | -LL | let _ = match x {}; - | ^ - | - = note: the matched value is of type `[Void; 1]` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown - | -LL ~ let _ = match x { -LL + _ => todo!(), -LL ~ }; - | - error[E0004]: non-exhaustive patterns: `&[_, ..]` not covered --> $DIR/uninhabited-matches-feature-gated.rs:24:19 | @@ -71,45 +43,13 @@ LL | let _ = match x { | ^ pattern `&[_, ..]` not covered | = note: the matched value is of type `&[Void]` + = note: `Void` is uninhabited but is not being matched by value, so a wildcard `_` is required help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ &[] => (), LL ~ &[_, ..] => todo!(), | -error[E0004]: non-exhaustive patterns: `Err(_)` not covered - --> $DIR/uninhabited-matches-feature-gated.rs:32:19 - | -LL | let _ = match x { - | ^ pattern `Err(_)` not covered - | -note: `Result<u32, Void>` defined here - --> $SRC_DIR/core/src/result.rs:LL:COL - ::: $SRC_DIR/core/src/result.rs:LL:COL - | - = note: not covered - = note: the matched value is of type `Result<u32, Void>` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown - | -LL ~ Ok(x) => x, -LL ~ Err(_) => todo!(), - | - -error[E0005]: refutable pattern in local binding - --> $DIR/uninhabited-matches-feature-gated.rs:37:9 - | -LL | let Ok(x) = x; - | ^^^^^ pattern `Err(_)` not covered - | - = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant - = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html - = note: the matched value is of type `Result<u32, Void>` -help: you might want to use `let else` to handle the variant that isn't matched - | -LL | let Ok(x) = x else { todo!() }; - | ++++++++++++++++ - -error: aborting due to 7 previous errors +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0004, E0005. -For more information about an error, try `rustc --explain E0004`. +For more information about this error, try `rustc --explain E0004`. diff --git a/tests/ui/uninhabited/uninhabited-patterns.rs b/tests/ui/uninhabited/uninhabited-patterns.rs index ae12c0fc4af68..988383e691b4e 100644 --- a/tests/ui/uninhabited/uninhabited-patterns.rs +++ b/tests/ui/uninhabited/uninhabited-patterns.rs @@ -1,6 +1,5 @@ #![feature(box_patterns)] #![feature(never_type)] -#![feature(min_exhaustive_patterns)] #![deny(unreachable_patterns)] mod foo { diff --git a/tests/ui/uninhabited/uninhabited-patterns.stderr b/tests/ui/uninhabited/uninhabited-patterns.stderr index ca62386d7ef02..4e4aaa93f8044 100644 --- a/tests/ui/uninhabited/uninhabited-patterns.stderr +++ b/tests/ui/uninhabited/uninhabited-patterns.stderr @@ -1,18 +1,18 @@ error: unreachable pattern - --> $DIR/uninhabited-patterns.rs:30:9 + --> $DIR/uninhabited-patterns.rs:29:9 | LL | Ok(box _) => (), | ^^^^^^^^^ | = note: this pattern matches no values because `NotSoSecretlyEmpty` is uninhabited note: the lint level is defined here - --> $DIR/uninhabited-patterns.rs:4:9 + --> $DIR/uninhabited-patterns.rs:3:9 | LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ error: unreachable pattern - --> $DIR/uninhabited-patterns.rs:39:9 + --> $DIR/uninhabited-patterns.rs:38:9 | LL | Err(Ok(_y)) => (), | ^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL | Err(Ok(_y)) => (), = note: this pattern matches no values because `NotSoSecretlyEmpty` is uninhabited error: unreachable pattern - --> $DIR/uninhabited-patterns.rs:42:15 + --> $DIR/uninhabited-patterns.rs:41:15 | LL | while let Some(_y) = foo() { | ^^^^^^^^ From d0601daf86bc71a445c98d0fafb2e4515944722f Mon Sep 17 00:00:00 2001 From: Nadrieril <nadrieril+git@gmail.com> Date: Wed, 20 Mar 2024 19:49:20 +0100 Subject: [PATCH 3/5] Update std and compiler --- compiler/rustc_errors/src/diagnostic_impls.rs | 1 + compiler/rustc_middle/src/lib.rs | 2 +- compiler/rustc_target/src/lib.rs | 2 +- compiler/rustc_transmute/src/layout/nfa.rs | 1 + compiler/rustc_type_ir/src/fold.rs | 2 ++ library/core/src/lib.rs | 2 +- library/std/src/lib.rs | 2 +- 7 files changed, 8 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_errors/src/diagnostic_impls.rs b/compiler/rustc_errors/src/diagnostic_impls.rs index 3e22786a01f7a..9e3bc3e60b12f 100644 --- a/compiler/rustc_errors/src/diagnostic_impls.rs +++ b/compiler/rustc_errors/src/diagnostic_impls.rs @@ -66,6 +66,7 @@ macro_rules! into_diag_arg_for_number { impl IntoDiagArg for $ty { fn into_diag_arg(self) -> DiagArgValue { // Convert to a string if it won't fit into `Number`. + #[allow(irrefutable_let_patterns)] if let Ok(n) = TryInto::<i32>::try_into(self) { DiagArgValue::Number(n) } else { diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index b499604df87e8..5bd7736a3f3cc 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -28,6 +28,7 @@ #![allow(rustc::diagnostic_outside_of_impl)] #![allow(rustc::potential_query_instability)] #![allow(rustc::untranslatable_diagnostic)] +#![cfg_attr(bootstrap, feature(min_exhaustive_patterns))] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(rust_logo)] #![feature(allocator_api)] @@ -48,7 +49,6 @@ #![feature(iter_from_coroutine)] #![feature(let_chains)] #![feature(macro_metavar_expr)] -#![feature(min_exhaustive_patterns)] #![feature(min_specialization)] #![feature(negative_impls)] #![feature(never_type)] diff --git a/compiler/rustc_target/src/lib.rs b/compiler/rustc_target/src/lib.rs index ecc91ab9a310e..b2116c5121695 100644 --- a/compiler/rustc_target/src/lib.rs +++ b/compiler/rustc_target/src/lib.rs @@ -9,12 +9,12 @@ // tidy-alphabetical-start #![allow(internal_features)] +#![cfg_attr(bootstrap, feature(min_exhaustive_patterns))] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(rust_logo)] #![feature(assert_matches)] #![feature(iter_intersperse)] #![feature(let_chains)] -#![feature(min_exhaustive_patterns)] #![feature(rustc_attrs)] #![feature(rustdoc_internals)] // tidy-alphabetical-end diff --git a/compiler/rustc_transmute/src/layout/nfa.rs b/compiler/rustc_transmute/src/layout/nfa.rs index 0dd26badc885f..5db5a8f222db0 100644 --- a/compiler/rustc_transmute/src/layout/nfa.rs +++ b/compiler/rustc_transmute/src/layout/nfa.rs @@ -87,6 +87,7 @@ where pub(crate) fn from_tree(tree: Tree<!, R>) -> Result<Self, Uninhabited> { Ok(match tree { Tree::Byte(b) => Self::from_byte(b), + #[cfg(bootstrap)] Tree::Def(..) => unreachable!(), Tree::Ref(r) => Self::from_ref(r), Tree::Alt(alts) => { diff --git a/compiler/rustc_type_ir/src/fold.rs b/compiler/rustc_type_ir/src/fold.rs index 16dcf76e73eb8..d37bacc7d359f 100644 --- a/compiler/rustc_type_ir/src/fold.rs +++ b/compiler/rustc_type_ir/src/fold.rs @@ -91,6 +91,7 @@ pub trait TypeFoldable<I: Interner>: TypeVisitable<I> { fn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self { match self.try_fold_with(folder) { Ok(t) => t, + #[cfg(bootstrap)] Err(e) => match e {}, } } @@ -115,6 +116,7 @@ pub trait TypeSuperFoldable<I: Interner>: TypeFoldable<I> { fn super_fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self { match self.try_super_fold_with(folder) { Ok(t) => t, + #[cfg(bootstrap)] Err(e) => match e {}, } } diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index e74900ff7471b..514ae6f30cffd 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -192,6 +192,7 @@ // // Language features: // tidy-alphabetical-start +#![cfg_attr(bootstrap, feature(min_exhaustive_patterns))] #![feature(abi_unadjusted)] #![feature(adt_const_params)] #![feature(allow_internal_unsafe)] @@ -225,7 +226,6 @@ #![feature(link_llvm_intrinsics)] #![feature(macro_metavar_expr)] #![feature(marker_trait_attr)] -#![feature(min_exhaustive_patterns)] #![feature(min_specialization)] #![feature(multiple_supertrait_upcastable)] #![feature(must_not_suspend)] diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 05e33d47bac39..321d91cf380f0 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -272,6 +272,7 @@ // // Language features: // tidy-alphabetical-start +#![cfg_attr(bootstrap, feature(min_exhaustive_patterns))] #![feature(alloc_error_handler)] #![feature(allocator_internals)] #![feature(allow_internal_unsafe)] @@ -299,7 +300,6 @@ #![feature(link_cfg)] #![feature(linkage)] #![feature(macro_metavar_expr_concat)] -#![feature(min_exhaustive_patterns)] #![feature(min_specialization)] #![feature(must_not_suspend)] #![feature(needs_panic_runtime)] From a1d0cdb2d63a224920c91c0bfe14d70aa2b76248 Mon Sep 17 00:00:00 2001 From: Nadrieril <nadrieril+git@gmail.com> Date: Sat, 30 Mar 2024 12:21:59 +0100 Subject: [PATCH 4/5] Test that 0/unknown-length arrays are nonempty --- .../empty-match.exhaustive_patterns.stderr | 92 ++++++++++++++----- .../usefulness/empty-match.normal.stderr | 92 ++++++++++++++----- tests/ui/pattern/usefulness/empty-match.rs | 7 +- 3 files changed, 144 insertions(+), 47 deletions(-) diff --git a/tests/ui/pattern/usefulness/empty-match.exhaustive_patterns.stderr b/tests/ui/pattern/usefulness/empty-match.exhaustive_patterns.stderr index bc12327a1b2a3..f2067f0341fcd 100644 --- a/tests/ui/pattern/usefulness/empty-match.exhaustive_patterns.stderr +++ b/tests/ui/pattern/usefulness/empty-match.exhaustive_patterns.stderr @@ -1,5 +1,5 @@ error[E0004]: non-exhaustive patterns: type `u8` is non-empty - --> $DIR/empty-match.rs:46:20 + --> $DIR/empty-match.rs:47:20 | LL | match_no_arms!(0u8); | ^^^ @@ -8,7 +8,7 @@ LL | match_no_arms!(0u8); = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern error[E0004]: non-exhaustive patterns: type `i8` is non-empty - --> $DIR/empty-match.rs:47:20 + --> $DIR/empty-match.rs:48:20 | LL | match_no_arms!(0i8); | ^^^ @@ -17,7 +17,7 @@ LL | match_no_arms!(0i8); = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern error[E0004]: non-exhaustive patterns: type `usize` is non-empty - --> $DIR/empty-match.rs:48:20 + --> $DIR/empty-match.rs:49:20 | LL | match_no_arms!(0usize); | ^^^^^^ @@ -26,7 +26,7 @@ LL | match_no_arms!(0usize); = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern error[E0004]: non-exhaustive patterns: type `isize` is non-empty - --> $DIR/empty-match.rs:49:20 + --> $DIR/empty-match.rs:50:20 | LL | match_no_arms!(0isize); | ^^^^^^ @@ -35,7 +35,7 @@ LL | match_no_arms!(0isize); = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern error[E0004]: non-exhaustive patterns: type `NonEmptyStruct1` is non-empty - --> $DIR/empty-match.rs:50:20 + --> $DIR/empty-match.rs:51:20 | LL | match_no_arms!(NonEmptyStruct1); | ^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | struct NonEmptyStruct1; = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern error[E0004]: non-exhaustive patterns: type `NonEmptyStruct2` is non-empty - --> $DIR/empty-match.rs:51:20 + --> $DIR/empty-match.rs:52:20 | LL | match_no_arms!(NonEmptyStruct2(true)); | ^^^^^^^^^^^^^^^^^^^^^ @@ -63,7 +63,7 @@ LL | struct NonEmptyStruct2(bool); = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty - --> $DIR/empty-match.rs:52:20 + --> $DIR/empty-match.rs:53:20 | LL | match_no_arms!((NonEmptyUnion1 { foo: () })); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -77,7 +77,7 @@ LL | union NonEmptyUnion1 { = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty - --> $DIR/empty-match.rs:53:20 + --> $DIR/empty-match.rs:54:20 | LL | match_no_arms!((NonEmptyUnion2 { foo: () })); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -91,7 +91,7 @@ LL | union NonEmptyUnion2 { = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern error[E0004]: non-exhaustive patterns: `NonEmptyEnum1::Foo(_)` not covered - --> $DIR/empty-match.rs:54:20 + --> $DIR/empty-match.rs:55:20 | LL | match_no_arms!(NonEmptyEnum1::Foo(true)); | ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered @@ -107,7 +107,7 @@ LL | Foo(bool), = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern error[E0004]: non-exhaustive patterns: `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered - --> $DIR/empty-match.rs:55:20 + --> $DIR/empty-match.rs:56:20 | LL | match_no_arms!(NonEmptyEnum2::Foo(true)); | ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered @@ -125,7 +125,7 @@ LL | Bar, = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms error[E0004]: non-exhaustive patterns: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered - --> $DIR/empty-match.rs:56:20 + --> $DIR/empty-match.rs:57:20 | LL | match_no_arms!(NonEmptyEnum5::V1); | ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered @@ -148,8 +148,26 @@ LL | V5, = note: the matched value is of type `NonEmptyEnum5` = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms +error[E0004]: non-exhaustive patterns: type `[!; 0]` is non-empty + --> $DIR/empty-match.rs:58:20 + | +LL | match_no_arms!(array0_of_empty); + | ^^^^^^^^^^^^^^^ + | + = note: the matched value is of type `[!; 0]` + = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern + +error[E0004]: non-exhaustive patterns: type `[!; N]` is non-empty + --> $DIR/empty-match.rs:59:20 + | +LL | match_no_arms!(arrayN_of_empty); + | ^^^^^^^^^^^^^^^ + | + = note: the matched value is of type `[!; N]` + = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern + error[E0004]: non-exhaustive patterns: `0_u8..=u8::MAX` not covered - --> $DIR/empty-match.rs:58:24 + --> $DIR/empty-match.rs:61:24 | LL | match_guarded_arm!(0u8); | ^^^ pattern `0_u8..=u8::MAX` not covered @@ -163,7 +181,7 @@ LL + 0_u8..=u8::MAX => todo!() | error[E0004]: non-exhaustive patterns: `i8::MIN..=i8::MAX` not covered - --> $DIR/empty-match.rs:59:24 + --> $DIR/empty-match.rs:62:24 | LL | match_guarded_arm!(0i8); | ^^^ pattern `i8::MIN..=i8::MAX` not covered @@ -177,7 +195,7 @@ LL + i8::MIN..=i8::MAX => todo!() | error[E0004]: non-exhaustive patterns: `0_usize..` not covered - --> $DIR/empty-match.rs:60:24 + --> $DIR/empty-match.rs:63:24 | LL | match_guarded_arm!(0usize); | ^^^^^^ pattern `0_usize..` not covered @@ -191,7 +209,7 @@ LL + 0_usize.. => todo!() | error[E0004]: non-exhaustive patterns: `_` not covered - --> $DIR/empty-match.rs:61:24 + --> $DIR/empty-match.rs:64:24 | LL | match_guarded_arm!(0isize); | ^^^^^^ pattern `_` not covered @@ -205,7 +223,7 @@ LL + _ => todo!() | error[E0004]: non-exhaustive patterns: `NonEmptyStruct1` not covered - --> $DIR/empty-match.rs:62:24 + --> $DIR/empty-match.rs:65:24 | LL | match_guarded_arm!(NonEmptyStruct1); | ^^^^^^^^^^^^^^^ pattern `NonEmptyStruct1` not covered @@ -224,7 +242,7 @@ LL + NonEmptyStruct1 => todo!() | error[E0004]: non-exhaustive patterns: `NonEmptyStruct2(_)` not covered - --> $DIR/empty-match.rs:63:24 + --> $DIR/empty-match.rs:66:24 | LL | match_guarded_arm!(NonEmptyStruct2(true)); | ^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyStruct2(_)` not covered @@ -243,7 +261,7 @@ LL + NonEmptyStruct2(_) => todo!() | error[E0004]: non-exhaustive patterns: `NonEmptyUnion1 { .. }` not covered - --> $DIR/empty-match.rs:64:24 + --> $DIR/empty-match.rs:67:24 | LL | match_guarded_arm!((NonEmptyUnion1 { foo: () })); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion1 { .. }` not covered @@ -262,7 +280,7 @@ LL + NonEmptyUnion1 { .. } => todo!() | error[E0004]: non-exhaustive patterns: `NonEmptyUnion2 { .. }` not covered - --> $DIR/empty-match.rs:65:24 + --> $DIR/empty-match.rs:68:24 | LL | match_guarded_arm!((NonEmptyUnion2 { foo: () })); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion2 { .. }` not covered @@ -282,7 +300,7 @@ LL + NonEmptyUnion2 { .. } => todo!() | error[E0004]: non-exhaustive patterns: `NonEmptyEnum1::Foo(_)` not covered - --> $DIR/empty-match.rs:66:24 + --> $DIR/empty-match.rs:69:24 | LL | match_guarded_arm!(NonEmptyEnum1::Foo(true)); | ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered @@ -303,7 +321,7 @@ LL + NonEmptyEnum1::Foo(_) => todo!() | error[E0004]: non-exhaustive patterns: `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered - --> $DIR/empty-match.rs:67:24 + --> $DIR/empty-match.rs:70:24 | LL | match_guarded_arm!(NonEmptyEnum2::Foo(true)); | ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered @@ -326,7 +344,7 @@ LL + NonEmptyEnum2::Foo(_) | NonEmptyEnum2::Bar => todo!() | error[E0004]: non-exhaustive patterns: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered - --> $DIR/empty-match.rs:68:24 + --> $DIR/empty-match.rs:71:24 | LL | match_guarded_arm!(NonEmptyEnum5::V1); | ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered @@ -354,6 +372,34 @@ LL ~ _ if false => {}, LL + _ => todo!() | -error: aborting due to 22 previous errors +error[E0004]: non-exhaustive patterns: `[]` not covered + --> $DIR/empty-match.rs:72:24 + | +LL | match_guarded_arm!(array0_of_empty); + | ^^^^^^^^^^^^^^^ pattern `[]` not covered + | + = note: the matched value is of type `[!; 0]` + = note: match arms with guards don't count towards exhaustivity +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ _ if false => {}, +LL + [] => todo!() + | + +error[E0004]: non-exhaustive patterns: `[]` not covered + --> $DIR/empty-match.rs:73:24 + | +LL | match_guarded_arm!(arrayN_of_empty); + | ^^^^^^^^^^^^^^^ pattern `[]` not covered + | + = note: the matched value is of type `[!; N]` + = note: match arms with guards don't count towards exhaustivity +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ _ if false => {}, +LL + [] => todo!() + | + +error: aborting due to 26 previous errors For more information about this error, try `rustc --explain E0004`. diff --git a/tests/ui/pattern/usefulness/empty-match.normal.stderr b/tests/ui/pattern/usefulness/empty-match.normal.stderr index bc12327a1b2a3..f2067f0341fcd 100644 --- a/tests/ui/pattern/usefulness/empty-match.normal.stderr +++ b/tests/ui/pattern/usefulness/empty-match.normal.stderr @@ -1,5 +1,5 @@ error[E0004]: non-exhaustive patterns: type `u8` is non-empty - --> $DIR/empty-match.rs:46:20 + --> $DIR/empty-match.rs:47:20 | LL | match_no_arms!(0u8); | ^^^ @@ -8,7 +8,7 @@ LL | match_no_arms!(0u8); = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern error[E0004]: non-exhaustive patterns: type `i8` is non-empty - --> $DIR/empty-match.rs:47:20 + --> $DIR/empty-match.rs:48:20 | LL | match_no_arms!(0i8); | ^^^ @@ -17,7 +17,7 @@ LL | match_no_arms!(0i8); = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern error[E0004]: non-exhaustive patterns: type `usize` is non-empty - --> $DIR/empty-match.rs:48:20 + --> $DIR/empty-match.rs:49:20 | LL | match_no_arms!(0usize); | ^^^^^^ @@ -26,7 +26,7 @@ LL | match_no_arms!(0usize); = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern error[E0004]: non-exhaustive patterns: type `isize` is non-empty - --> $DIR/empty-match.rs:49:20 + --> $DIR/empty-match.rs:50:20 | LL | match_no_arms!(0isize); | ^^^^^^ @@ -35,7 +35,7 @@ LL | match_no_arms!(0isize); = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern error[E0004]: non-exhaustive patterns: type `NonEmptyStruct1` is non-empty - --> $DIR/empty-match.rs:50:20 + --> $DIR/empty-match.rs:51:20 | LL | match_no_arms!(NonEmptyStruct1); | ^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | struct NonEmptyStruct1; = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern error[E0004]: non-exhaustive patterns: type `NonEmptyStruct2` is non-empty - --> $DIR/empty-match.rs:51:20 + --> $DIR/empty-match.rs:52:20 | LL | match_no_arms!(NonEmptyStruct2(true)); | ^^^^^^^^^^^^^^^^^^^^^ @@ -63,7 +63,7 @@ LL | struct NonEmptyStruct2(bool); = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty - --> $DIR/empty-match.rs:52:20 + --> $DIR/empty-match.rs:53:20 | LL | match_no_arms!((NonEmptyUnion1 { foo: () })); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -77,7 +77,7 @@ LL | union NonEmptyUnion1 { = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty - --> $DIR/empty-match.rs:53:20 + --> $DIR/empty-match.rs:54:20 | LL | match_no_arms!((NonEmptyUnion2 { foo: () })); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -91,7 +91,7 @@ LL | union NonEmptyUnion2 { = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern error[E0004]: non-exhaustive patterns: `NonEmptyEnum1::Foo(_)` not covered - --> $DIR/empty-match.rs:54:20 + --> $DIR/empty-match.rs:55:20 | LL | match_no_arms!(NonEmptyEnum1::Foo(true)); | ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered @@ -107,7 +107,7 @@ LL | Foo(bool), = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern error[E0004]: non-exhaustive patterns: `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered - --> $DIR/empty-match.rs:55:20 + --> $DIR/empty-match.rs:56:20 | LL | match_no_arms!(NonEmptyEnum2::Foo(true)); | ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered @@ -125,7 +125,7 @@ LL | Bar, = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms error[E0004]: non-exhaustive patterns: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered - --> $DIR/empty-match.rs:56:20 + --> $DIR/empty-match.rs:57:20 | LL | match_no_arms!(NonEmptyEnum5::V1); | ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered @@ -148,8 +148,26 @@ LL | V5, = note: the matched value is of type `NonEmptyEnum5` = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms +error[E0004]: non-exhaustive patterns: type `[!; 0]` is non-empty + --> $DIR/empty-match.rs:58:20 + | +LL | match_no_arms!(array0_of_empty); + | ^^^^^^^^^^^^^^^ + | + = note: the matched value is of type `[!; 0]` + = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern + +error[E0004]: non-exhaustive patterns: type `[!; N]` is non-empty + --> $DIR/empty-match.rs:59:20 + | +LL | match_no_arms!(arrayN_of_empty); + | ^^^^^^^^^^^^^^^ + | + = note: the matched value is of type `[!; N]` + = help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern + error[E0004]: non-exhaustive patterns: `0_u8..=u8::MAX` not covered - --> $DIR/empty-match.rs:58:24 + --> $DIR/empty-match.rs:61:24 | LL | match_guarded_arm!(0u8); | ^^^ pattern `0_u8..=u8::MAX` not covered @@ -163,7 +181,7 @@ LL + 0_u8..=u8::MAX => todo!() | error[E0004]: non-exhaustive patterns: `i8::MIN..=i8::MAX` not covered - --> $DIR/empty-match.rs:59:24 + --> $DIR/empty-match.rs:62:24 | LL | match_guarded_arm!(0i8); | ^^^ pattern `i8::MIN..=i8::MAX` not covered @@ -177,7 +195,7 @@ LL + i8::MIN..=i8::MAX => todo!() | error[E0004]: non-exhaustive patterns: `0_usize..` not covered - --> $DIR/empty-match.rs:60:24 + --> $DIR/empty-match.rs:63:24 | LL | match_guarded_arm!(0usize); | ^^^^^^ pattern `0_usize..` not covered @@ -191,7 +209,7 @@ LL + 0_usize.. => todo!() | error[E0004]: non-exhaustive patterns: `_` not covered - --> $DIR/empty-match.rs:61:24 + --> $DIR/empty-match.rs:64:24 | LL | match_guarded_arm!(0isize); | ^^^^^^ pattern `_` not covered @@ -205,7 +223,7 @@ LL + _ => todo!() | error[E0004]: non-exhaustive patterns: `NonEmptyStruct1` not covered - --> $DIR/empty-match.rs:62:24 + --> $DIR/empty-match.rs:65:24 | LL | match_guarded_arm!(NonEmptyStruct1); | ^^^^^^^^^^^^^^^ pattern `NonEmptyStruct1` not covered @@ -224,7 +242,7 @@ LL + NonEmptyStruct1 => todo!() | error[E0004]: non-exhaustive patterns: `NonEmptyStruct2(_)` not covered - --> $DIR/empty-match.rs:63:24 + --> $DIR/empty-match.rs:66:24 | LL | match_guarded_arm!(NonEmptyStruct2(true)); | ^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyStruct2(_)` not covered @@ -243,7 +261,7 @@ LL + NonEmptyStruct2(_) => todo!() | error[E0004]: non-exhaustive patterns: `NonEmptyUnion1 { .. }` not covered - --> $DIR/empty-match.rs:64:24 + --> $DIR/empty-match.rs:67:24 | LL | match_guarded_arm!((NonEmptyUnion1 { foo: () })); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion1 { .. }` not covered @@ -262,7 +280,7 @@ LL + NonEmptyUnion1 { .. } => todo!() | error[E0004]: non-exhaustive patterns: `NonEmptyUnion2 { .. }` not covered - --> $DIR/empty-match.rs:65:24 + --> $DIR/empty-match.rs:68:24 | LL | match_guarded_arm!((NonEmptyUnion2 { foo: () })); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion2 { .. }` not covered @@ -282,7 +300,7 @@ LL + NonEmptyUnion2 { .. } => todo!() | error[E0004]: non-exhaustive patterns: `NonEmptyEnum1::Foo(_)` not covered - --> $DIR/empty-match.rs:66:24 + --> $DIR/empty-match.rs:69:24 | LL | match_guarded_arm!(NonEmptyEnum1::Foo(true)); | ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered @@ -303,7 +321,7 @@ LL + NonEmptyEnum1::Foo(_) => todo!() | error[E0004]: non-exhaustive patterns: `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered - --> $DIR/empty-match.rs:67:24 + --> $DIR/empty-match.rs:70:24 | LL | match_guarded_arm!(NonEmptyEnum2::Foo(true)); | ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered @@ -326,7 +344,7 @@ LL + NonEmptyEnum2::Foo(_) | NonEmptyEnum2::Bar => todo!() | error[E0004]: non-exhaustive patterns: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered - --> $DIR/empty-match.rs:68:24 + --> $DIR/empty-match.rs:71:24 | LL | match_guarded_arm!(NonEmptyEnum5::V1); | ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered @@ -354,6 +372,34 @@ LL ~ _ if false => {}, LL + _ => todo!() | -error: aborting due to 22 previous errors +error[E0004]: non-exhaustive patterns: `[]` not covered + --> $DIR/empty-match.rs:72:24 + | +LL | match_guarded_arm!(array0_of_empty); + | ^^^^^^^^^^^^^^^ pattern `[]` not covered + | + = note: the matched value is of type `[!; 0]` + = note: match arms with guards don't count towards exhaustivity +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ _ if false => {}, +LL + [] => todo!() + | + +error[E0004]: non-exhaustive patterns: `[]` not covered + --> $DIR/empty-match.rs:73:24 + | +LL | match_guarded_arm!(arrayN_of_empty); + | ^^^^^^^^^^^^^^^ pattern `[]` not covered + | + = note: the matched value is of type `[!; N]` + = note: match arms with guards don't count towards exhaustivity +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ _ if false => {}, +LL + [] => todo!() + | + +error: aborting due to 26 previous errors For more information about this error, try `rustc --explain E0004`. diff --git a/tests/ui/pattern/usefulness/empty-match.rs b/tests/ui/pattern/usefulness/empty-match.rs index 9b22b47a12b1f..b34427a7c2388 100644 --- a/tests/ui/pattern/usefulness/empty-match.rs +++ b/tests/ui/pattern/usefulness/empty-match.rs @@ -5,7 +5,7 @@ #![cfg_attr(exhaustive_patterns, feature(exhaustive_patterns))] #![deny(unreachable_patterns)] -fn nonempty() { +fn nonempty<const N: usize>(arrayN_of_empty: [!; N]) { macro_rules! match_no_arms { ($e:expr) => { match $e {} @@ -42,6 +42,7 @@ fn nonempty() { V4, V5, } + let array0_of_empty: [!; 0] = []; match_no_arms!(0u8); //~ ERROR type `u8` is non-empty match_no_arms!(0i8); //~ ERROR type `i8` is non-empty @@ -54,6 +55,8 @@ fn nonempty() { match_no_arms!(NonEmptyEnum1::Foo(true)); //~ ERROR `NonEmptyEnum1::Foo(_)` not covered match_no_arms!(NonEmptyEnum2::Foo(true)); //~ ERROR `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered match_no_arms!(NonEmptyEnum5::V1); //~ ERROR `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered + match_no_arms!(array0_of_empty); //~ ERROR type `[!; 0]` is non-empty + match_no_arms!(arrayN_of_empty); //~ ERROR type `[!; N]` is non-empty match_guarded_arm!(0u8); //~ ERROR `0_u8..=u8::MAX` not covered match_guarded_arm!(0i8); //~ ERROR `i8::MIN..=i8::MAX` not covered @@ -66,6 +69,8 @@ fn nonempty() { match_guarded_arm!(NonEmptyEnum1::Foo(true)); //~ ERROR `NonEmptyEnum1::Foo(_)` not covered match_guarded_arm!(NonEmptyEnum2::Foo(true)); //~ ERROR `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered match_guarded_arm!(NonEmptyEnum5::V1); //~ ERROR `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered + match_guarded_arm!(array0_of_empty); //~ ERROR `[]` not covered + match_guarded_arm!(arrayN_of_empty); //~ ERROR `[]` not covered } fn main() {} From 48c7ebe6ecfb16f9d17658eb53fe69e1b133f7d1 Mon Sep 17 00:00:00 2001 From: Nadrieril <nadrieril+git@gmail.com> Date: Wed, 20 Mar 2024 22:51:29 +0100 Subject: [PATCH 5/5] Fixes in various places --- .../rustc_codegen_cranelift/example/mini_core_hello_world.rs | 1 + compiler/rustc_codegen_gcc/example/mini_core_hello_world.rs | 1 + src/tools/clippy/clippy_utils/src/lib.rs | 1 + src/tools/clippy/tests/ui/single_match_else.fixed | 2 +- src/tools/clippy/tests/ui/single_match_else.rs | 2 +- src/tools/clippy/tests/ui/single_match_else.stderr | 4 ++-- src/tools/miri/src/eval.rs | 1 + src/tools/miri/tests/pass/async-fn.rs | 1 + src/tools/miri/tests/pass/enums.rs | 1 + 9 files changed, 10 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs b/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs index 7d361a9ab2bb6..e603ac566f4ec 100644 --- a/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs +++ b/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs @@ -585,6 +585,7 @@ pub enum E2<X> { V4, } +#[allow(unreachable_patterns)] fn check_niche_behavior() { if let E1::V2 { .. } = (E1::V1 { f: true }) { intrinsics::abort(); diff --git a/compiler/rustc_codegen_gcc/example/mini_core_hello_world.rs b/compiler/rustc_codegen_gcc/example/mini_core_hello_world.rs index 5a7ddc4cd7fa5..9f096e9022012 100644 --- a/compiler/rustc_codegen_gcc/example/mini_core_hello_world.rs +++ b/compiler/rustc_codegen_gcc/example/mini_core_hello_world.rs @@ -430,6 +430,7 @@ pub enum E2<X> { V4, } +#[allow(unreachable_patterns)] fn check_niche_behavior () { if let E1::V2 { .. } = (E1::V1 { f: true }) { intrinsics::abort(); diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index 1d5f1a2a2bb13..163e70f9fe54a 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -2927,6 +2927,7 @@ pub fn expr_use_ctxt<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> ExprU moved_before_use, same_ctxt, }, + #[allow(unreachable_patterns)] Some(ControlFlow::Break(_)) => unreachable!("type of node is ControlFlow<!>"), None => ExprUseCtxt { node: Node::Crate(cx.tcx.hir().root_module()), diff --git a/src/tools/clippy/tests/ui/single_match_else.fixed b/src/tools/clippy/tests/ui/single_match_else.fixed index e840adf0fa34b..163be16ad8be7 100644 --- a/src/tools/clippy/tests/ui/single_match_else.fixed +++ b/src/tools/clippy/tests/ui/single_match_else.fixed @@ -89,7 +89,7 @@ fn main() { // lint here use std::convert::Infallible; - if let Ok(a) = Result::<i32, Infallible>::Ok(1) { println!("${:?}", a) } else { + if let Ok(a) = Result::<i32, &Infallible>::Ok(1) { println!("${:?}", a) } else { println!("else block"); return; } diff --git a/src/tools/clippy/tests/ui/single_match_else.rs b/src/tools/clippy/tests/ui/single_match_else.rs index 430c4da20f12a..3f1fd2b31832f 100644 --- a/src/tools/clippy/tests/ui/single_match_else.rs +++ b/src/tools/clippy/tests/ui/single_match_else.rs @@ -98,7 +98,7 @@ fn main() { // lint here use std::convert::Infallible; - match Result::<i32, Infallible>::Ok(1) { + match Result::<i32, &Infallible>::Ok(1) { Ok(a) => println!("${:?}", a), Err(_) => { println!("else block"); diff --git a/src/tools/clippy/tests/ui/single_match_else.stderr b/src/tools/clippy/tests/ui/single_match_else.stderr index f8f88379d6d12..61c348260d05e 100644 --- a/src/tools/clippy/tests/ui/single_match_else.stderr +++ b/src/tools/clippy/tests/ui/single_match_else.stderr @@ -64,7 +64,7 @@ LL + } error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> tests/ui/single_match_else.rs:101:5 | -LL | / match Result::<i32, Infallible>::Ok(1) { +LL | / match Result::<i32, &Infallible>::Ok(1) { LL | | Ok(a) => println!("${:?}", a), LL | | Err(_) => { LL | | println!("else block"); @@ -75,7 +75,7 @@ LL | | } | help: try | -LL ~ if let Ok(a) = Result::<i32, Infallible>::Ok(1) { println!("${:?}", a) } else { +LL ~ if let Ok(a) = Result::<i32, &Infallible>::Ok(1) { println!("${:?}", a) } else { LL + println!("else block"); LL + return; LL + } diff --git a/src/tools/miri/src/eval.rs b/src/tools/miri/src/eval.rs index 53e877517089c..b5d13e9b32479 100644 --- a/src/tools/miri/src/eval.rs +++ b/src/tools/miri/src/eval.rs @@ -460,6 +460,7 @@ pub fn eval_entry<'tcx>( let res = match res { Err(res) => res, // `Ok` can never happen + #[cfg(bootstrap)] Ok(never) => match never {}, }; diff --git a/src/tools/miri/tests/pass/async-fn.rs b/src/tools/miri/tests/pass/async-fn.rs index 13400c88c7112..67ec2e26b3068 100644 --- a/src/tools/miri/tests/pass/async-fn.rs +++ b/src/tools/miri/tests/pass/async-fn.rs @@ -59,6 +59,7 @@ async fn hello_world() { } // This example comes from https://github.com/rust-lang/rust/issues/115145 +#[allow(unreachable_patterns)] async fn uninhabited_variant() { async fn unreachable(_: Never) {} diff --git a/src/tools/miri/tests/pass/enums.rs b/src/tools/miri/tests/pass/enums.rs index ac7aafc1bb2e3..1dafef025e958 100644 --- a/src/tools/miri/tests/pass/enums.rs +++ b/src/tools/miri/tests/pass/enums.rs @@ -43,6 +43,7 @@ fn discriminant_overflow() { } } +#[allow(unreachable_patterns)] fn more_discriminant_overflow() { pub enum Infallible {}