diff options
| author | bors <bors@rust-lang.org> | 2024-03-09 03:49:01 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-03-09 03:49:01 +0000 |
| commit | 1b427b3bf79c2cd48c75915301be3b009b82dea3 (patch) | |
| tree | 3567f55ab86ee59c0a67343c4d1749c01d5b0226 /compiler/rustc_interface/src/queries.rs | |
| parent | 4d4bb491b65c300835442f6cb4f34fc9a5685c26 (diff) | |
| parent | 8ac9a04257f73d9861625816d4c741096dd69c67 (diff) | |
| download | rust-1b427b3bf79c2cd48c75915301be3b009b82dea3.tar.gz rust-1b427b3bf79c2cd48c75915301be3b009b82dea3.zip | |
Auto merge of #118879 - Nadrieril:lint-range-gap, r=estebank
Lint singleton gaps after exclusive ranges
In the discussion to stabilize exclusive range patterns (https://github.com/rust-lang/rust/issues/37854), it has often come up that they're likely to cause off-by-one mistakes. We already have the `overlapping_range_endpoints` lint, so I [proposed](https://github.com/rust-lang/rust/issues/37854#issuecomment-1845580712) a lint to catch the complementary mistake.
This PR adds a new `non_contiguous_range_endpoints` lint that catches likely off-by-one errors with exclusive range patterns. Here's the idea (see the test file for more examples):
```rust
match x {
0..10 => ..., // WARN: this range doesn't match `10_u8` because `..` is an exclusive range
11..20 => ..., // this could appear to continue range `0_u8..10_u8`, but `10_u8` isn't matched by either of them
_ => ...,
}
// help: use an inclusive range instead: `0_u8..=10_u8`
```
More precisely: for any exclusive range `lo..hi`, if `hi+1` is matched by another range but `hi` isn't, we suggest writing an inclusive range `lo..=hi` instead. We also catch `lo..T::MAX`.
Diffstat (limited to 'compiler/rustc_interface/src/queries.rs')
0 files changed, 0 insertions, 0 deletions
