rust-lang / rust-lang/rust-clippy
new lint: Unexpected double indirection
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
In Rust it's relatively easy to accidentally end up with a &&T type when expecting to use &T.
The problem is that thanks to auto dereferencing &&T most of the time works just as well as &T, so the difference may go unnoticed for a while. But later when the code is changed, it may get weird type errors in unexpected places somewhere later in the code:
let s = "foo";
let s = &s[1..2]; // ok
let s = &s[1..2].trim(); // &&str suddenly
let l = s.len(); // but seems to work…
if s == "oo" // except, "can't compare `&str` with `str`"!?
for s in ["a", "b"].iter() { // gives &&str
let s: String = s.to_owned(); // error: makes "owned" &str
}
So I'm hoping Clippy could find patterns which typically cause unexpected creation of doubly-indirect types, and warn about them before they become a hard-to-diagnose problem later.
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.
Research direction
Start from the two Rust examples in the issue and identify which expressions create unexpected &&T values through borrowing or iteration. Define the lint's supported patterns and warnings, then verify that it catches the demonstrated cases without flagging intentional double indirection.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100