rust-lang / rust-lang/rust-clippy
new lint: find unused method results (take '&mut self' into account)
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Currently, the rustc unused value warning seems to just look for LHS value that is not referenced anywhere else, like
let x = 0; // unused !
let y = 1;
println!("{}", y);
However there is no warning if we call an object method that modifies the object inplace, but we don't use the new object state afterwards:
let mut x = vec![1, 3, 2];
x.sort(); // here "x" is "used"
// here "x" is no longer used so technically we can omit the entire "x.sort()"
// but there is no warning for this :(
Maybe there could be a more advanced unused variable lint that checks if we call an object method taking &mut self without side effects and not returning anything without the object being ever referenced afterwards?
I'd love to have some sort of warning for the vec.sort() example.
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 reviewing how rustc's unused value warning handles the shown let example, then compare it with the vec.sort() example involving &mut self. Define the lint's intended side-effect boundary and verify that it warns only when the mutated object is not referenced afterward, while avoiding methods with observable side effects.
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
- Mostly clear
- Newbie friendliness
- 25/100