Skip to content

Commit

Permalink
Add tests that show: insert() can be a read or not
Browse files Browse the repository at this point in the history
  • Loading branch information
schubart committed Feb 28, 2023
1 parent 5770d40 commit cb3bb8a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
14 changes: 13 additions & 1 deletion tests/ui/collection_is_never_read.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(unused)]
#![warn(clippy::collection_is_never_read)]

use std::collections::HashMap;
use std::collections::{HashSet, HashMap};

fn main() {}

Expand Down Expand Up @@ -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");
}
}
8 changes: 7 additions & 1 deletion tests/ui/collection_is_never_read.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cb3bb8a

Please sign in to comment.