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

redundant_pattern_matching shouldn't complain about macro generated redundant patterns #6065

Closed
KamilaBorowska opened this issue Sep 18, 2020 · 0 comments · Fixed by #6069
Closed
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@KamilaBorowska
Copy link
Contributor

I tried this code:

fn main() {
    macro_rules! if_let_in_macro {
        ($pat:pat, $x:expr) => {
            if let Some($pat) = $x {}
        };
    }

    if_let_in_macro!(_, Some(42));
}

Macro is external to the crate in actual code.

I expected to see this happen: No complaints

Instead, this happened:

warning: redundant pattern matching, consider using `is_some()`
 --> src/main.rs:4:20
  |
4 |               if let Some($pat) = $x {}
  |  _____________-      ^^^^^^^^^^
5 | |         };
6 | |     }
7 | |
8 | |     if_let_in_macro!(_, Some(42));
  | |     ------------------------------
  | |_____|__________________________|
  |       |                          help: try this: `if Some(42).is_some()`
  |       in this macro invocation
  |
  = note: `#[warn(clippy::redundant_pattern_matching)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching
  = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

I believe this is wrong as it's not always fixable in macros

Meta

  • cargo clippy -V: clippy 0.0.212 (f3c923a 2020-09-17)
  • rustc -Vv:
    rustc 1.48.0-nightly (f3c923a13 2020-09-17)
    binary: rustc
    commit-hash: f3c923a13a458c35ee26b3513533fce8a15c9c05
    commit-date: 2020-09-17
    host: x86_64-unknown-linux-gnu
    release: 1.48.0-nightly
    LLVM version: 11.0
    
Backtrace

<backtrace>

@KamilaBorowska KamilaBorowska added the C-bug Category: Clippy is not doing the correct thing label Sep 18, 2020
@bors bors closed this as completed in 29b12f2 Sep 22, 2020
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant