Rollup merge of #129281 - Nadrieril:tweak-unreachable-lint-wording, r=estebank
Tweak unreachable lint wording Some tweaks to the notes added in https://github.com/rust-lang/rust/pull/128034. r? `@estebank`
This commit is contained in:
commit
9bb17d345a
47 changed files with 742 additions and 673 deletions
|
@ -327,14 +327,17 @@ mir_build_union_pattern = cannot use unions in constant patterns
|
|||
|
||||
mir_build_unreachable_making_this_unreachable = collectively making this unreachable
|
||||
|
||||
mir_build_unreachable_making_this_unreachable_n_more = ...and {$covered_by_many_n_more_count} other patterns collectively make this unreachable
|
||||
|
||||
mir_build_unreachable_matches_same_values = matches some of the same values
|
||||
|
||||
mir_build_unreachable_pattern = unreachable pattern
|
||||
.label = unreachable pattern
|
||||
.unreachable_matches_no_values = this pattern matches no values because `{$ty}` is uninhabited
|
||||
.label = no value can reach this
|
||||
.unreachable_matches_no_values = matches no values because `{$matches_no_values_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 values already
|
||||
.unreachable_covered_by_many = these patterns collectively make the last one unreachable
|
||||
.unreachable_covered_by_one = matches all the relevant values
|
||||
.unreachable_covered_by_many = multiple earlier patterns match some of the same values
|
||||
|
||||
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
|
||||
|
|
|
@ -586,20 +586,18 @@ pub(crate) struct NonConstPath {
|
|||
pub(crate) struct UnreachablePattern<'tcx> {
|
||||
#[label]
|
||||
pub(crate) span: Option<Span>,
|
||||
#[subdiagnostic]
|
||||
pub(crate) matches_no_values: Option<UnreachableMatchesNoValues<'tcx>>,
|
||||
#[label(mir_build_unreachable_matches_no_values)]
|
||||
pub(crate) matches_no_values: Option<Span>,
|
||||
pub(crate) matches_no_values_ty: Ty<'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)]
|
||||
pub(crate) covered_by_one: Option<Span>,
|
||||
#[note(mir_build_unreachable_covered_by_many)]
|
||||
pub(crate) covered_by_many: Option<MultiSpan>,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[note(mir_build_unreachable_matches_no_values)]
|
||||
pub(crate) struct UnreachableMatchesNoValues<'tcx> {
|
||||
pub(crate) ty: Ty<'tcx>,
|
||||
pub(crate) covered_by_many_n_more_count: usize,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
|
|
|
@ -917,22 +917,28 @@ fn report_unreachable_pattern<'p, 'tcx>(
|
|||
pat: &DeconstructedPat<'p, 'tcx>,
|
||||
explanation: &RedundancyExplanation<'p, 'tcx>,
|
||||
) {
|
||||
static CAP_COVERED_BY_MANY: usize = 4;
|
||||
let pat_span = pat.data().span;
|
||||
let mut lint = UnreachablePattern {
|
||||
span: Some(pat_span),
|
||||
matches_no_values: None,
|
||||
matches_no_values_ty: **pat.ty(),
|
||||
uninhabited_note: None,
|
||||
covered_by_catchall: None,
|
||||
covered_by_one: None,
|
||||
covered_by_many: None,
|
||||
covered_by_many_n_more_count: 0,
|
||||
};
|
||||
match explanation.covered_by.as_slice() {
|
||||
[] => {
|
||||
// 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
|
||||
lint.matches_no_values = Some(pat_span);
|
||||
pat.walk(&mut |subpat| {
|
||||
let ty = **subpat.ty();
|
||||
if cx.is_uninhabited(ty) {
|
||||
lint.matches_no_values = Some(UnreachableMatchesNoValues { ty });
|
||||
lint.matches_no_values_ty = ty;
|
||||
false // No need to dig further.
|
||||
} else if matches!(subpat.ctor(), Constructor::Ref | Constructor::UnionField) {
|
||||
false // Don't explore further since they are not by-value.
|
||||
|
@ -948,15 +954,27 @@ fn report_unreachable_pattern<'p, 'tcx>(
|
|||
lint.covered_by_one = Some(covering_pat.data().span);
|
||||
}
|
||||
covering_pats => {
|
||||
let mut iter = covering_pats.iter();
|
||||
let mut multispan = MultiSpan::from_span(pat_span);
|
||||
for p in covering_pats {
|
||||
for p in iter.by_ref().take(CAP_COVERED_BY_MANY) {
|
||||
multispan.push_span_label(
|
||||
p.data().span,
|
||||
fluent::mir_build_unreachable_matches_same_values,
|
||||
);
|
||||
}
|
||||
multispan
|
||||
.push_span_label(pat_span, fluent::mir_build_unreachable_making_this_unreachable);
|
||||
let remain = iter.count();
|
||||
if remain == 0 {
|
||||
multispan.push_span_label(
|
||||
pat_span,
|
||||
fluent::mir_build_unreachable_making_this_unreachable,
|
||||
);
|
||||
} else {
|
||||
lint.covered_by_many_n_more_count = remain;
|
||||
multispan.push_span_label(
|
||||
pat_span,
|
||||
fluent::mir_build_unreachable_making_this_unreachable_n_more,
|
||||
);
|
||||
}
|
||||
lint.covered_by_many = Some(multispan);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue