-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Warn for unmatchable NaN case. #6804
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Hi, I'm not sure what the "bad" way to match NaN would be. Since |
@emillon it is a |
Oops, thanks the clarification. So the test case is:
Interesting project to dive in the compiler, let's see how it goes. |
Ideally nested uses of NaN will trigger the same error, ie: match vector {
(NaN, _) => true,
_ => false
} |
Hi, As noted in #6804, a pattern that contains `NaN` will never match because `NaN != NaN`. This adds a warning for such a case. The first commit handles the basic case and the second one generalizes it to more complex patterns using `walk_pat`.
Fix unnecessary_filter_map false positive changelog: Fix an [`unnecessary_filter_map`] false positive Fixes rust-lang#6804
Rust already warns for unmatchable cases in a match expression. Since NaN != NaN, any use of NaN (f64, float, other?) in a match pattern should generate the same unmatchable case warning.
If the reader is curious, the proper way to match NaN is something like:
For bonus points, the unmatchable case warning for NaN could mention this: "use isNaN in a guard expression instead".
The text was updated successfully, but these errors were encountered: