-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
New lint: map_unwrap_or_bool #5895
Comments
Hmm, that doesn't quite work, does it? Surely there must be some way to handle that operator chaining better... |
Ah, it's filter. I'll update the issue. |
This seems like it belongs in I prefer both to comparison with if https_proxy.map(|v| v.starts_with("https://")) == Some(true) {
//...
} Also Clippy will ask you to use |
I did not update that part after my edit. Perhaps you are right. I will fix that.
I saw that lint, but even specifying Even if I am wrong, though, I feel there is a better suggestion than Related, which I just found: rust-lang/rust#75298 Ironically, the only alternative not mentioned in that discussion is what I suggested linting this to. |
I actually think
It works for me. Playground |
What it does
This lint discourages a less readable idiom when checking an operation which returns an
Option<T>
chained with a boolean predicate.My main motivation is to avoid a bad habit of mine while I was still learning all the parts of the APIs. I imagine I am not the only one who learned it.
Categories
clippy::pedantic
What is the advantage of the recommended code over the original code
let Some(...)
clausesDrawbacks
Could be superseded by rust-lang/rust#75298
Example
Could be written as:
The text was updated successfully, but these errors were encountered: