rust-lang / rust-lang/rust-analyzer
Lint option: Highlighting copies
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
It would be nice to have a lint feature that, when enabled, will highlight all instances where a variable is copied. This would be useful because it's not always clear when a copy would occur, and highlighting copies could point out areas where code compiles correctly, but could be written better.
For example:
#[derive(Debug, Clone, Copy)]
struct Test {
num: [u8; 20],
}
fn func(_: Test) {
// ...
}
fn main() {
let t = Test{
num:[0;20],
};
let t2 = t.clone();
func(t);
println!("{:?}", t2);
}
In this case, the author of the code is unaware that Test implements Copy, so they clone t to pass to func() in order to keep using t after they assume it was moved. When highlighting is enabled, the t in func(t) would be highlighted which would provide a visual indicator that the clone is unnecessary, as t will be copied instead of moved when passed to func.
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 examining rust-analyzer's existing lint and highlighting behavior, then trace how the Rust example's Copy semantics are represented. Define the enabled-option scope and how copied variable uses should be identified and highlighted, and add coverage for the provided Test example before verifying the resulting editor highlighting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100