From 1f696384005c27c49ee0e31b1b9031d61b89be6b Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 19 Aug 2024 21:33:48 +0200 Subject: [PATCH] Add a machine-applicable suggestion to "unreachable pattern" --- compiler/rustc_mir_build/messages.ftl | 1 + compiler/rustc_mir_build/src/errors.rs | 2 + .../src/thir/pattern/check_match.rs | 35 +++- ...tch-check-notes.exhaustive_patterns.stderr | 20 +- .../empty-match-check-notes.normal.stderr | 20 +- .../empty-types.exhaustive_patterns.stderr | 175 ++++++++++++++---- .../usefulness/empty-types.never_pats.stderr | 75 ++++++-- .../usefulness/empty-types.normal.stderr | 75 ++++++-- .../explain-unreachable-pats.stderr | 15 +- tests/ui/pattern/usefulness/impl-trait.stderr | 40 +++- .../rustfix-unreachable-pattern.fixed | 23 +++ .../usefulness/rustfix-unreachable-pattern.rs | 23 +++ .../rustfix-unreachable-pattern.stderr | 51 +++++ .../reachable/unreachable-try-pattern.stderr | 10 +- .../unreachable.stderr | 5 +- .../enum_same_crate_empty_match.stderr | 5 +- .../uninhabited/patterns.stderr | 5 +- .../uninhabited/patterns_same_crate.stderr | 10 +- .../uninhabited/uninhabited-patterns.stderr | 10 +- 19 files changed, 502 insertions(+), 98 deletions(-) create mode 100644 tests/ui/pattern/usefulness/rustfix-unreachable-pattern.fixed create mode 100644 tests/ui/pattern/usefulness/rustfix-unreachable-pattern.rs create mode 100644 tests/ui/pattern/usefulness/rustfix-unreachable-pattern.stderr diff --git a/compiler/rustc_mir_build/messages.ftl b/compiler/rustc_mir_build/messages.ftl index 7a10e627ccd..1c4e9fd11cb 100644 --- a/compiler/rustc_mir_build/messages.ftl +++ b/compiler/rustc_mir_build/messages.ftl @@ -338,6 +338,7 @@ mir_build_unreachable_pattern = unreachable pattern .unreachable_covered_by_catchall = matches any value .unreachable_covered_by_one = matches all the relevant values .unreachable_covered_by_many = multiple earlier patterns match some of the same values + .suggestion = remove the match arm mir_build_unsafe_fn_safe_body = an unsafe function restricts its caller, but its body is safe by default mir_build_unsafe_not_inherited = items do not inherit unsafety from separate enclosing items diff --git a/compiler/rustc_mir_build/src/errors.rs b/compiler/rustc_mir_build/src/errors.rs index 7f9eefd1d52..411e9420914 100644 --- a/compiler/rustc_mir_build/src/errors.rs +++ b/compiler/rustc_mir_build/src/errors.rs @@ -598,6 +598,8 @@ pub(crate) struct UnreachablePattern<'tcx> { #[note(mir_build_unreachable_covered_by_many)] pub(crate) covered_by_many: Option, pub(crate) covered_by_many_n_more_count: usize, + #[suggestion(code = "", applicability = "machine-applicable")] + pub(crate) suggest_remove: Option, } #[derive(Diagnostic)] 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 4c066a68ef9..3fde6466d8c 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -413,7 +413,7 @@ fn analyze_patterns( // Emit lints in the order in which they occur in the file. redundant_subpats.sort_unstable_by_key(|(pat, _)| pat.data().span); for (pat, explanation) in redundant_subpats { - report_unreachable_pattern(cx, arm.arm_data, pat, &explanation) + report_unreachable_pattern(cx, arm.arm_data, pat, &explanation, None) } } } @@ -474,7 +474,11 @@ fn check_match( hir::MatchSource::ForLoopDesugar | hir::MatchSource::Postfix | hir::MatchSource::Normal - | hir::MatchSource::FormatArgs => report_arm_reachability(&cx, &report), + | hir::MatchSource::FormatArgs => { + let is_match_arm = + matches!(source, hir::MatchSource::Postfix | hir::MatchSource::Normal); + report_arm_reachability(&cx, &report, is_match_arm); + } // Unreachable patterns in try and await expressions occur when one of // the arms are an uninhabited type. Which is OK. hir::MatchSource::AwaitDesugar | hir::MatchSource::TryDesugar(_) => {} @@ -626,7 +630,7 @@ fn is_let_irrefutable( ) -> Result { let (cx, report) = self.analyze_binding(pat, Refutable, scrut)?; // Report if the pattern is unreachable, which can only occur when the type is uninhabited. - report_arm_reachability(&cx, &report); + report_arm_reachability(&cx, &report, false); // If the list of witnesses is empty, the match is exhaustive, i.e. the `if let` pattern is // irrefutable. Ok(if report.non_exhaustiveness_witnesses.is_empty() { Irrefutable } else { Refutable }) @@ -916,6 +920,7 @@ fn report_unreachable_pattern<'p, 'tcx>( hir_id: HirId, pat: &DeconstructedPat<'p, 'tcx>, explanation: &RedundancyExplanation<'p, 'tcx>, + whole_arm_span: Option, ) { static CAP_COVERED_BY_MANY: usize = 4; let pat_span = pat.data().span; @@ -928,6 +933,7 @@ fn report_unreachable_pattern<'p, 'tcx>( covered_by_one: None, covered_by_many: None, covered_by_many_n_more_count: 0, + suggest_remove: None, }; match explanation.covered_by.as_slice() { [] => { @@ -935,6 +941,7 @@ fn report_unreachable_pattern<'p, 'tcx>( lint.span = None; // Don't label the pattern itself lint.uninhabited_note = Some(()); // Give a link about empty types lint.matches_no_values = Some(pat_span); + lint.suggest_remove = whole_arm_span; // Suggest to remove the match arm pat.walk(&mut |subpat| { let ty = **subpat.ty(); if cx.is_uninhabited(ty) { @@ -982,10 +989,28 @@ fn report_unreachable_pattern<'p, 'tcx>( } /// Report unreachable arms, if any. -fn report_arm_reachability<'p, 'tcx>(cx: &PatCtxt<'p, 'tcx>, report: &UsefulnessReport<'p, 'tcx>) { +fn report_arm_reachability<'p, 'tcx>( + cx: &PatCtxt<'p, 'tcx>, + report: &UsefulnessReport<'p, 'tcx>, + is_match_arm: bool, +) { + let sm = cx.tcx.sess.source_map(); for (arm, is_useful) in report.arm_usefulness.iter() { if let Usefulness::Redundant(explanation) = is_useful { - report_unreachable_pattern(cx, arm.arm_data, arm.pat, explanation) + let hir_id = arm.arm_data; + let arm_span = cx.tcx.hir().span(hir_id); + let whole_arm_span = if is_match_arm { + // If the arm is followed by a comma, extend the span to include it. + let with_whitespace = sm.span_extend_while_whitespace(arm_span); + if let Some(comma) = sm.span_look_ahead(with_whitespace, ",", Some(1)) { + Some(arm_span.to(comma)) + } else { + Some(arm_span) + } + } else { + None + }; + report_unreachable_pattern(cx, hir_id, arm.pat, explanation, whole_arm_span) } } } 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 60ab4d52c30..ec08e22e2ca 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 @@ -2,7 +2,10 @@ error: unreachable pattern --> $DIR/empty-match-check-notes.rs:17:9 | LL | _ => {} - | ^ matches no values because `EmptyEnum` is uninhabited + | ^------ + | | + | matches no values because `EmptyEnum` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types note: the lint level is defined here @@ -15,7 +18,10 @@ error: unreachable pattern --> $DIR/empty-match-check-notes.rs:22:9 | LL | _ if false => {} - | ^ matches no values because `EmptyEnum` is uninhabited + | ^--------------- + | | + | matches no values because `EmptyEnum` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -23,7 +29,10 @@ error: unreachable pattern --> $DIR/empty-match-check-notes.rs:31:9 | LL | _ => {} - | ^ matches no values because `EmptyForeignEnum` is uninhabited + | ^------ + | | + | matches no values because `EmptyForeignEnum` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -31,7 +40,10 @@ error: unreachable pattern --> $DIR/empty-match-check-notes.rs:36:9 | LL | _ if false => {} - | ^ matches no values because `EmptyForeignEnum` is uninhabited + | ^--------------- + | | + | matches no values because `EmptyForeignEnum` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types 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 60ab4d52c30..ec08e22e2ca 100644 --- a/tests/ui/pattern/usefulness/empty-match-check-notes.normal.stderr +++ b/tests/ui/pattern/usefulness/empty-match-check-notes.normal.stderr @@ -2,7 +2,10 @@ error: unreachable pattern --> $DIR/empty-match-check-notes.rs:17:9 | LL | _ => {} - | ^ matches no values because `EmptyEnum` is uninhabited + | ^------ + | | + | matches no values because `EmptyEnum` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types note: the lint level is defined here @@ -15,7 +18,10 @@ error: unreachable pattern --> $DIR/empty-match-check-notes.rs:22:9 | LL | _ if false => {} - | ^ matches no values because `EmptyEnum` is uninhabited + | ^--------------- + | | + | matches no values because `EmptyEnum` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -23,7 +29,10 @@ error: unreachable pattern --> $DIR/empty-match-check-notes.rs:31:9 | LL | _ => {} - | ^ matches no values because `EmptyForeignEnum` is uninhabited + | ^------ + | | + | matches no values because `EmptyForeignEnum` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -31,7 +40,10 @@ error: unreachable pattern --> $DIR/empty-match-check-notes.rs:36:9 | LL | _ if false => {} - | ^ matches no values because `EmptyForeignEnum` is uninhabited + | ^--------------- + | | + | matches no values because `EmptyForeignEnum` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types diff --git a/tests/ui/pattern/usefulness/empty-types.exhaustive_patterns.stderr b/tests/ui/pattern/usefulness/empty-types.exhaustive_patterns.stderr index 9decddfe5de..c6e41c1875f 100644 --- a/tests/ui/pattern/usefulness/empty-types.exhaustive_patterns.stderr +++ b/tests/ui/pattern/usefulness/empty-types.exhaustive_patterns.stderr @@ -2,7 +2,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:49:9 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types note: the lint level is defined here @@ -15,7 +18,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:52:9 | LL | _x => {} - | ^^ matches no values because `!` is uninhabited + | ^^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -38,7 +44,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:70:9 | LL | (_, _) => {} - | ^^^^^^ matches no values because `(u32, !)` is uninhabited + | ^^^^^^------ + | | + | matches no values because `(u32, !)` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -46,7 +55,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:76:9 | LL | _ => {} - | ^ matches no values because `(!, !)` is uninhabited + | ^------ + | | + | matches no values because `(!, !)` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -54,7 +66,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:79:9 | LL | (_, _) => {} - | ^^^^^^ matches no values because `(!, !)` is uninhabited + | ^^^^^^------ + | | + | matches no values because `(!, !)` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -62,7 +77,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:83:9 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -89,7 +107,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:94:9 | LL | Err(_) => {} - | ^^^^^^ matches no values because `!` is uninhabited + | ^^^^^^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -97,7 +118,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:99:9 | LL | Err(_) => {} - | ^^^^^^ matches no values because `!` is uninhabited + | ^^^^^^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -137,7 +161,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:112:9 | LL | _ => {} - | ^ matches no values because `Result` is uninhabited + | ^------ + | | + | matches no values because `Result` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -145,7 +172,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:115:9 | LL | Ok(_) => {} - | ^^^^^ matches no values because `Result` is uninhabited + | ^^^^^------ + | | + | matches no values because `Result` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -153,7 +183,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:118:9 | LL | Ok(_) => {} - | ^^^^^ matches no values because `Result` is uninhabited + | ^^^^^------ + | | + | matches no values because `Result` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -161,7 +194,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:119:9 | LL | _ => {} - | ^ matches no values because `Result` is uninhabited + | ^------ + | | + | matches no values because `Result` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -169,7 +205,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:122:9 | LL | Ok(_) => {} - | ^^^^^ matches no values because `Result` is uninhabited + | ^^^^^------ + | | + | matches no values because `Result` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -177,7 +216,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:123:9 | LL | Err(_) => {} - | ^^^^^^ matches no values because `Result` is uninhabited + | ^^^^^^------ + | | + | matches no values because `Result` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -185,7 +227,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:132:13 | LL | _ => {} - | ^ matches no values because `Void` is uninhabited + | ^------ + | | + | matches no values because `Void` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -193,7 +238,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:135:13 | LL | _ if false => {} - | ^ matches no values because `Void` is uninhabited + | ^--------------- + | | + | matches no values because `Void` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -201,7 +249,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:143:13 | LL | Some(_) => {} - | ^^^^^^^ matches no values because `Void` is uninhabited + | ^^^^^^^------ + | | + | matches no values because `Void` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -217,7 +268,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:199:13 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -225,7 +279,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:204:13 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -233,7 +290,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:209:13 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -241,7 +301,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:214:13 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -249,7 +312,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:220:13 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -257,7 +323,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:281:9 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -265,7 +334,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:284:9 | LL | (_, _) => {} - | ^^^^^^ matches no values because `(!, !)` is uninhabited + | ^^^^^^------ + | | + | matches no values because `(!, !)` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -273,7 +345,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:287:9 | LL | Ok(_) => {} - | ^^^^^ matches no values because `Result` is uninhabited + | ^^^^^------ + | | + | matches no values because `Result` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -281,7 +356,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:288:9 | LL | Err(_) => {} - | ^^^^^^ matches no values because `Result` is uninhabited + | ^^^^^^------ + | | + | matches no values because `Result` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -344,7 +422,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:368:9 | LL | _ => {} - | ^ matches no values because `[!; 3]` is uninhabited + | ^------ + | | + | matches no values because `[!; 3]` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -352,7 +433,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:371:9 | LL | [_, _, _] => {} - | ^^^^^^^^^ matches no values because `[!; 3]` is uninhabited + | ^^^^^^^^^------ + | | + | matches no values because `[!; 3]` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -360,7 +444,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:374:9 | LL | [_, ..] => {} - | ^^^^^^^ matches no values because `[!; 3]` is uninhabited + | ^^^^^^^------ + | | + | matches no values because `[!; 3]` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -404,7 +491,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:416:9 | LL | Some(_) => {} - | ^^^^^^^ matches no values because `!` is uninhabited + | ^^^^^^^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -412,7 +502,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:421:9 | LL | Some(_a) => {} - | ^^^^^^^^ matches no values because `!` is uninhabited + | ^^^^^^^^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -438,7 +531,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:603:9 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -446,7 +542,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:606:9 | LL | _x => {} - | ^^ matches no values because `!` is uninhabited + | ^^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -454,7 +553,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:609:9 | LL | _ if false => {} - | ^ matches no values because `!` is uninhabited + | ^--------------- + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -462,7 +564,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:612:9 | LL | _x if false => {} - | ^^ matches no values because `!` is uninhabited + | ^^--------------- + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types diff --git a/tests/ui/pattern/usefulness/empty-types.never_pats.stderr b/tests/ui/pattern/usefulness/empty-types.never_pats.stderr index fe9c4319820..3f312d46c7e 100644 --- a/tests/ui/pattern/usefulness/empty-types.never_pats.stderr +++ b/tests/ui/pattern/usefulness/empty-types.never_pats.stderr @@ -11,7 +11,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:49:9 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types note: the lint level is defined here @@ -24,7 +27,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:52:9 | LL | _x => {} - | ^^ matches no values because `!` is uninhabited + | ^^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -47,7 +53,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:83:9 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -120,7 +129,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:132:13 | LL | _ => {} - | ^ matches no values because `Void` is uninhabited + | ^------ + | | + | matches no values because `Void` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -128,7 +140,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:135:13 | LL | _ if false => {} - | ^ matches no values because `Void` is uninhabited + | ^--------------- + | | + | matches no values because `Void` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -155,7 +170,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:199:13 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -163,7 +181,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:204:13 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -171,7 +192,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:209:13 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -179,7 +203,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:214:13 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -187,7 +214,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:220:13 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -195,7 +225,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:281:9 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -476,7 +509,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:603:9 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -484,7 +520,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:606:9 | LL | _x => {} - | ^^ matches no values because `!` is uninhabited + | ^^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -492,7 +531,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:609:9 | LL | _ if false => {} - | ^ matches no values because `!` is uninhabited + | ^--------------- + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -500,7 +542,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:612:9 | LL | _x if false => {} - | ^^ matches no values because `!` is uninhabited + | ^^--------------- + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types diff --git a/tests/ui/pattern/usefulness/empty-types.normal.stderr b/tests/ui/pattern/usefulness/empty-types.normal.stderr index 201b0b5c3fd..bba50dab27b 100644 --- a/tests/ui/pattern/usefulness/empty-types.normal.stderr +++ b/tests/ui/pattern/usefulness/empty-types.normal.stderr @@ -2,7 +2,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:49:9 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types note: the lint level is defined here @@ -15,7 +18,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:52:9 | LL | _x => {} - | ^^ matches no values because `!` is uninhabited + | ^^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -38,7 +44,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:83:9 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -111,7 +120,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:132:13 | LL | _ => {} - | ^ matches no values because `Void` is uninhabited + | ^------ + | | + | matches no values because `Void` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -119,7 +131,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:135:13 | LL | _ if false => {} - | ^ matches no values because `Void` is uninhabited + | ^--------------- + | | + | matches no values because `Void` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -146,7 +161,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:199:13 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -154,7 +172,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:204:13 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -162,7 +183,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:209:13 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -170,7 +194,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:214:13 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -178,7 +205,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:220:13 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -186,7 +216,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:281:9 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -467,7 +500,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:603:9 | LL | _ => {} - | ^ matches no values because `!` is uninhabited + | ^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -475,7 +511,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:606:9 | LL | _x => {} - | ^^ matches no values because `!` is uninhabited + | ^^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -483,7 +522,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:609:9 | LL | _ if false => {} - | ^ matches no values because `!` is uninhabited + | ^--------------- + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -491,7 +533,10 @@ error: unreachable pattern --> $DIR/empty-types.rs:612:9 | LL | _x if false => {} - | ^^ matches no values because `!` is uninhabited + | ^^--------------- + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types diff --git a/tests/ui/pattern/usefulness/explain-unreachable-pats.stderr b/tests/ui/pattern/usefulness/explain-unreachable-pats.stderr index 67f83a85175..8651be2055f 100644 --- a/tests/ui/pattern/usefulness/explain-unreachable-pats.stderr +++ b/tests/ui/pattern/usefulness/explain-unreachable-pats.stderr @@ -59,7 +59,10 @@ error: unreachable pattern --> $DIR/explain-unreachable-pats.rs:52:9 | LL | Err(_) => {} - | ^^^^^^ matches no values because `!` is uninhabited + | ^^^^^^------ + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -67,7 +70,10 @@ error: unreachable pattern --> $DIR/explain-unreachable-pats.rs:66:9 | LL | (Err(_), Err(_)) => {} - | ^^^^^^^^^^^^^^^^ matches no values because `Void2` is uninhabited + | ^^^^^^^^^^^^^^^^------ + | | + | matches no values because `Void2` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -75,7 +81,10 @@ error: unreachable pattern --> $DIR/explain-unreachable-pats.rs:73:9 | LL | (Err(_), Err(_)) => {} - | ^^^^^^^^^^^^^^^^ matches no values because `Void1` is uninhabited + | ^^^^^^^^^^^^^^^^------ + | | + | matches no values because `Void1` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types diff --git a/tests/ui/pattern/usefulness/impl-trait.stderr b/tests/ui/pattern/usefulness/impl-trait.stderr index f2945fca82b..75cba4b5f02 100644 --- a/tests/ui/pattern/usefulness/impl-trait.stderr +++ b/tests/ui/pattern/usefulness/impl-trait.stderr @@ -2,7 +2,10 @@ error: unreachable pattern --> $DIR/impl-trait.rs:17:13 | LL | _ => {} - | ^ matches no values because `Void` is uninhabited + | ^------ + | | + | matches no values because `Void` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types note: the lint level is defined here @@ -15,7 +18,10 @@ error: unreachable pattern --> $DIR/impl-trait.rs:31:13 | LL | _ => {} - | ^ matches no values because `Void` is uninhabited + | ^------ + | | + | matches no values because `Void` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -23,7 +29,10 @@ error: unreachable pattern --> $DIR/impl-trait.rs:45:13 | LL | Some(_) => {} - | ^^^^^^^ matches no values because `Void` is uninhabited + | ^^^^^^^------ + | | + | matches no values because `Void` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -39,7 +48,10 @@ error: unreachable pattern --> $DIR/impl-trait.rs:59:13 | LL | Some(_) => {} - | ^^^^^^^ matches no values because `Void` is uninhabited + | ^^^^^^^------ + | | + | matches no values because `Void` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -55,7 +67,10 @@ error: unreachable pattern --> $DIR/impl-trait.rs:76:9 | LL | _ => {} - | ^ matches no values because `Void` is uninhabited + | ^------ + | | + | matches no values because `Void` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -71,7 +86,10 @@ error: unreachable pattern --> $DIR/impl-trait.rs:94:13 | LL | _ => {} - | ^ matches no values because `Void` is uninhabited + | ^------ + | | + | matches no values because `Void` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -95,7 +113,10 @@ error: unreachable pattern --> $DIR/impl-trait.rs:138:13 | LL | _ => {} - | ^ matches no values because `SecretelyVoid` is uninhabited + | ^------ + | | + | matches no values because `SecretelyVoid` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types @@ -103,7 +124,10 @@ error: unreachable pattern --> $DIR/impl-trait.rs:151:13 | LL | _ => {} - | ^ matches no values because `SecretelyDoubleVoid` is uninhabited + | ^------ + | | + | matches no values because `SecretelyDoubleVoid` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types diff --git a/tests/ui/pattern/usefulness/rustfix-unreachable-pattern.fixed b/tests/ui/pattern/usefulness/rustfix-unreachable-pattern.fixed new file mode 100644 index 00000000000..18e3aecbd0d --- /dev/null +++ b/tests/ui/pattern/usefulness/rustfix-unreachable-pattern.fixed @@ -0,0 +1,23 @@ +//@ run-rustfix +#![feature(never_patterns)] +#![feature(exhaustive_patterns)] +#![allow(incomplete_features)] +#![deny(unreachable_patterns)] + +enum Void {} + +#[rustfmt::skip] +fn main() { + let res: Result<(), Void> = Ok(()); + match res { + Ok(_) => {} + //~ ERROR unreachable + //~ ERROR unreachable + } + + match res { + Ok(_x) => {} + //~ ERROR unreachable + //~ ERROR unreachable + } +} diff --git a/tests/ui/pattern/usefulness/rustfix-unreachable-pattern.rs b/tests/ui/pattern/usefulness/rustfix-unreachable-pattern.rs new file mode 100644 index 00000000000..a81420d1496 --- /dev/null +++ b/tests/ui/pattern/usefulness/rustfix-unreachable-pattern.rs @@ -0,0 +1,23 @@ +//@ run-rustfix +#![feature(never_patterns)] +#![feature(exhaustive_patterns)] +#![allow(incomplete_features)] +#![deny(unreachable_patterns)] + +enum Void {} + +#[rustfmt::skip] +fn main() { + let res: Result<(), Void> = Ok(()); + match res { + Ok(_) => {} + Err(_) => {} //~ ERROR unreachable + Err(_) => {}, //~ ERROR unreachable + } + + match res { + Ok(_x) => {} + Err(!), //~ ERROR unreachable + Err(!) //~ ERROR unreachable + } +} diff --git a/tests/ui/pattern/usefulness/rustfix-unreachable-pattern.stderr b/tests/ui/pattern/usefulness/rustfix-unreachable-pattern.stderr new file mode 100644 index 00000000000..bb246cea0a0 --- /dev/null +++ b/tests/ui/pattern/usefulness/rustfix-unreachable-pattern.stderr @@ -0,0 +1,51 @@ +error: unreachable pattern + --> $DIR/rustfix-unreachable-pattern.rs:14:9 + | +LL | Err(_) => {} + | ^^^^^^------ + | | + | matches no values because `Void` is uninhabited + | help: remove the match arm + | + = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types +note: the lint level is defined here + --> $DIR/rustfix-unreachable-pattern.rs:5:9 + | +LL | #![deny(unreachable_patterns)] + | ^^^^^^^^^^^^^^^^^^^^ + +error: unreachable pattern + --> $DIR/rustfix-unreachable-pattern.rs:15:9 + | +LL | Err(_) => {}, + | ^^^^^^------- + | | + | matches no values because `Void` is uninhabited + | help: remove the match arm + | + = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types + +error: unreachable pattern + --> $DIR/rustfix-unreachable-pattern.rs:20:9 + | +LL | Err(!), + | ^^^^^^- + | | + | matches no values because `Void` is uninhabited + | help: remove the match arm + | + = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types + +error: unreachable pattern + --> $DIR/rustfix-unreachable-pattern.rs:21:9 + | +LL | Err(!) + | ^^^^^^ + | | + | matches no values because `Void` is uninhabited + | help: remove the match arm + | + = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types + +error: aborting due to 4 previous errors + diff --git a/tests/ui/reachable/unreachable-try-pattern.stderr b/tests/ui/reachable/unreachable-try-pattern.stderr index b082bc11603..40b11613105 100644 --- a/tests/ui/reachable/unreachable-try-pattern.stderr +++ b/tests/ui/reachable/unreachable-try-pattern.stderr @@ -17,7 +17,10 @@ warning: unreachable pattern --> $DIR/unreachable-try-pattern.rs:19:24 | LL | let y = (match x { Ok(n) => Ok(n as u32), Err(e) => Err(e) })?; - | ^^^^^ matches no values because `!` is uninhabited + | ^^^^^----------------- + | | + | matches no values because `!` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types note: the lint level is defined here @@ -30,7 +33,10 @@ warning: unreachable pattern --> $DIR/unreachable-try-pattern.rs:30:40 | LL | let y = (match x { Ok(n) => Ok(n), Err(e) => Err(e) })?; - | ^^^^^^ matches no values because `Void` is uninhabited + | ^^^^^^---------- + | | + | matches no values because `Void` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/unreachable.stderr b/tests/ui/rfcs/rfc-0000-never_patterns/unreachable.stderr index 90874760a56..0c9552bb950 100644 --- a/tests/ui/rfcs/rfc-0000-never_patterns/unreachable.stderr +++ b/tests/ui/rfcs/rfc-0000-never_patterns/unreachable.stderr @@ -2,7 +2,10 @@ error: unreachable pattern --> $DIR/unreachable.rs:15:9 | LL | Err(!), - | ^^^^^^ matches no values because `Void` is uninhabited + | ^^^^^^- + | | + | matches no values because `Void` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types note: the lint level is defined here diff --git a/tests/ui/rfcs/rfc-2008-non-exhaustive/enum_same_crate_empty_match.stderr b/tests/ui/rfcs/rfc-2008-non-exhaustive/enum_same_crate_empty_match.stderr index dfd7f9d6300..45a0ca01a56 100644 --- a/tests/ui/rfcs/rfc-2008-non-exhaustive/enum_same_crate_empty_match.stderr +++ b/tests/ui/rfcs/rfc-2008-non-exhaustive/enum_same_crate_empty_match.stderr @@ -2,7 +2,10 @@ error: unreachable pattern --> $DIR/enum_same_crate_empty_match.rs:28:9 | LL | _ => {} - | ^ matches no values because `EmptyNonExhaustiveEnum` is uninhabited + | ^------ + | | + | matches no values because `EmptyNonExhaustiveEnum` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types note: the lint level is defined here diff --git a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/patterns.stderr b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/patterns.stderr index 83300049ea9..1bb07fd0671 100644 --- a/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/patterns.stderr +++ b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/patterns.stderr @@ -2,7 +2,10 @@ error: unreachable pattern --> $DIR/patterns.rs:42:9 | LL | Some(_x) => (), - | ^^^^^^^^ matches no values because `UninhabitedVariants` is uninhabited + | ^^^^^^^^------- + | | + | matches no values because `UninhabitedVariants` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types note: the lint level is defined here 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 4b107b03645..bd70a7b4091 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 @@ -2,7 +2,10 @@ error: unreachable pattern --> $DIR/patterns_same_crate.rs:53:9 | LL | Some(_x) => (), - | ^^^^^^^^ matches no values because `UninhabitedEnum` is uninhabited + | ^^^^^^^^------- + | | + | matches no values because `UninhabitedEnum` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types note: the lint level is defined here @@ -15,7 +18,10 @@ error: unreachable pattern --> $DIR/patterns_same_crate.rs:58:9 | LL | Some(_x) => (), - | ^^^^^^^^ matches no values because `UninhabitedVariants` is uninhabited + | ^^^^^^^^------- + | | + | matches no values because `UninhabitedVariants` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types diff --git a/tests/ui/uninhabited/uninhabited-patterns.stderr b/tests/ui/uninhabited/uninhabited-patterns.stderr index db0166ad5f2..7a872767d95 100644 --- a/tests/ui/uninhabited/uninhabited-patterns.stderr +++ b/tests/ui/uninhabited/uninhabited-patterns.stderr @@ -2,7 +2,10 @@ error: unreachable pattern --> $DIR/uninhabited-patterns.rs:30:9 | LL | Ok(box _) => (), - | ^^^^^^^^^ matches no values because `NotSoSecretlyEmpty` is uninhabited + | ^^^^^^^^^------- + | | + | matches no values because `NotSoSecretlyEmpty` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types note: the lint level is defined here @@ -15,7 +18,10 @@ error: unreachable pattern --> $DIR/uninhabited-patterns.rs:39:9 | LL | Err(Ok(_y)) => (), - | ^^^^^^^^^^^ matches no values because `NotSoSecretlyEmpty` is uninhabited + | ^^^^^^^^^^^------- + | | + | matches no values because `NotSoSecretlyEmpty` is uninhabited + | help: remove the match arm | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types