1
Fork 0

Add a note with a link to explain empty types

This commit is contained in:
Nadrieril 2024-08-19 21:08:18 +02:00
parent 25964b541e
commit efb28bdd90
18 changed files with 171 additions and 17 deletions

View file

@ -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

View file

@ -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)]

View file

@ -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) {