Add tests that show: insert() can be a read or not

This commit is contained in:
Michael Schubart 2023-02-28 22:01:48 +00:00
parent 5770d40d8e
commit cb3bb8a5b5
2 changed files with 20 additions and 2 deletions

View File

@ -1,7 +1,7 @@
#![allow(unused)]
#![warn(clippy::collection_is_never_read)]
use std::collections::HashMap;
use std::collections::{HashSet, HashMap};
fn main() {}
@ -114,3 +114,15 @@ fn method_argument_but_not_target() {
x.reverse();
my_struct.my_method(&x);
}
fn insert_is_not_a_read() {
let mut x = HashSet::new(); // WARNING
x.insert(5);
}
fn insert_is_a_read() {
let mut x = HashSet::new(); // Ok
if x.insert(5) {
println!("5 was inserted");
}
}

View File

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