New lint: collapsible_str_replace
#6651
Labels
A-lint
Area: New lints
good-first-issue
These issues are a good way to get started with Clippy
L-perf
Lint: Belongs in the perf lint group
T-middle
Type: Probably requires verifiying types
What it does
Checks for consecutive calls to
str::replace
(2 or more) that can be collapsed into a single call.Categories (optional)
What is the advantage of the recommended code over the original code
Faster since the string is only scanned once. Also less repetitive code.
Drawbacks
None.
Example
Could be written as:
Using
matches!
is potentially faster than a slice of chars (replace(&['s', 'u', 'p'], "l")
). But if any of the chars are variables, the lint can fall back to suggesting a slice of chars.The text was updated successfully, but these errors were encountered: