-
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
Manual char string search pattern #12490
Labels
Comments
Alexendoo
added
the
good-first-issue
These issues are a good way to get started with Clippy
label
Mar 15, 2024
@rustbot claim |
@rustbot claim |
Hello @Vrajs16, |
@AurelienFT you can claim it |
@rustbot claim |
bors
added a commit
that referenced
this issue
Jun 11, 2024
…lexendoo Add lint to check manual pattern char comparison This PR adds a new lint asked in #12490 This lint catches manual char comparison in pattern of string functions and propose to use `char` or array of `char` instead. As it's my first contribution i'm not feeling very safe about not matching too much or missing some cases. Thanks in advance for taking time to review and propose feedback !
bors
added a commit
that referenced
this issue
Jun 11, 2024
…lexendoo Add lint to check manual pattern char comparison This PR adds a new lint asked in #12490 This lint catches manual char comparison in pattern of string functions and propose to use `char` or array of `char` instead. As it's my first contribution i'm not feeling very safe about not matching too much or missing some cases. Thanks in advance for taking time to review and propose feedback ! changelog: new lint [`manual_pattern_char_comparison`]
Closing as this was implemented in #12849 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
What it does
Uses of
Pattern
(in methods likestr.split()
,str.replace()
,str.trim_matches()
) where the pattern is a closure matchingchar
s:can be expressed more succinctly as:
and a single-char comparison can be simplified further.
Advantage
It makes the code much shorter, and the character set much easier to read.
They all have about the same performance, except a single-char pattern is much faster than the other forms.
Drawbacks
No response
Example
Could be written as:
The text was updated successfully, but these errors were encountered: