Skip to content

Lint for replacing x.strip_[prefix/suffix](...).unwrap_or(x) with x.trim_[prefix/suffix](...) #17779

Description

@ChayimFriedman2

What it does

Rust 1.100.0 will stabilize the str::trim_prefix() and trim_suffix() methods. The previous workaround for them was s.strip_[prefix/suffix](...).unwrap_or(s). I think we should have a lint for the new method.

Advantage

It's just simpler, and perhaps also faster.

Drawbacks

No response

Example

let s: &str;
s.strip_prefix("foo").unwrap_or(s)

Could be written as:

let s: &str;
s.trim_prefix("foo")

Comparison with existing lints

No response

Additional Context

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-lintArea: New lintsgood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions