Skip to content

Wrong suggestion from single_match #1404

Closed
@killercup

Description

@killercup

I'm trying to add clippy to diesel (again), and just got this:

error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`
   --> /Users/pascal/Projekte/tools/diesel/diesel/src/types/impls/tuples.rs:145:25
    |
145 |                           match self.$idx {
    |  _________________________^ starting here...
146 | |                             ColumnInsertValue::Expression(_, ref value) => {
147 | |                                 try!(value.collect_binds(out));
148 | |                             }
149 | |                             _ => {}
150 | |                         }
    | |_________________________^ ...ending here
...
296 |   tuple_impls! {
    |   - in this macro invocation
    |
note: lint level defined here
   --> /Users/pascal/Projekte/tools/diesel/diesel/src/lib.rs:7:9
    |
7   | #![deny(warnings, missing_debug_implementations, missing_copy_implementations)]
    |         ^^^^^^^^
help: try this
    |                         if let ColumnInsertValue::Expression(_, ref value) = self.$idx {
    |                             ColumnInsertValue::Expression(_, ref value) => {
    |                                 try!(value.collect_binds(out));
    |                             }
    |                             _ => {}
    |                         }
...
    = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#single_match

The suggestion contains the correct line for if-let itself, but the body is an exact copy of the match arms, not the expression on the right side of the single match arm.

The correct suggestion would be:

if let ColumnInsertValue::Expression(_, ref value) = self.$idx {
    try!(value.collect_binds(out));
}

As you can see, this is inside a macro. I can try to make a smaller example to reproduce this if you want.

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingT-macrosType: Issues with macros and macro expansiongood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions