Skip to content

False positive with match_on_same_arms and macros #1390

Closed
@jugglerchris

Description

@jugglerchris

Hi,

I have a trace macro which normally expands to nothing, but can be turned on by a Cargo feature. I get match_same_arms warning on a case like this:

macro_rules! trace {
    ($e:expr) => ()
}

pub enum Foo { A, B, C }
use Foo::*;

pub fn test(x: Foo) {
    match x {
        A => { println!("something"); },
        B => { trace!("Got B"); },
        _ => {},
    }
}

which gives the following warning:

warning: this `match` has identical arm bodies, #[warn(match_same_arms)] on by default
  --> src/lib.rs:15:14
   |
15 |         _ => {},
   |              ^^
   |
note: same as this
  --> src/lib.rs:14:14
   |
14 |         B => { trace!("Got B"); },
   |              ^^^^^^^^^^^^^^^^^^^^
note: `B` has the same arm body as the `_` wildcard, consider removing it`
  --> src/lib.rs:14:14
   |
14 |         B => { trace!("Got B"); },
   |              ^^^^^^^^^^^^^^^^^^^^
   = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#match_same_arms

In some sense they expand to the same, but they're not the same to me the programmer; when I turn on a feature the tracing becomes more useful.

Playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=929ad50b7c6d82e2df6bf3a8cbd7a944

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-an-interesting-projectCategory: Interesting projects, that usually are more involved design/code wise.C-bugCategory: Clippy is not doing the correct thingE-hardCall for participation: This a hard problem and requires more experience or effort to work onI-false-positiveIssue: The lint was triggered on code it shouldn't haveT-middleType: Probably requires verifiying types

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions