-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
Consider the following function:
fn nan_test() -> bool {
let v = std::f32::NAN;
v != v //warning: equal expressions as operands to `!=`
}
The eq_op
warning is wrong here since floats only implement PartialOrd
and doing v != v
allows me to detect them in a generic context:
fn max<T: PartialOrd>(v1: T, v2: T) -> T {
if v2 != v2 { v2 }
else if v2 > v1 { v2 } else { v1 }
}
Maybe a solution is to check whether the result of the expression returns something that implements Ord
or not?
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have