Skip to content

Wrong similar code lint #6039

Closed
Closed
@leonardo-m

Description

@leonardo-m

This is a very common type of bugs that I'd like Clippy to catch (clippy::correctness), I think it's too much to ask rustc to do this:

struct Vec3 { x: f64, y: f64, z: f64 }

impl Eq for Vec3 {}

impl PartialEq for Vec3 {
    fn eq(&self, other: &Self) -> bool {
        self.x == other.y && self.y == other.y && self.z == other.z
    }
}

fn main() {}

For C++ similar to that Rust code PVS-Studio gives the error:

V1013 Suspicious subexpression a.x == b.y in a sequence of similar comparisons. vec3.h 182

I predict that if you implement a similar lint in a reasonable way then people that use Clippy regularly will suddenly find several new bugs in their code :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions