rust-lang / rust-lang/rust-clippy

`redundant_as_str` misses chained method calls

Open
#16,979 1 comment 0 reactions 1 assignee View on GitHub

@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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.