Skip to content

Incorrect macro handling in match_single_binding #14634

@samueltardieu

Description

@samueltardieu

Summary

match_single_binding doesn't handle macros either in the scrutinee or in the pattern.

Reproducer

I tried this code:

#![deny(clippy::match_single_binding)]

fn main() {
    macro_rules! id {
        ($i:ident) => { $i };
    }
    match dbg!(3) {
        _ => ()
    }
    match dbg!(3) {
        id!(a) => ()
    }
}

I expected to see this happen: non-expanded suggestions

Instead, this happened:

error: this match could be replaced by its scrutinee and body
 --> t.rs:7:5
  |
7 | /     match dbg!(3) {
8 | |         _ => ()
9 | |     }
  | |_____^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_single_binding
note: the lint level is defined here
 --> t.rs:1:9
  |
1 | #![deny(clippy::match_single_binding)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider using the scrutinee and body instead
  |
7 ~     match $val {
8 +             tmp => {
9 +                 $crate::eprintln!("[{}:{}:{}] {} = {:#?}",
10+                     $crate::file!(), $crate::line!(), $crate::column!(), $crate::stringify!($val), &tmp);
11+                 tmp
12+             }
13+         };
14+     ();
  |

error: this match could be written as a `let` statement
  --> t.rs:10:5
   |
10 | /     match dbg!(3) {
11 | |         id!(_a) => ()
12 | |     }
   | |_____^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_single_binding
help: consider using a `let` statement
   |
10 ~     let $i = match $val {
11 +             tmp => {
12 +                 $crate::eprintln!("[{}:{}:{}] {} = {:#?}",
13 +                     $crate::file!(), $crate::line!(), $crate::column!(), $crate::stringify!($val), &tmp);
14 +                 tmp
15 +             }
16 +         };
17 +     ()
   |

error: aborting due to 2 previous errors

Version


Additional Labels

@rustbot claim
@rustbot label +Isuggestion-causes-error

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions