diff options
| author | Michael Schubart <michael@schubart.net> | 2023-02-28 22:01:48 +0000 |
|---|---|---|
| committer | Michael Schubart <michael@schubart.net> | 2023-02-28 22:09:04 +0000 |
| commit | cb3bb8a5b5449f330cba8544a30d1f7e1d5f16d3 (patch) | |
| tree | 3d00ff6869238c85bc67d0d1b73adf66270bf708 | |
| parent | 5770d40d8ea3ba8d5a41db5e5914b45f32d80a9f (diff) | |
| download | rust-cb3bb8a5b5449f330cba8544a30d1f7e1d5f16d3.tar.gz rust-cb3bb8a5b5449f330cba8544a30d1f7e1d5f16d3.zip | |
Add tests that show: insert() can be a read or not
| -rw-r--r-- | tests/ui/collection_is_never_read.rs | 14 | ||||
| -rw-r--r-- | tests/ui/collection_is_never_read.stderr | 8 |
2 files changed, 20 insertions, 2 deletions
diff --git a/tests/ui/collection_is_never_read.rs b/tests/ui/collection_is_never_read.rs index 2c37fc212b0..28ec4bf0aeb 100644 --- a/tests/ui/collection_is_never_read.rs +++ b/tests/ui/collection_is_never_read.rs @@ -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"); + } +} diff --git a/tests/ui/collection_is_never_read.stderr b/tests/ui/collection_is_never_read.stderr index 43349f550a6..d66b833c522 100644 --- a/tests/ui/collection_is_never_read.stderr +++ b/tests/ui/collection_is_never_read.stderr @@ -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 |
