Skip to content

Commit fbb7fd5

Browse files
committed
Add test for an interesting edge case
1 parent cb3bb8a commit fbb7fd5

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

tests/ui/collection_is_never_read.rs

Lines changed: 8 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::{HashSet, HashMap};
4+
use std::collections::{HashMap, HashSet};
55

66
fn main() {}
77

@@ -126,3 +126,10 @@ fn insert_is_a_read() {
126126
println!("5 was inserted");
127127
}
128128
}
129+
130+
fn not_read_if_return_value_not_used() {
131+
// `is_empty` does not modify the set, so it's a query. But since the return value is not used, the
132+
// lint does not consider it a read here.
133+
let x = vec![1, 2, 3]; // WARNING
134+
x.is_empty();
135+
}

tests/ui/collection_is_never_read.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,11 @@ error: collection is never read
4242
LL | let mut x = HashSet::new(); // WARNING
4343
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
4444

45-
error: aborting due to 7 previous errors
45+
error: collection is never read
46+
--> $DIR/collection_is_never_read.rs:133:5
47+
|
48+
LL | let x = vec![1, 2, 3]; // WARNING
49+
| ^^^^^^^^^^^^^^^^^^^^^^
50+
51+
error: aborting due to 8 previous errors
4652

0 commit comments

Comments
 (0)