Add test for an interesting edge case

This commit is contained in:
Michael Schubart 2023-02-28 22:08:15 +00:00
parent cb3bb8a5b5
commit fbb7fd59c3
2 changed files with 15 additions and 2 deletions

View File

@ -1,7 +1,7 @@
#![allow(unused)]
#![warn(clippy::collection_is_never_read)]
use std::collections::{HashSet, HashMap};
use std::collections::{HashMap, HashSet};
fn main() {}
@ -126,3 +126,10 @@ fn insert_is_a_read() {
println!("5 was inserted");
}
}
fn not_read_if_return_value_not_used() {
// `is_empty` does not modify the set, so it's a query. But since the return value is not used, the
// lint does not consider it a read here.
let x = vec![1, 2, 3]; // WARNING
x.is_empty();
}

View File

@ -42,5 +42,11 @@ error: collection is never read
LL | let mut x = HashSet::new(); // WARNING
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 7 previous errors
error: collection is never read
--> $DIR/collection_is_never_read.rs:133:5
|
LL | let x = vec![1, 2, 3]; // WARNING
| ^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 8 previous errors