Skip to content

match_same_arms: suppress when reordering arms? #1140

Closed
@birkenfeld

Description

@birkenfeld

match_same_arms will not consider the order of match arms.

Since it is specified that arms are checked in order, this leads to suggestions with two potential problems:

  • less optimal performance, when expensive arm conditions are checked too early
  • changes in semantics

Example for the latter:

fn main() {
    let x = match 2 {
        1 ... 3 => false,
        0 ... 5 => true,
        _ => false
    };
}

If this seems bad anyway because of overlap, consider the slightly more complex

fn main() {
    let y = 1;
    let x = match 2 {
        1 ... 3 => false,
        0 ... 5 if y == 2 => true,
        _ => false
    };
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions