Skip to content

Test all types supported by [collection_is_never_read] #10627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 31 additions & 18 deletions tests/ui/collection_is_never_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
62 changes: 55 additions & 7 deletions tests/ui/collection_is_never_read.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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