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

clippy::option-if-let-else suggests a worse code. #7006

Closed
fxdave opened this issue Mar 30, 2021 · 3 comments · Fixed by #7216
Closed

clippy::option-if-let-else suggests a worse code. #7006

fxdave opened this issue Mar 30, 2021 · 3 comments · Fixed by #7216
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

@fxdave
Copy link

fxdave commented Mar 30, 2021

Lint name: clippy::option-if-let-else

I tried this code:

if let Some(draggable) = utils::dom::find(target, "draggable") {
    // some code
} else if let Some(relation) = utils::dom::find(target, "relation") {
    // some code
} else {
    // some code
}

I expected to see no errors.

Instead, this happened:

error: use Option::map_or instead of an if let/else
  --> src/components/viewport/mod.rs:78:12
   |
78 |       } else if let Some(relation) = utils::dom::find(target, "relation") {
   |  ____________^
...  |
90 | |     }
   | |_____^
   |
   = note: `-D clippy::option-if-let-else` implied by `-D clippy::pedantic`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#option_if_let_else
help: try
   |
78 |     } else { utils::dom::find(target, "relation").map_or(
              // some code,
               |relation| {
82 |         // some code

Meta

  • cargo clippy -V: clippy 0.1.53 (4a20eb6 2021-03-28)
  • rustc -Vv:
    rustc 1.53.0-nightly (4a20eb6a9 2021-03-28)
    binary: rustc
    commit-hash: 4a20eb6a9da36c88ee929826c4f1eb8d7ea393b2
    commit-date: 2021-03-28
    host: x86_64-unknown-linux-gnu
    release: 1.53.0-nightly
    LLVM version: 12.0.0
    
@fxdave fxdave 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 30, 2021
@magurotuna
Copy link
Contributor

So do you mean that the suggested code works fine but feels worse than your original code, right?

@fxdave
Copy link
Author

fxdave commented Mar 31, 2021

Yes

@camsteffen camsteffen added the good-first-issue These issues are a good way to get started with Clippy label May 3, 2021
@camsteffen
Copy link
Contributor

Yeah...I'd be inclined to just never lint else if let.

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.

3 participants