Auto merge of #10627 - schubart:collection_is_never_read_all_types, r=xFrednet

Test all types supported by [`collection_is_never_read`]

changelog: none
This commit is contained in:
bors 2023-04-11 19:51:06 +00:00
commit 2a774bb2c7
2 changed files with 83 additions and 22 deletions

View File

@ -169,22 +169,35 @@ fn function_argument() {
foo(&x); foo(&x);
} }
fn string() { fn supported_types() {
// Do lint (write without read) let mut x = std::collections::BTreeMap::new(); // WARNING
let mut s = String::new(); x.insert(true, 1);
s.push_str("Hello, World!");
// Do not lint (read without write) let mut x = std::collections::BTreeSet::new(); // WARNING
let mut s = String::from("Hello, World!"); x.insert(1);
let _ = s.len();
// Do not lint (write and read) let mut x = std::collections::BinaryHeap::new(); // WARNING
let mut s = String::from("Hello, World!"); x.push(1);
s.push_str("foo, bar");
let _ = s.len();
// Do lint the first line, but not the second let mut x = std::collections::HashMap::new(); // WARNING
let mut s = String::from("Hello, World!"); x.insert(1, 2);
let t = String::from("foo, bar");
s = t; 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);
} }

View File

@ -61,16 +61,64 @@ LL | let x = vec![1, 2, 3]; // WARNING
| ^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^
error: collection is never read 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 error: collection is never read
--> $DIR/collection_is_never_read.rs:187:5 --> $DIR/collection_is_never_read.rs:176:5
| |
LL | let mut s = String::from("Hello, World!"); LL | let mut x = std::collections::BTreeSet::new(); // WARNING
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 12 previous errors 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:201:5
|
LL | let mut x = std::collections::VecDeque::new(); // WARNING
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 20 previous errors