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

needless_match mistakenly evaluates match as no-op #8599

Closed
rdrpenguin04 opened this issue Mar 28, 2022 · 0 comments · Fixed by #8549
Closed

needless_match mistakenly evaluates match as no-op #8599

rdrpenguin04 opened this issue Mar 28, 2022 · 0 comments · Fixed by #8549
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@rdrpenguin04
Copy link

Summary

In a standard library implementation I'm helping with, we have a replacement for Result::as_mut. We implemented it using match ergonomics, and it looks like a no-op because of that. Apparently, Clippy agrees.

Lint Name

needless_match

Reproducer

I tried this code:

pub fn as_mut(&mut self) -> Result<&mut T, &mut E> {
    match self {
        Ok(x) => Ok(x),
        Err(e) => Err(e),
    }
}

I saw this happen:

error: this match expression is unnecessary
  --> xlang/xlang_abi/src/result.rs:84:9
   |
84 | /         match self {
85 | |             Ok(x) => Ok(x),
86 | |             Err(e) => Err(e),
87 | |         }
   | |_________^ help: replace it with: `self`

I expected to see this happen:

Either a valid suggestion or a lack of a lint.

Version

rustc 1.61.0-nightly (1d9c262ee 2022-03-26)
binary: rustc
commit-hash: 1d9c262eea411ec5230f8a4c9ba50b3647064da4
commit-date: 2022-03-26
host: x86_64-unknown-linux-gnu
release: 1.61.0-nightly
LLVM version: 14.0.0

Additional Labels

@rustbot label +I-suggestion-causes-error

@rdrpenguin04 rdrpenguin04 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 Mar 28, 2022
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Mar 28, 2022
@bors bors closed this as completed in 81e004a Apr 6, 2022
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 I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants