diff --git a/compiler/rustc_mir_build/messages.ftl b/compiler/rustc_mir_build/messages.ftl index 7a10e627ccd89..1c4e9fd11cbd6 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 7f9eefd1d52e3..411e9420914da 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 4c066a68ef9ff..3fde6466d8cb0 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 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> { // 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 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> { 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 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> { ) -> 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 60ab4d52c30f1..ec08e22e2ca07 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 60ab4d52c30f1..ec08e22e2ca07 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 9decddfe5de9a..c6e41c1875fa7 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 68213a2d661e0..6822401b7e95b 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: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 @@ -55,7 +64,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 @@ -63,7 +75,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 @@ -71,7 +86,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 @@ -98,7 +116,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 @@ -106,7 +127,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 @@ -160,7 +184,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 @@ -168,7 +195,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 @@ -176,7 +206,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 @@ -184,7 +217,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 @@ -192,7 +228,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 @@ -200,7 +239,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 @@ -208,7 +250,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 @@ -216,7 +261,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 @@ -224,7 +272,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 @@ -259,7 +310,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 @@ -267,7 +321,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 @@ -275,7 +332,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 @@ -283,7 +343,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 @@ -291,7 +354,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 @@ -299,7 +365,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 @@ -307,7 +376,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 @@ -315,7 +387,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 @@ -323,7 +398,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 @@ -478,7 +556,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 @@ -486,7 +567,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 @@ -494,7 +578,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 @@ -538,7 +625,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 @@ -546,7 +636,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 @@ -662,7 +755,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 @@ -670,7 +766,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 @@ -678,7 +777,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 @@ -686,7 +788,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 8f60dad4467bc..d6897515a45a8 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: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 @@ -151,7 +175,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 @@ -159,7 +186,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 @@ -167,7 +197,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 @@ -175,7 +208,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 @@ -183,7 +219,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 @@ -191,7 +230,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 @@ -199,7 +241,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 @@ -207,7 +252,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 @@ -215,7 +263,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 @@ -250,7 +301,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 @@ -258,7 +312,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 @@ -266,7 +323,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 @@ -274,7 +334,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 @@ -282,7 +345,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 @@ -290,7 +356,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 @@ -298,7 +367,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 @@ -306,7 +378,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 @@ -314,7 +389,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 @@ -469,7 +547,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 @@ -477,7 +558,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 @@ -485,7 +569,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 @@ -529,7 +616,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 @@ -537,7 +627,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 @@ -653,7 +746,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 @@ -661,7 +757,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 @@ -669,7 +768,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 @@ -677,7 +779,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 7023c2775e9a7..a18454b2cf95a 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:51: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:65: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:72: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 34b157f0fc443..f3390d25b2f4a 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:16: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:30: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:44: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:58: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:75: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:93: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:137: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:150: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 0000000000000..010500e967d65 --- /dev/null +++ b/tests/ui/pattern/usefulness/rustfix-unreachable-pattern.fixed @@ -0,0 +1,22 @@ +//@ run-rustfix +#![feature(never_patterns)] +#![deny(unreachable_patterns)] +#![allow(incomplete_features)] + +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 0000000000000..62d51f8533600 --- /dev/null +++ b/tests/ui/pattern/usefulness/rustfix-unreachable-pattern.rs @@ -0,0 +1,22 @@ +//@ run-rustfix +#![feature(never_patterns)] +#![deny(unreachable_patterns)] +#![allow(incomplete_features)] + +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 0000000000000..27e3824166e21 --- /dev/null +++ b/tests/ui/pattern/usefulness/rustfix-unreachable-pattern.stderr @@ -0,0 +1,51 @@ +error: unreachable pattern + --> $DIR/rustfix-unreachable-pattern.rs:13: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:3:9 + | +LL | #![deny(unreachable_patterns)] + | ^^^^^^^^^^^^^^^^^^^^ + +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 + +error: unreachable pattern + --> $DIR/rustfix-unreachable-pattern.rs:19: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: 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 b082bc1160332..40b116131057c 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 6b3f303eeab84..36d6187b4bff1 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:14: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 dfd7f9d630051..45a0ca01a5603 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_same_crate.stderr b/tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/patterns_same_crate.stderr index 7e7dc802e7fbf..576907d3be3c1 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:51: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:56: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 0e1c9d31a731f..6679d2f9e2546 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:29: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:38: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