Skip to content

Commit 0e675b2

Browse files
authored
Rollup merge of rust-lang#146745 - helldawg:master, r=workingjubilee
Clarified error note for usize range matching Fixes rust-lang#146476 This is kinda rough, but it gets the point across a little better and stays short.
2 parents 2fd7851 + 7e58c91 commit 0e675b2

File tree

7 files changed

+31
-31
lines changed

7 files changed

+31
-31
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,13 +1275,13 @@ fn report_non_exhaustive_match<'p, 'tcx>(
12751275
if ty.is_ptr_sized_integral() {
12761276
if ty.inner() == cx.tcx.types.usize {
12771277
err.note(format!(
1278-
"`{ty}` does not have a fixed maximum value, so half-open ranges are \
1279-
necessary to match exhaustively",
1278+
"`{ty}::MAX` is not treated as exhaustive, \
1279+
so half-open ranges are necessary to match exhaustively",
12801280
));
12811281
} else if ty.inner() == cx.tcx.types.isize {
12821282
err.note(format!(
1283-
"`{ty}` does not have fixed minimum and maximum values, so half-open \
1284-
ranges are necessary to match exhaustively",
1283+
"`{ty}::MIN` and `{ty}::MAX` are not treated as exhaustive, \
1284+
so half-open ranges are necessary to match exhaustively",
12851285
));
12861286
}
12871287
} else if ty.inner() == cx.tcx.types.str_ {

tests/ui/feature-gates/feature-gate-precise_pointer_size_matching.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ fn main() {
33
//~^ ERROR non-exhaustive patterns: `usize::MAX..` not covered
44
//~| NOTE pattern `usize::MAX..` not covered
55
//~| NOTE the matched value is of type `usize`
6-
//~| NOTE `usize` does not have a fixed maximum value
6+
//~| NOTE `usize::MAX` is not treated as exhaustive, so half-open ranges are necessary to match exhaustively
77
0..=usize::MAX => {}
88
}
99

1010
match 0isize {
1111
//~^ ERROR non-exhaustive patterns: `..isize::MIN` and `isize::MAX..` not covered
1212
//~| NOTE patterns `..isize::MIN` and `isize::MAX..` not covered
1313
//~| NOTE the matched value is of type `isize`
14-
//~| NOTE `isize` does not have fixed minimum and maximum values
14+
//~| NOTE `isize::MIN` and `isize::MAX` are not treated as exhaustive, so half-open ranges are necessary to match exhaustively
1515
isize::MIN..=isize::MAX => {}
1616
}
1717
}

tests/ui/feature-gates/feature-gate-precise_pointer_size_matching.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | match 0usize {
55
| ^^^^^^ pattern `usize::MAX..` not covered
66
|
77
= note: the matched value is of type `usize`
8-
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
8+
= note: `usize::MAX` is not treated as exhaustive, so half-open ranges are necessary to match exhaustively
99
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
1010
|
1111
LL ~ 0..=usize::MAX => {},
@@ -19,7 +19,7 @@ LL | match 0isize {
1919
| ^^^^^^ patterns `..isize::MIN` and `isize::MAX..` not covered
2020
|
2121
= note: the matched value is of type `isize`
22-
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
22+
= note: `isize::MIN` and `isize::MAX` are not treated as exhaustive, so half-open ranges are necessary to match exhaustively
2323
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
2424
|
2525
LL ~ isize::MIN..=isize::MAX => {},

tests/ui/pattern/usefulness/integer-ranges/pointer-sized-int.deny.stderr

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | match 0usize {
55
| ^^^^^^ pattern `usize::MAX..` not covered
66
|
77
= note: the matched value is of type `usize`
8-
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
8+
= note: `usize::MAX` is not treated as exhaustive, so half-open ranges are necessary to match exhaustively
99
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
1010
|
1111
LL ~ 0..=usize::MAX => {},
@@ -19,7 +19,7 @@ LL | match 0isize {
1919
| ^^^^^^ patterns `..isize::MIN` and `isize::MAX..` not covered
2020
|
2121
= note: the matched value is of type `isize`
22-
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
22+
= note: `isize::MIN` and `isize::MAX` are not treated as exhaustive, so half-open ranges are necessary to match exhaustively
2323
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
2424
|
2525
LL ~ isize::MIN..=isize::MAX => {},
@@ -33,7 +33,7 @@ LL | m!(0usize, 0..=usize::MAX);
3333
| ^^^^^^ pattern `usize::MAX..` not covered
3434
|
3535
= note: the matched value is of type `usize`
36-
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
36+
= note: `usize::MAX` is not treated as exhaustive, so half-open ranges are necessary to match exhaustively
3737
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
3838
|
3939
LL | match $s { $($t)+ => {}, usize::MAX.. => todo!() }
@@ -46,7 +46,7 @@ LL | m!(0usize, 0..5 | 5..=usize::MAX);
4646
| ^^^^^^ pattern `usize::MAX..` not covered
4747
|
4848
= note: the matched value is of type `usize`
49-
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
49+
= note: `usize::MAX` is not treated as exhaustive, so half-open ranges are necessary to match exhaustively
5050
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
5151
|
5252
LL | match $s { $($t)+ => {}, usize::MAX.. => todo!() }
@@ -59,7 +59,7 @@ LL | m!(0usize, 0..usize::MAX | usize::MAX);
5959
| ^^^^^^ pattern `usize::MAX..` not covered
6060
|
6161
= note: the matched value is of type `usize`
62-
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
62+
= note: `usize::MAX` is not treated as exhaustive, so half-open ranges are necessary to match exhaustively
6363
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
6464
|
6565
LL | match $s { $($t)+ => {}, usize::MAX.. => todo!() }
@@ -72,7 +72,7 @@ LL | m!((0usize, true), (0..5, true) | (5..=usize::MAX, true) | (0..=usize::
7272
| ^^^^^^^^^^^^^^ pattern `(usize::MAX.., _)` not covered
7373
|
7474
= note: the matched value is of type `(usize, bool)`
75-
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
75+
= note: `usize::MAX` is not treated as exhaustive, so half-open ranges are necessary to match exhaustively
7676
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
7777
|
7878
LL | match $s { $($t)+ => {}, (usize::MAX.., _) => todo!() }
@@ -85,7 +85,7 @@ LL | m!(0isize, isize::MIN..=isize::MAX);
8585
| ^^^^^^ patterns `..isize::MIN` and `isize::MAX..` not covered
8686
|
8787
= note: the matched value is of type `isize`
88-
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
88+
= note: `isize::MIN` and `isize::MAX` are not treated as exhaustive, so half-open ranges are necessary to match exhaustively
8989
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
9090
|
9191
LL | match $s { $($t)+ => {}, ..isize::MIN | isize::MAX.. => todo!() }
@@ -98,7 +98,7 @@ LL | m!(0isize, isize::MIN..5 | 5..=isize::MAX);
9898
| ^^^^^^ patterns `..isize::MIN` and `isize::MAX..` not covered
9999
|
100100
= note: the matched value is of type `isize`
101-
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
101+
= note: `isize::MIN` and `isize::MAX` are not treated as exhaustive, so half-open ranges are necessary to match exhaustively
102102
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
103103
|
104104
LL | match $s { $($t)+ => {}, ..isize::MIN | isize::MAX.. => todo!() }
@@ -111,7 +111,7 @@ LL | m!(0isize, isize::MIN..=-1 | 0 | 1..=isize::MAX);
111111
| ^^^^^^ patterns `..isize::MIN` and `isize::MAX..` not covered
112112
|
113113
= note: the matched value is of type `isize`
114-
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
114+
= note: `isize::MIN` and `isize::MAX` are not treated as exhaustive, so half-open ranges are necessary to match exhaustively
115115
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
116116
|
117117
LL | match $s { $($t)+ => {}, ..isize::MIN | isize::MAX.. => todo!() }
@@ -124,7 +124,7 @@ LL | m!(0isize, isize::MIN..isize::MAX | isize::MAX);
124124
| ^^^^^^ patterns `..isize::MIN` and `isize::MAX..` not covered
125125
|
126126
= note: the matched value is of type `isize`
127-
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
127+
= note: `isize::MIN` and `isize::MAX` are not treated as exhaustive, so half-open ranges are necessary to match exhaustively
128128
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
129129
|
130130
LL | match $s { $($t)+ => {}, ..isize::MIN | isize::MAX.. => todo!() }
@@ -137,7 +137,7 @@ LL | (0isize, true),
137137
| ^^^^^^^^^^^^^^ patterns `(..isize::MIN, _)` and `(isize::MAX.., _)` not covered
138138
|
139139
= note: the matched value is of type `(isize, bool)`
140-
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
140+
= note: `isize::MIN` and `isize::MAX` are not treated as exhaustive, so half-open ranges are necessary to match exhaustively
141141
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
142142
|
143143
LL | match $s { $($t)+ => {}, (..isize::MIN, _) | (isize::MAX.., _) => todo!() }

tests/ui/pattern/usefulness/integer-ranges/precise_pointer_matching-message.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ fn main() {
44
//~^ ERROR non-exhaustive patterns: `usize::MAX..` not covered
55
//~| NOTE pattern `usize::MAX..` not covered
66
//~| NOTE the matched value is of type `usize`
7-
//~| NOTE `usize` does not have a fixed maximum value
7+
//~| NOTE `usize::MAX` is not treated as exhaustive, so half-open ranges are necessary to match exhaustively
88
0..=usize::MAX => {}
99
}
1010

1111
match 0isize {
1212
//~^ ERROR non-exhaustive patterns: `..isize::MIN` and `isize::MAX..` not covered
1313
//~| NOTE patterns `..isize::MIN` and `isize::MAX..` not covered
1414
//~| NOTE the matched value is of type `isize`
15-
//~| NOTE `isize` does not have fixed minimum and maximum values
15+
//~| NOTE `isize::MIN` and `isize::MAX` are not treated as exhaustive, so half-open ranges are necessary to match exhaustively
1616
isize::MIN..=isize::MAX => {}
1717
}
1818
}

tests/ui/pattern/usefulness/integer-ranges/precise_pointer_matching-message.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | match 0usize {
55
| ^^^^^^ pattern `usize::MAX..` not covered
66
|
77
= note: the matched value is of type `usize`
8-
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
8+
= note: `usize::MAX` is not treated as exhaustive, so half-open ranges are necessary to match exhaustively
99
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
1010
|
1111
LL ~ 0..=usize::MAX => {},
@@ -19,7 +19,7 @@ LL | match 0isize {
1919
| ^^^^^^ patterns `..isize::MIN` and `isize::MAX..` not covered
2020
|
2121
= note: the matched value is of type `isize`
22-
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
22+
= note: `isize::MIN` and `isize::MAX` are not treated as exhaustive, so half-open ranges are necessary to match exhaustively
2323
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
2424
|
2525
LL ~ isize::MIN..=isize::MAX => {},

tests/ui/pattern/usefulness/issue-85222-types-containing-non-exhaustive-types.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | match 0 {
55
| ^ pattern `usize::MAX..` not covered
66
|
77
= note: the matched value is of type `usize`
8-
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
8+
= note: `usize::MAX` is not treated as exhaustive, so half-open ranges are necessary to match exhaustively
99
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
1010
|
1111
LL ~ 1..=usize::MAX => (),
@@ -19,7 +19,7 @@ LL | match (0usize, 0usize) {
1919
| ^^^^^^^^^^^^^^^^ pattern `(usize::MAX.., _)` not covered
2020
|
2121
= note: the matched value is of type `(usize, usize)`
22-
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
22+
= note: `usize::MAX` is not treated as exhaustive, so half-open ranges are necessary to match exhaustively
2323
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
2424
|
2525
LL ~ (1..=usize::MAX, 1..=usize::MAX) => (),
@@ -33,7 +33,7 @@ LL | match (0isize, 0usize) {
3333
| ^^^^^^^^^^^^^^^^ patterns `(..isize::MIN, _)` and `(isize::MAX.., _)` not covered
3434
|
3535
= note: the matched value is of type `(isize, usize)`
36-
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
36+
= note: `isize::MIN` and `isize::MAX` are not treated as exhaustive, so half-open ranges are necessary to match exhaustively
3737
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
3838
|
3939
LL ~ (isize::MIN..=isize::MAX, 1..=usize::MAX) => (),
@@ -70,7 +70,7 @@ note: `Option<usize>` defined here
7070
|
7171
= note: not covered
7272
= note: the matched value is of type `Option<usize>`
73-
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
73+
= note: `usize::MAX` is not treated as exhaustive, so half-open ranges are necessary to match exhaustively
7474
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
7575
|
7676
LL ~ None => (),
@@ -93,7 +93,7 @@ note: `Option<Option<Option<usize>>>` defined here
9393
|
9494
= note: not covered
9595
= note: the matched value is of type `Option<Option<Option<usize>>>`
96-
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
96+
= note: `usize::MAX` is not treated as exhaustive, so half-open ranges are necessary to match exhaustively
9797
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
9898
|
9999
LL ~ None => (),
@@ -112,7 +112,7 @@ note: `A<usize>` defined here
112112
LL | struct A<T> {
113113
| ^
114114
= note: the matched value is of type `A<usize>`
115-
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
115+
= note: `usize::MAX` is not treated as exhaustive, so half-open ranges are necessary to match exhaustively
116116
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
117117
|
118118
LL ~ A { a: 1..=usize::MAX } => (),
@@ -131,7 +131,7 @@ note: `B<isize, usize>` defined here
131131
LL | struct B<T, U>(T, U);
132132
| ^
133133
= note: the matched value is of type `B<isize, usize>`
134-
= note: `isize` does not have fixed minimum and maximum values, so half-open ranges are necessary to match exhaustively
134+
= note: `isize::MIN` and `isize::MAX` are not treated as exhaustive, so half-open ranges are necessary to match exhaustively
135135
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
136136
|
137137
LL ~ B(isize::MIN..=isize::MAX, 1..=usize::MAX) => (),
@@ -150,7 +150,7 @@ note: `B<isize, usize>` defined here
150150
LL | struct B<T, U>(T, U);
151151
| ^
152152
= note: the matched value is of type `B<isize, usize>`
153-
= note: `usize` does not have a fixed maximum value, so half-open ranges are necessary to match exhaustively
153+
= note: `usize::MAX` is not treated as exhaustive, so half-open ranges are necessary to match exhaustively
154154
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
155155
|
156156
LL ~ B(_, 1..=usize::MAX) => (),

0 commit comments

Comments
 (0)