-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Add check for overlapping ranges to unreachable patterns lint #64007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
91a3db9
Add check for overlapping ranges to unreachable patterns lint
estebank 220b9b2
Move overlapping patterns to its own lint
estebank 916936c
Silence lint in `fit_signed` and `fit_unsigned`
estebank d2cb5a8
Move lint emitter to its own method
estebank be9e6af
review comments: use if let
estebank 1ec6073
Deduplicate code for formatting `RangeEnd`
estebank 6832da8
rename method
estebank 89b19cc
Continue to emit unreachable pattern on cases caught by overlapping p…
estebank 73d6efc
Only emit overlapping patterns lint if the overlap is partial
estebank 593cdcc
Lint only on single element overlap
estebank File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Add check for overlapping ranges to unreachable patterns lint
- Loading branch information
commit 91a3db95a1a5939054d72d2ce69c5647c3cfb93b
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,41 @@ | ||
//error-pattern: unreachable | ||
//error-pattern: unreachable | ||
//error-pattern: unreachable | ||
//error-pattern: unreachable | ||
//error-pattern: unreachable | ||
|
||
#![deny(unreachable_patterns)] | ||
|
||
fn main() { | ||
match 5 { | ||
1 ..= 10 => { } | ||
5 ..= 6 => { } | ||
5 ..= 6 => { } //~ ERROR multiple patterns covering the same range | ||
_ => {} | ||
}; | ||
|
||
match 5 { | ||
3 ..= 6 => { } | ||
4 ..= 6 => { } | ||
4 ..= 6 => { } //~ ERROR multiple patterns covering the same range | ||
_ => {} | ||
}; | ||
|
||
match 5 { | ||
4 ..= 6 => { } | ||
4 ..= 6 => { } | ||
4 ..= 6 => { } //~ ERROR multiple patterns covering the same range | ||
_ => {} | ||
}; | ||
|
||
match 'c' { | ||
'A' ..= 'z' => {} | ||
'a' ..= 'z' => {} | ||
'a' ..= 'z' => {} //~ ERROR multiple patterns covering the same range | ||
_ => {} | ||
}; | ||
|
||
match 1.0f64 { | ||
0.01f64 ..= 6.5f64 => {} | ||
0.02f64 => {} | ||
//~^ WARNING floating-point types cannot be used in patterns | ||
//~| WARNING floating-point types cannot be used in patterns | ||
//~| WARNING floating-point types cannot be used in patterns | ||
//~| WARNING this was previously accepted by the compiler | ||
//~| WARNING this was previously accepted by the compiler | ||
//~| WARNING this was previously accepted by the compiler | ||
0.02f64 => {} //~ ERROR unreachable pattern | ||
//~^ WARNING floating-point types cannot be used in patterns | ||
//~| WARNING this was previously accepted by the compiler | ||
_ => {} | ||
}; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.