rust-lang / rust-lang/rust-clippy
`redundant_as_str` misses chained method calls
Open
@profetia is already working on this.
Since May 9, 2026.
C-enhancement
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
The lint currently does not trigger for .as_str().len() even though the .as_str() call is unnecessary.
Reproducer: https://rust.godbolt.org/z/5s563YbP3
Lint Name
redundant_as_str
Reproducer
I tried this code:
fn issue16979(s: String) -> usize {
s.as_str().len()
}
I expected to see this happen:
warning: this `as_str` is redundant and can be removed as the method immediately following exists on `String` too
--> <source>:5:7
|
5 | s.as_str().len()
| ^^^^^^^^^^^^^^^^^ help: try: `len`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_as_str
Or something similar indicating that the .as_str() call can be removed.
Instead, this happened:
No lint ouput
Version
clippy 0.1.97 (fb0a5a5a9c 2026-05-08)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.