diff options
| author | bors <bors@rust-lang.org> | 2020-11-29 18:50:19 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-11-29 18:50:19 +0000 |
| commit | b776d1c3e3db8befabb123ebb1e46c3531eaed46 (patch) | |
| tree | d3c1f37d4299d77cc8f07ba017b07c4625ec492f /src | |
| parent | 88b81970ba7a989a728b32039dd075dc206f1360 (diff) | |
| parent | bdd2bdb53beebe86fdfa91e845bd176bf7e55ef3 (diff) | |
| download | rust-b776d1c3e3db8befabb123ebb1e46c3531eaed46.tar.gz rust-b776d1c3e3db8befabb123ebb1e46c3531eaed46.zip | |
Auto merge of #79523 - Nadrieril:fix-usize-ranges, r=varkor
Fix overlap detection of `usize`/`isize` range patterns
`usize` and `isize` are a bit of a special case in the match usefulness algorithm, because the range of values they contain depends on the platform. Specifically, we don't want `0..usize::MAX` to count as an exhaustive match (see also [`precise_pointer_size_matching`](https://github.com/rust-lang/rust/issues/56354)). The way this was initially implemented is by treating those ranges like float ranges, i.e. with limited cleverness. This means we didn't catch the following as unreachable:
```rust
match 0usize {
0..10 => {},
10..20 => {},
5..15 => {}, // oops, should be detected as unreachable
_ => {},
}
```
This PRs fixes this oversight. Now the only difference between `usize` and `u64` range patterns is in what ranges count as exhaustive.
r? `@varkor`
`@rustbot` label +A-exhaustiveness-checking
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/pattern/usefulness/integer-ranges/reachability.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/pattern/usefulness/integer-ranges/reachability.stderr | 8 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/test/ui/pattern/usefulness/integer-ranges/reachability.rs b/src/test/ui/pattern/usefulness/integer-ranges/reachability.rs index 9078e65f667..6516925e939 100644 --- a/src/test/ui/pattern/usefulness/integer-ranges/reachability.rs +++ b/src/test/ui/pattern/usefulness/integer-ranges/reachability.rs @@ -72,7 +72,7 @@ fn main() { match 0usize { 0..10 => {}, 10..20 => {}, - 5..15 => {}, // FIXME: should be unreachable + 5..15 => {}, //~ ERROR unreachable pattern _ => {}, } // Chars between '\u{D7FF}' and '\u{E000}' are invalid even though ranges that contain them are diff --git a/src/test/ui/pattern/usefulness/integer-ranges/reachability.stderr b/src/test/ui/pattern/usefulness/integer-ranges/reachability.stderr index 8baf0d50c88..e6878d950d6 100644 --- a/src/test/ui/pattern/usefulness/integer-ranges/reachability.stderr +++ b/src/test/ui/pattern/usefulness/integer-ranges/reachability.stderr @@ -125,6 +125,12 @@ LL | 5..25 => {}, | ^^^^^ error: unreachable pattern + --> $DIR/reachability.rs:75:9 + | +LL | 5..15 => {}, + | ^^^^^ + +error: unreachable pattern --> $DIR/reachability.rs:82:9 | LL | '\u{D7FF}'..='\u{E000}' => {}, @@ -142,5 +148,5 @@ error: unreachable pattern LL | BAR => {} | ^^^ -error: aborting due to 23 previous errors +error: aborting due to 24 previous errors |
