Skip to content

Commit 2a774bb

Browse files
committed
Auto merge of #10627 - schubart:collection_is_never_read_all_types, r=xFrednet
Test all types supported by [`collection_is_never_read`] changelog: none
2 parents 83e42a2 + b85deea commit 2a774bb

File tree

2 files changed

+86
-25
lines changed

2 files changed

+86
-25
lines changed

tests/ui/collection_is_never_read.rs

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -169,22 +169,35 @@ fn function_argument() {
169169
foo(&x);
170170
}
171171

172-
fn string() {
173-
// Do lint (write without read)
174-
let mut s = String::new();
175-
s.push_str("Hello, World!");
176-
177-
// Do not lint (read without write)
178-
let mut s = String::from("Hello, World!");
179-
let _ = s.len();
180-
181-
// Do not lint (write and read)
182-
let mut s = String::from("Hello, World!");
183-
s.push_str("foo, bar");
184-
let _ = s.len();
185-
186-
// Do lint the first line, but not the second
187-
let mut s = String::from("Hello, World!");
188-
let t = String::from("foo, bar");
189-
s = t;
172+
fn supported_types() {
173+
let mut x = std::collections::BTreeMap::new(); // WARNING
174+
x.insert(true, 1);
175+
176+
let mut x = std::collections::BTreeSet::new(); // WARNING
177+
x.insert(1);
178+
179+
let mut x = std::collections::BinaryHeap::new(); // WARNING
180+
x.push(1);
181+
182+
let mut x = std::collections::HashMap::new(); // WARNING
183+
x.insert(1, 2);
184+
185+
let mut x = std::collections::HashSet::new(); // WARNING
186+
x.insert(1);
187+
188+
let mut x = std::collections::LinkedList::new(); // WARNING
189+
x.push_front(1);
190+
191+
let mut x = Some(true); // WARNING
192+
x.insert(false);
193+
194+
let mut x = String::from("hello"); // WARNING
195+
x.push('!');
196+
197+
let mut x = Vec::new(); // WARNING
198+
x.clear();
199+
x.push(1);
200+
201+
let mut x = std::collections::VecDeque::new(); // WARNING
202+
x.push_front(1);
190203
}

tests/ui/collection_is_never_read.stderr

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,64 @@ LL | let x = vec![1, 2, 3]; // WARNING
6161
| ^^^^^^^^^^^^^^^^^^^^^^
6262

6363
error: collection is never read
64-
--> $DIR/collection_is_never_read.rs:174:5
64+
--> $DIR/collection_is_never_read.rs:173:5
6565
|
66-
LL | let mut s = String::new();
67-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
66+
LL | let mut x = std::collections::BTreeMap::new(); // WARNING
67+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
68+
69+
error: collection is never read
70+
--> $DIR/collection_is_never_read.rs:176:5
71+
|
72+
LL | let mut x = std::collections::BTreeSet::new(); // WARNING
73+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
74+
75+
error: collection is never read
76+
--> $DIR/collection_is_never_read.rs:179:5
77+
|
78+
LL | let mut x = std::collections::BinaryHeap::new(); // WARNING
79+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
80+
81+
error: collection is never read
82+
--> $DIR/collection_is_never_read.rs:182:5
83+
|
84+
LL | let mut x = std::collections::HashMap::new(); // WARNING
85+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
86+
87+
error: collection is never read
88+
--> $DIR/collection_is_never_read.rs:185:5
89+
|
90+
LL | let mut x = std::collections::HashSet::new(); // WARNING
91+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
92+
93+
error: collection is never read
94+
--> $DIR/collection_is_never_read.rs:188:5
95+
|
96+
LL | let mut x = std::collections::LinkedList::new(); // WARNING
97+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
98+
99+
error: collection is never read
100+
--> $DIR/collection_is_never_read.rs:191:5
101+
|
102+
LL | let mut x = Some(true); // WARNING
103+
| ^^^^^^^^^^^^^^^^^^^^^^^
104+
105+
error: collection is never read
106+
--> $DIR/collection_is_never_read.rs:194:5
107+
|
108+
LL | let mut x = String::from("hello"); // WARNING
109+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
110+
111+
error: collection is never read
112+
--> $DIR/collection_is_never_read.rs:197:5
113+
|
114+
LL | let mut x = Vec::new(); // WARNING
115+
| ^^^^^^^^^^^^^^^^^^^^^^^
68116

69117
error: collection is never read
70-
--> $DIR/collection_is_never_read.rs:187:5
118+
--> $DIR/collection_is_never_read.rs:201:5
71119
|
72-
LL | let mut s = String::from("Hello, World!");
73-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
120+
LL | let mut x = std::collections::VecDeque::new(); // WARNING
121+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
74122

75-
error: aborting due to 12 previous errors
123+
error: aborting due to 20 previous errors
76124

0 commit comments

Comments
 (0)