Skip to content

collapsible_match suggestion changes behaviour #6740

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

Closed
glts opened this issue Feb 14, 2021 · 0 comments · Fixed by #6754
Closed

collapsible_match suggestion changes behaviour #6740

glts opened this issue Feb 14, 2021 · 0 comments · Fixed by #6754
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@glts
Copy link

glts commented Feb 14, 2021

Lint name: collapsible_match

Clippy suggests collapsing the nested match in the following code snippet (the full code is here):

pub fn focus_error(error: &ConfigError) -> &dyn Error {
    match error {
        ConfigError::ReadConfig(e) => match e {
            ReadConfigError::Parse(e) => e,
            e => e,
        },
        e => e,
    }
}

I expected to see this happen: no Clippy warning

Instead, this happened:

warning: Unnecessary nested match
   --> src/config/read.rs:293:39
    |
293 |           ConfigError::ReadConfig(e) => match e {
    |  _______________________________________^
294 | |             ReadConfigError::Parse(e) => e,
295 | |             e => e,
296 | |         },
    | |_________^
    |
    = note: `#[warn(clippy::collapsible_match)]` on by default
help: The outer pattern can be modified to include the inner pattern.
   --> src/config/read.rs:293:33
    |
293 |         ConfigError::ReadConfig(e) => match e {
    |                                 ^ Replace this binding
294 |             ReadConfigError::Parse(e) => e,
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^ with this pattern
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_match

This suggestion is invalid. It changes the type of the error object is returned and noticeably changes the behaviour of the code (in this case the error message printed to the command-line changes).

Meta

  • cargo clippy -V: clippy 0.0.212 (cb75ad5 2021-02-10)
  • rustc -Vv:
    rustc 1.50.0 (cb75ad5db 2021-02-10)
    binary: rustc
    commit-hash: cb75ad5db02783e8b0222fee363c5f63f7e2cf5b
    commit-date: 2021-02-10
    host: x86_64-unknown-linux-gnu
    release: 1.50.0
    
@glts glts added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Feb 14, 2021
@camsteffen camsteffen added the good-first-issue These issues are a good way to get started with Clippy label Feb 16, 2021
camsteffen added a commit to camsteffen/rust-clippy that referenced this issue Feb 16, 2021
@bors bors closed this as completed in d2ddf9c Feb 21, 2021
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 good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants