diff options
| author | Nadrieril <nadrieril+git@gmail.com> | 2024-08-19 21:08:18 +0200 |
|---|---|---|
| committer | Nadrieril <nadrieril+git@gmail.com> | 2024-08-19 21:57:37 +0200 |
| commit | efb28bdd90cf7b4ef6d436edaca8f394724fb604 (patch) | |
| tree | fd39643995558d2f7d8a4e8194820d3638307d31 /compiler | |
| parent | 25964b541e5671de044fd01d058a45bb92b75d1e (diff) | |
Add a note with a link to explain empty types
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_mir_build/messages.ftl | 1 | ||||
| -rw-r--r-- | compiler/rustc_mir_build/src/errors.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_mir_build/src/thir/pattern/check_match.rs | 2 |
3 files changed, 5 insertions, 0 deletions
diff --git a/compiler/rustc_mir_build/messages.ftl b/compiler/rustc_mir_build/messages.ftl index ae13485ce73..b6258045566 100644 --- a/compiler/rustc_mir_build/messages.ftl +++ b/compiler/rustc_mir_build/messages.ftl @@ -332,6 +332,7 @@ mir_build_unreachable_matches_same_values = matches some of the same values mir_build_unreachable_pattern = unreachable pattern .label = no value can reach this .unreachable_matches_no_values = matches no values because `{$ty}` is uninhabited + .unreachable_uninhabited_note = to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types .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 diff --git a/compiler/rustc_mir_build/src/errors.rs b/compiler/rustc_mir_build/src/errors.rs index 34577f102d1..a45a0311e32 100644 --- a/compiler/rustc_mir_build/src/errors.rs +++ b/compiler/rustc_mir_build/src/errors.rs @@ -588,6 +588,8 @@ pub(crate) struct UnreachablePattern<'tcx> { pub(crate) span: Option<Span>, #[subdiagnostic] pub(crate) matches_no_values: Option<UnreachableMatchesNoValues<'tcx>>, + #[note(mir_build_unreachable_uninhabited_note)] + pub(crate) uninhabited_note: Option<()>, #[label(mir_build_unreachable_covered_by_catchall)] pub(crate) covered_by_catchall: Option<Span>, #[label(mir_build_unreachable_covered_by_one)] 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 85b9dacb129..a948e5d0c21 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -921,6 +921,7 @@ fn report_unreachable_pattern<'p, 'tcx>( let mut lint = UnreachablePattern { span: Some(pat_span), matches_no_values: None, + uninhabited_note: None, covered_by_catchall: None, covered_by_one: None, covered_by_many: None, @@ -929,6 +930,7 @@ fn report_unreachable_pattern<'p, 'tcx>( [] => { // Empty pattern; we report the uninhabited type that caused the emptiness. lint.span = None; // Don't label the pattern itself + lint.uninhabited_note = Some(()); // Give a link about empty types pat.walk(&mut |subpat| { let ty = **subpat.ty(); if cx.is_uninhabited(ty) { |
