Skip to content

FN single_match_else #3489

@matthiaskrgr

Description

@matthiaskrgr

clippy 0.0.212 (b2601be 2018-11-27)

I had this code which did not trigger any lints:

    let input = match directory {
        Some(value) => value,
        None => {
            return Err((
                ErrorKind::RemoveDirNoArg,
                "No argument assigned to --remove-dir, example: 'git-repos,registry-sources'"
                    .to_string(),
            ))
        }
    };

After applying rustfmt, an additional ; was added:

    let input = match directory {
        Some(value) => value,
        None => {
            return Err((
                ErrorKind::RemoveDirNoArg,
                "No argument assigned to --remove-dir, example: 'git-repos,registry-sources'"
                    .to_string(),
            ));                                   // <--------- HERE
        }
    };

which caused clippy::single_match_else to trigger.

warning: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`
   --> src/library.rs:432:17
    |
432 |       let input = match directory {
    |  _________________^
433 | |         Some(value) => value,
434 | |         None => {
435 | |             return Err((
...   |
440 | |         }
441 | |     };
    | |_____^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else
help: try this
    |
432 |     let input = if let Some(value) = directory { value } else {
433 |     return Err((
434 |         ErrorKind::RemoveDirNoArg,
435 |         "No argument assigned to --remove-dir, example: 'git-repos,registry-sources'"
436 |             .to_string(),
437 |     ));
  ...

I think the link should also trigger on the unformatted example!

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions