Test all types supported by [collection_is_never_read
]
This commit is contained in:
parent
3b5b2ed01a
commit
b85deea3f5
@ -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!");
|
||||
fn supported_types() {
|
||||
let mut x = std::collections::BTreeMap::new(); // WARNING
|
||||
x.insert(true, 1);
|
||||
|
||||
// Do not lint (read without write)
|
||||
let mut s = String::from("Hello, World!");
|
||||
let _ = s.len();
|
||||
let mut x = std::collections::BTreeSet::new(); // WARNING
|
||||
x.insert(1);
|
||||
|
||||
// Do not lint (write and read)
|
||||
let mut s = String::from("Hello, World!");
|
||||
s.push_str("foo, bar");
|
||||
let _ = s.len();
|
||||
let mut x = std::collections::BinaryHeap::new(); // WARNING
|
||||
x.push(1);
|
||||
|
||||
// Do lint the first line, but not the second
|
||||
let mut s = String::from("Hello, World!");
|
||||
let t = String::from("foo, bar");
|
||||
s = t;
|
||||
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);
|
||||
}
|
||||
|
@ -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: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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user