about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-04-11 19:51:06 +0000
committerbors <bors@rust-lang.org>2023-04-11 19:51:06 +0000
commit2a774bb2c789b4dc5ca5d595c467b01a42b56803 (patch)
tree763afd065095c70d91dc158106f9a33c07bb36b0
parent83e42a2337dadac915c956d125f1d69132f36425 (diff)
parentb85deea3f5031df837fe4ec08c6c30929e4a2cb6 (diff)
downloadrust-2a774bb2c789b4dc5ca5d595c467b01a42b56803.tar.gz
rust-2a774bb2c789b4dc5ca5d595c467b01a42b56803.zip
Auto merge of #10627 - schubart:collection_is_never_read_all_types, r=xFrednet
Test all types supported by [`collection_is_never_read`]

changelog: none
-rw-r--r--tests/ui/collection_is_never_read.rs49
-rw-r--r--tests/ui/collection_is_never_read.stderr62
2 files changed, 86 insertions, 25 deletions
diff --git a/tests/ui/collection_is_never_read.rs b/tests/ui/collection_is_never_read.rs
index 01259a983ab..2c1a42a72c1 100644
--- a/tests/ui/collection_is_never_read.rs
+++ b/tests/ui/collection_is_never_read.rs
@@ -169,22 +169,35 @@ fn function_argument() {
     foo(&x);
 }
 
-fn string() {
-    // Do lint (write without read)
-    let mut s = String::new();
-    s.push_str("Hello, World!");
-
-    // Do not lint (read without write)
-    let mut s = String::from("Hello, World!");
-    let _ = s.len();
-
-    // Do not lint (write and read)
-    let mut s = String::from("Hello, World!");
-    s.push_str("foo, bar");
-    let _ = s.len();
-
-    // Do lint the first line, but not the second
-    let mut s = String::from("Hello, World!");
-    let t = String::from("foo, bar");
-    s = t;
+fn supported_types() {
+    let mut x = std::collections::BTreeMap::new(); // WARNING
+    x.insert(true, 1);
+
+    let mut x = std::collections::BTreeSet::new(); // WARNING
+    x.insert(1);
+
+    let mut x = std::collections::BinaryHeap::new(); // WARNING
+    x.push(1);
+
+    let mut x = std::collections::HashMap::new(); // WARNING
+    x.insert(1, 2);
+
+    let mut x = std::collections::HashSet::new(); // WARNING
+    x.insert(1);
+
+    let mut x = std::collections::LinkedList::new(); // WARNING
+    x.push_front(1);
+
+    let mut x = Some(true); // WARNING
+    x.insert(false);
+
+    let mut x = String::from("hello"); // WARNING
+    x.push('!');
+
+    let mut x = Vec::new(); // WARNING
+    x.clear();
+    x.push(1);
+
+    let mut x = std::collections::VecDeque::new(); // WARNING
+    x.push_front(1);
 }
diff --git a/tests/ui/collection_is_never_read.stderr b/tests/ui/collection_is_never_read.stderr
index cf51a53686f..982cb445534 100644
--- a/tests/ui/collection_is_never_read.stderr
+++ b/tests/ui/collection_is_never_read.stderr
@@ -61,16 +61,64 @@ LL |     let x = vec![1, 2, 3]; // WARNING
    |     ^^^^^^^^^^^^^^^^^^^^^^
 
 error: collection is never read
-  --> $DIR/collection_is_never_read.rs:174:5
+  --> $DIR/collection_is_never_read.rs:173:5
    |
-LL |     let mut s = String::new();
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL |     let mut x = std::collections::BTreeMap::new(); // WARNING
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: collection is never read
+  --> $DIR/collection_is_never_read.rs:176:5
+   |
+LL |     let mut x = std::collections::BTreeSet::new(); // WARNING
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: collection is never read
+  --> $DIR/collection_is_never_read.rs:179:5
+   |
+LL |     let mut x = std::collections::BinaryHeap::new(); // WARNING
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: collection is never read
+  --> $DIR/collection_is_never_read.rs:182:5
+   |
+LL |     let mut x = std::collections::HashMap::new(); // WARNING
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: collection is never read
+  --> $DIR/collection_is_never_read.rs:185:5
+   |
+LL |     let mut x = std::collections::HashSet::new(); // WARNING
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: collection is never read
+  --> $DIR/collection_is_never_read.rs:188:5
+   |
+LL |     let mut x = std::collections::LinkedList::new(); // WARNING
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: collection is never read
+  --> $DIR/collection_is_never_read.rs:191:5
+   |
+LL |     let mut x = Some(true); // WARNING
+   |     ^^^^^^^^^^^^^^^^^^^^^^^
+
+error: collection is never read
+  --> $DIR/collection_is_never_read.rs:194:5
+   |
+LL |     let mut x = String::from("hello"); // WARNING
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: collection is never read
+  --> $DIR/collection_is_never_read.rs:197:5
+   |
+LL |     let mut x = Vec::new(); // WARNING
+   |     ^^^^^^^^^^^^^^^^^^^^^^^
 
 error: collection is never read
-  --> $DIR/collection_is_never_read.rs:187:5
+  --> $DIR/collection_is_never_read.rs:201:5
    |
-LL |     let mut s = String::from("Hello, World!");
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL |     let mut x = std::collections::VecDeque::new(); // WARNING
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error: aborting due to 12 previous errors
+error: aborting due to 20 previous errors