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

Invalid suggestion for single_match #810

Closed
Keats opened this issue Mar 29, 2016 · 2 comments
Closed

Invalid suggestion for single_match #810

Keats opened this issue Mar 29, 2016 · 2 comments
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@Keats
Copy link

Keats commented Mar 29, 2016

It gives me the following:

src/lib.rs:112:17: 115:18 warning: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`, #[warn(single_match)] on by default
src/lib.rs:112                 match self.$field_name {
src/lib.rs:113                     Some(ref value) => { d.insert(stringify!($field_name).to_string(), value.to_json()); },
src/lib.rs:114                     None => {},
src/lib.rs:115                 }
src/lib.rs:118:9: 118:24 note: in this expansion of optional! (defined in src/lib.rs)
src/lib.rs:112:17: 115:18 help: try this
src/lib.rs:                    if let Some(ref value) = self.$field_name {
src/lib.rs:                        Some(ref value) => { d.insert(stringify!($field_name).to_string(), value.to_json()); },
src/lib.rs:                        None => {},
src/lib.rs:                    }
src/lib.rs:                )
src/lib.rs:            }

while the suggestion should be (afaik):

                if let Some(ref value) = self.$field_name {
                    d.insert(stringify!($field_name).to_string(), value.to_json());
                }
@mcarton
Copy link
Member

mcarton commented Mar 29, 2016

Weird, probably because of the macro, we get the span wrong.

@mcarton mcarton added the C-bug Category: Clippy is not doing the correct thing label Mar 29, 2016
@phansch
Copy link
Member

phansch commented Apr 25, 2020

Going to close this in favor of #1404 since it's most likely the same issue and has some more code examples.

@phansch phansch closed this as completed Apr 25, 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

No branches or pull requests

3 participants