Closed
Description
What it does
Adding to a collection and never using it is pointless and might indicate that the developer forgot to do something with the collection.
Currently this does not raise warnings:
#![warn(clippy::all, clippy::pedantic)]
fn main() {
let mut numbers = Vec::new();
for number in 1..10 {
numbers.push(number);
}
}
The new lint would point out that numbers
is never read.
To fix the warning, one could delete all code in main
or do something with numbers
, such as printing it.
What do people think? If this sounds useful, I'd like to do it as my first contribution.
Lint Name
collection_is_never_read
Category
suspicious
Advantage
The new code no longer unnecessarily does the work of updating the collection.
Drawbacks
No response
Example
<code>
Could be written as:
#![warn(clippy::all, clippy::pedantic)]
fn main() {
let mut numbers = Vec::new();
for number in 1..10 {
numbers.push(number);
}
println!("The numbers are: {numbers:?}");
}