Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

match_same_arms: suppress when reordering arms? #1140

Closed
birkenfeld opened this issue Aug 5, 2016 · 2 comments · Fixed by #8232
Closed

match_same_arms: suppress when reordering arms? #1140

birkenfeld opened this issue Aug 5, 2016 · 2 comments · Fixed by #8232

Comments

@birkenfeld
Copy link
Contributor

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
    };
}
@oli-obk
Copy link
Contributor

oli-obk commented Aug 5, 2016

We can try to analyze whether order changes don't change semantics. A simple analysis would probably assume that only the order of different enum variants is irrelevant or the order of non overlapping int patterns

@Arnavion
Copy link
Contributor

Duplicate of #860, though that one initially meandered into an unrelated discussion and this one has a more realistic example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants