Skip to content

Commit f30392a

Browse files
committed
Move the "matches no value" note to be a span label
1 parent 36eced4 commit f30392a

16 files changed

+149
-294
lines changed

compiler/rustc_mir_build/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ mir_build_unreachable_matches_same_values = matches some of the same values
333333
334334
mir_build_unreachable_pattern = unreachable pattern
335335
.label = no value can reach this
336-
.unreachable_matches_no_values = matches no values because `{$ty}` is uninhabited
336+
.unreachable_matches_no_values = matches no values because `{$matches_no_values_ty}` is uninhabited
337337
.unreachable_uninhabited_note = to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types
338338
.unreachable_covered_by_catchall = matches any value
339339
.unreachable_covered_by_one = matches all the relevant values

compiler/rustc_mir_build/src/errors.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,9 @@ pub(crate) struct NonConstPath {
586586
pub(crate) struct UnreachablePattern<'tcx> {
587587
#[label]
588588
pub(crate) span: Option<Span>,
589-
#[subdiagnostic]
590-
pub(crate) matches_no_values: Option<UnreachableMatchesNoValues<'tcx>>,
589+
#[label(mir_build_unreachable_matches_no_values)]
590+
pub(crate) matches_no_values: Option<Span>,
591+
pub(crate) matches_no_values_ty: Ty<'tcx>,
591592
#[note(mir_build_unreachable_uninhabited_note)]
592593
pub(crate) uninhabited_note: Option<()>,
593594
#[label(mir_build_unreachable_covered_by_catchall)]
@@ -599,12 +600,6 @@ pub(crate) struct UnreachablePattern<'tcx> {
599600
pub(crate) covered_by_many_n_more_count: usize,
600601
}
601602

602-
#[derive(Subdiagnostic)]
603-
#[note(mir_build_unreachable_matches_no_values)]
604-
pub(crate) struct UnreachableMatchesNoValues<'tcx> {
605-
pub(crate) ty: Ty<'tcx>,
606-
}
607-
608603
#[derive(Diagnostic)]
609604
#[diag(mir_build_const_pattern_depends_on_generic_parameter, code = E0158)]
610605
pub(crate) struct ConstPatternDependsOnGenericParameter {

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ fn report_unreachable_pattern<'p, 'tcx>(
922922
let mut lint = UnreachablePattern {
923923
span: Some(pat_span),
924924
matches_no_values: None,
925+
matches_no_values_ty: **pat.ty(),
925926
uninhabited_note: None,
926927
covered_by_catchall: None,
927928
covered_by_one: None,
@@ -933,10 +934,11 @@ fn report_unreachable_pattern<'p, 'tcx>(
933934
// Empty pattern; we report the uninhabited type that caused the emptiness.
934935
lint.span = None; // Don't label the pattern itself
935936
lint.uninhabited_note = Some(()); // Give a link about empty types
937+
lint.matches_no_values = Some(pat_span);
936938
pat.walk(&mut |subpat| {
937939
let ty = **subpat.ty();
938940
if cx.is_uninhabited(ty) {
939-
lint.matches_no_values = Some(UnreachableMatchesNoValues { ty });
941+
lint.matches_no_values_ty = ty;
940942
false // No need to dig further.
941943
} else if matches!(subpat.ctor(), Constructor::Ref | Constructor::UnionField) {
942944
false // Don't explore further since they are not by-value.

tests/ui/pattern/usefulness/empty-match-check-notes.exhaustive_patterns.stderr

+4-8
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ error: unreachable pattern
22
--> $DIR/empty-match-check-notes.rs:17:9
33
|
44
LL | _ => {}
5-
| ^
5+
| ^ matches no values because `EmptyEnum` is uninhabited
66
|
7-
= note: matches no values because `EmptyEnum` is uninhabited
87
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types
98
note: the lint level is defined here
109
--> $DIR/empty-match-check-notes.rs:7:9
@@ -16,27 +15,24 @@ error: unreachable pattern
1615
--> $DIR/empty-match-check-notes.rs:22:9
1716
|
1817
LL | _ if false => {}
19-
| ^
18+
| ^ matches no values because `EmptyEnum` is uninhabited
2019
|
21-
= note: matches no values because `EmptyEnum` is uninhabited
2220
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types
2321

2422
error: unreachable pattern
2523
--> $DIR/empty-match-check-notes.rs:31:9
2624
|
2725
LL | _ => {}
28-
| ^
26+
| ^ matches no values because `EmptyForeignEnum` is uninhabited
2927
|
30-
= note: matches no values because `EmptyForeignEnum` is uninhabited
3128
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types
3229

3330
error: unreachable pattern
3431
--> $DIR/empty-match-check-notes.rs:36:9
3532
|
3633
LL | _ if false => {}
37-
| ^
34+
| ^ matches no values because `EmptyForeignEnum` is uninhabited
3835
|
39-
= note: matches no values because `EmptyForeignEnum` is uninhabited
4036
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types
4137

4238
error[E0005]: refutable pattern in local binding

tests/ui/pattern/usefulness/empty-match-check-notes.normal.stderr

+4-8
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ error: unreachable pattern
22
--> $DIR/empty-match-check-notes.rs:17:9
33
|
44
LL | _ => {}
5-
| ^
5+
| ^ matches no values because `EmptyEnum` is uninhabited
66
|
7-
= note: matches no values because `EmptyEnum` is uninhabited
87
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types
98
note: the lint level is defined here
109
--> $DIR/empty-match-check-notes.rs:7:9
@@ -16,27 +15,24 @@ error: unreachable pattern
1615
--> $DIR/empty-match-check-notes.rs:22:9
1716
|
1817
LL | _ if false => {}
19-
| ^
18+
| ^ matches no values because `EmptyEnum` is uninhabited
2019
|
21-
= note: matches no values because `EmptyEnum` is uninhabited
2220
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types
2321

2422
error: unreachable pattern
2523
--> $DIR/empty-match-check-notes.rs:31:9
2624
|
2725
LL | _ => {}
28-
| ^
26+
| ^ matches no values because `EmptyForeignEnum` is uninhabited
2927
|
30-
= note: matches no values because `EmptyForeignEnum` is uninhabited
3128
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types
3229

3330
error: unreachable pattern
3431
--> $DIR/empty-match-check-notes.rs:36:9
3532
|
3633
LL | _ if false => {}
37-
| ^
34+
| ^ matches no values because `EmptyForeignEnum` is uninhabited
3835
|
39-
= note: matches no values because `EmptyForeignEnum` is uninhabited
4036
= note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types
4137

4238
error[E0005]: refutable pattern in local binding

0 commit comments

Comments
 (0)