-
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
Use is_some_and when appropriate #9125
Comments
There is no method |
Sorry, that's correct. The feature is called EDIT: Updated the original comment. |
Is there a hurry to get this done? I would love to learn how to implement lint's. If this is a good match for a beginner I would love to learn how to implement this. |
I'm also looking for Clippy veterans can correct me if I said anything wrong. |
Hey, welcome to Clippy 👋. This issue is not urgent, so you're welcome to claim it and take your time. If you have questions, you're also welcome to ask. Please don't hesitate to ping anyone of us (sometimes we miss questions in issues, if nobody mentions us) Some more context, about what is urgent, in case you're interested: A new version of Clippy is released every 6 weeks. There are only very few things which are kind of urgent, and these are mostly handled by maintainers. (like writing the changelog and syncing changes with the rust repo). Some issues have a slightly higher priority, like crashes or very common false positives. But even these can be handled differently if nobody wants to fix them. The wonderful part is that Clippy and other rust projects are about building cool software and very little about deadlines and releases :) |
@Rqnsom, @xFrednet Thank you for being so welcoming! :) How do I claim a lint? Do I do something like @bors claim? I think I saw someone use a command like that once to claim a lint but I can't seem to find it in https://bors.rust-lang.org/ |
For that, we have our lovely rustbot. Just include |
@rustbot claim |
I'm noticing that the documentation is pretty fragmented... That looks like a good easy (non technical) project to look at next. lol |
Yeah, Clippy sadly also has some areas which are not documented at all. We're recently made some good progress on that, but documentation improvements are always good and welcome! |
This should also trigger on |
It would be cool if all of these causes would be caught. For the start, it might be better to focus on one and add the others later :) |
@JoelMon Any progress on this? I would also love to try it as my first clippy lint, and my first contribution to an open source project. |
I haven't been able to take a crack at it and won't be able to any time soon. Go ahead and give it a go. Let me know if I have to do someone on my end to give up claim or what not. Hope you success and enjoyment to your first contribution! |
@rustbot claim |
@xFrednet I was trying to implement this lint, but then I found out about an existing lint |
Hey @TheCodingWombat, good catch! This lint is more specific in the sense that it specially detects boolean conversions. I think adding logic to the mentioned lint, to suggest Small sidenote, the lint has been renamed and the current name is |
@xFrednet What command do I use to run a single uitest? I tried |
@TheCodingWombat The interface is a bit weird, as the framework we use doesn't support cli arguments. Instead, a |
Here's another usage that could use This could be: if u.next().is_some_and(|u| l != u) {
return true;
} |
A start of this implementation can be found in this PR #10102 which was closed due to inactivity. If someone else wants to pick it up, I'm happy to help where I can :) |
@rustbot claim |
@rustbot claim |
@rustbot claim |
What it does
The lint would detect cases where the new Option function is_some_and would be appropriate. Examples would be places where
map()
converts anOption<T>
into anOption<bool>
and thenunwrap_or(false)
is used. The library function is still experimental, but once it's stable, this would be a useful modernization suggestion.Lint Name
option_is_some_with
Category
complexity
Advantage
Reduces function calls (even if they would optimize down), increases clarity.
Drawbacks
Low priority, since the existing approaches are functional, if less idiomatic/aesthetic.
Example
Could be written as:
The text was updated successfully, but these errors were encountered: