-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Closed
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.
Description
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:
match x {
x if f64::isNaN(x) => { ... }
...
}
For bonus points, the unmatchable case warning for NaN could mention this: "use isNaN in a guard expression instead".
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
emillon commentedon Jul 24, 2013
Hi,
I'm not sure what the "bad" way to match NaN would be. Since
NaN
is not a variant (it's just a constant defined as0.0/0.0
), matching against it (NaN => ...
) binds a new variable that shadows NaN. It's an irrefutable pattern so it will definitely be noticed. I may have overlooked something though.huonw commentedon Jul 24, 2013
@emillon it is a
static
, which are valid in patterns.emillon commentedon Jul 24, 2013
Oops, thanks the clarification. So the test case is:
Interesting project to dive in the compiler, let's see how it goes.
cscott commentedon Jul 24, 2013
Ideally nested uses of NaN will trigger the same error, ie:
Check for comparisons to NaN in patterns
auto merge of #8029 : emillon/rust/issue-6804, r=cmr
add back test for issue rust-lang#6804
Auto merge of rust-lang#7175 - camsteffen:filter-map-none, r=Manishearth