Skip to content

eq_op false positive with floats #1466

Open
@lukebitts

Description

@lukebitts

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

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions