Skip to content

Commit cb3bb8a

Browse files
committed
Add tests that show: insert() can be a read or not
1 parent 5770d40 commit cb3bb8a

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

tests/ui/collection_is_never_read.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(unused)]
22
#![warn(clippy::collection_is_never_read)]
33

4-
use std::collections::HashMap;
4+
use std::collections::{HashSet, HashMap};
55

66
fn main() {}
77

@@ -114,3 +114,15 @@ fn method_argument_but_not_target() {
114114
x.reverse();
115115
my_struct.my_method(&x);
116116
}
117+
118+
fn insert_is_not_a_read() {
119+
let mut x = HashSet::new(); // WARNING
120+
x.insert(5);
121+
}
122+
123+
fn insert_is_a_read() {
124+
let mut x = HashSet::new(); // Ok
125+
if x.insert(5) {
126+
println!("5 was inserted");
127+
}
128+
}

tests/ui/collection_is_never_read.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,11 @@ error: collection is never read
3636
LL | let mut x = vec![1, 2, 3]; // WARNING
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
3838

39-
error: aborting due to 6 previous errors
39+
error: collection is never read
40+
--> $DIR/collection_is_never_read.rs:119:5
41+
|
42+
LL | let mut x = HashSet::new(); // WARNING
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
44+
45+
error: aborting due to 7 previous errors
4046

0 commit comments

Comments
 (0)