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

False positive: match_same_arms const #2427

Closed
alexheretic opened this issue Feb 1, 2018 · 2 comments
Closed

False positive: match_same_arms const #2427

alexheretic opened this issue Feb 1, 2018 · 2 comments
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy

Comments

@alexheretic
Copy link
Member

Similar to #2420, just because a const is the same value this compilation doesn't mean it's the same thing.

const PRICE_OF_SWEETS: u32 = 5;
const PRICE_OF_KINDNESS: u32 = 0;
const PRICE_OF_DRINKS: u32 = 5;

fn price(thing: &str) -> u32 {
    match thing {
        "rolo" => PRICE_OF_SWEETS,
        "advice" => PRICE_OF_KINDNESS,
        "juice" => PRICE_OF_DRINKS,
        _ => panic!()
    }
}
warning: this `match` has identical arm bodies
  --> src/main.rs:16:20
   |
16 |         "juice" => PRICE_OF_DRINKS,
   |                    ^^^^^^^^^^^^^^^
   |
   = note: #[warn(match_same_arms)] on by default
note: same as this
  --> src/main.rs:14:19
   |
14 |         "rolo" => PRICE_OF_SWEETS,
   |                   ^^^^^^^^^^^^^^^
note: consider refactoring into `"rolo" | "juice"`
  --> src/main.rs:14:19
   |
14 |         "rolo" => PRICE_OF_SWEETS,
   |                   ^^^^^^^^^^^^^^^
   = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.184/index.html#match_same_arms
@oli-obk oli-obk added C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy labels Feb 8, 2018
@oli-obk
Copy link
Contributor

oli-obk commented Feb 8, 2018

Our const evaluator has a bool flag that makes it treat constants as black boxes. We just need to turn it on for this check.

oli-obk added a commit that referenced this issue Feb 9, 2018
@oli-obk oli-obk closed this as completed in ff32d5f Feb 9, 2018
@8573
Copy link

8573 commented Jul 21, 2020

Are this and #2185 duplicates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

No branches or pull requests

3 participants