Skip to content

detect if comparison chain that could be a tuple comparison instead #1111

Open
@MBons

Description

@MBons

The if_same_then_else lint triggered on the following code I use to sort some stuff:

positions.sort_by(|&(x1, y1, z1), &(x2, y2, z2)| {
    use std::cmp::Ordering::*;
    if z1 < z2 {
        Less
    } else if z1 > z2 {
        Greater
    } else if x1 > x2 {
        Less
    } else if x1 < x2 {
        Greater
    } else if y1 < y2 {
        Less
    } else {
        Greater
    }
});

I'm not sure if Clippy could reason about this or if it's even worth the trouble thinking about that but perhaps this is worthy of a footnote in the wiki?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.L-styleLint: Belongs in the style lint group

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions