rust-lang / rust-lang/rust-analyzer
Replace named generic with impl assist when the type variable occurs more than once
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
The "Replace named generic with impl trait" assist can change the semantics of the code if the type variable being replaced occurs more than once. For example, the following code fails to compile after applying the assist (in other cases it can be a silent change):
fn common_count<T: Eq>(slice: &[(T, T)]) -> usize {
slice.iter().filter(|(a, b)| a == b).count()
}
Either the assist should not apply in such cases or at least this behavior should be documented.
rust-analyzer version: 0.3.1689-standalone
rustc version: rustc 1.73.0 (cc66ad468 2023-10-03)
relevant settings: None
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 by locating the implementation and tests for the "Replace named generic with impl trait" assist. Reproduce the transformation with the provided common_count example, then determine whether repeated uses of the type variable should prevent the assist or be documented; done means the semantic regression is covered by the assist's tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100