Skip to content

Commit e5d8eb2

Browse files
committed
Add tests for const, static, type alias, enum, and method
1 parent 76fb981 commit e5d8eb2

File tree

3 files changed

+82
-9
lines changed

3 files changed

+82
-9
lines changed

.cargo/config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ dev = "run --target-dir clippy_dev/target --package clippy_dev --bin clippy_dev
44

55
[build]
66
rustflags = ["-Zunstable-options"]
7+
rustc-wrapper = ""

tests/ui/zero_sized_map_values.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
#![warn(clippy::zero_sized_map_values)]
22
use std::collections::HashMap;
33

4+
const CONST_OK: Option<HashMap<String, usize>> = None;
5+
const CONST_NOT_OK: Option<HashMap<String, ()>> = None;
6+
7+
static STATIC_OK: Option<HashMap<String, usize>> = None;
8+
static STATIC_NOT_OK: Option<HashMap<String, ()>> = None;
9+
10+
type OkMap = HashMap<String, usize>;
11+
type NotOkMap = HashMap<String, ()>;
12+
13+
enum TestEnum {
14+
Ok(HashMap<String, usize>),
15+
NotOk(HashMap<String, ()>),
16+
}
17+
418
struct Test {
519
ok: HashMap<String, usize>,
620
not_ok: HashMap<String, ()>,
@@ -16,6 +30,16 @@ trait TestTrait {
1630
fn weird_map(&self, map: HashMap<usize, ()>);
1731
}
1832

33+
impl Test {
34+
fn ok(&self) -> HashMap<String, usize> {
35+
todo!()
36+
}
37+
38+
fn not_ok(&self) -> HashMap<String, ()> {
39+
todo!()
40+
}
41+
}
42+
1943
impl TestTrait for Test {
2044
type Output = HashMap<String, ()>;
2145

tests/ui/zero_sized_map_values.stderr

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,107 @@
11
error: map with zero-sized value type
2-
--> $DIR/zero_sized_map_values.rs:6:13
2+
--> $DIR/zero_sized_map_values.rs:5:28
3+
|
4+
LL | const CONST_NOT_OK: Option<HashMap<String, ()>> = None;
5+
| ^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::zero-sized-map-values` implied by `-D warnings`
8+
= help: consider using a set instead
9+
10+
error: map with zero-sized value type
11+
--> $DIR/zero_sized_map_values.rs:8:30
12+
|
13+
LL | static STATIC_NOT_OK: Option<HashMap<String, ()>> = None;
14+
| ^^^^^^^^^^^^^^^^^^^
15+
|
16+
= help: consider using a set instead
17+
18+
error: map with zero-sized value type
19+
--> $DIR/zero_sized_map_values.rs:11:17
20+
|
21+
LL | type NotOkMap = HashMap<String, ()>;
22+
| ^^^^^^^^^^^^^^^^^^^
23+
|
24+
= help: consider using a set instead
25+
26+
error: map with zero-sized value type
27+
--> $DIR/zero_sized_map_values.rs:15:11
28+
|
29+
LL | NotOk(HashMap<String, ()>),
30+
| ^^^^^^^^^^^^^^^^^^^
31+
|
32+
= help: consider using a set instead
33+
34+
error: map with zero-sized value type
35+
--> $DIR/zero_sized_map_values.rs:20:13
336
|
437
LL | not_ok: HashMap<String, ()>,
538
| ^^^^^^^^^^^^^^^^^^^
639
|
7-
= note: `-D clippy::zero-sized-map-values` implied by `-D warnings`
840
= help: consider using a set instead
941

1042
error: map with zero-sized value type
11-
--> $DIR/zero_sized_map_values.rs:8:22
43+
--> $DIR/zero_sized_map_values.rs:22:22
1244
|
1345
LL | also_not_ok: Vec<HashMap<usize, ()>>,
1446
| ^^^^^^^^^^^^^^^^^^
1547
|
1648
= help: consider using a set instead
1749

1850
error: map with zero-sized value type
19-
--> $DIR/zero_sized_map_values.rs:16:30
51+
--> $DIR/zero_sized_map_values.rs:30:30
2052
|
2153
LL | fn weird_map(&self, map: HashMap<usize, ()>);
2254
| ^^^^^^^^^^^^^^^^^^
2355
|
2456
= help: consider using a set instead
2557

2658
error: map with zero-sized value type
27-
--> $DIR/zero_sized_map_values.rs:31:14
59+
--> $DIR/zero_sized_map_values.rs:38:25
60+
|
61+
LL | fn not_ok(&self) -> HashMap<String, ()> {
62+
| ^^^^^^^^^^^^^^^^^^^
63+
|
64+
= help: consider using a set instead
65+
66+
error: map with zero-sized value type
67+
--> $DIR/zero_sized_map_values.rs:55:14
2868
|
2969
LL | fn test(map: HashMap<String, ()>, key: &str) -> HashMap<String, ()> {
3070
| ^^^^^^^^^^^^^^^^^^^
3171
|
3272
= help: consider using a set instead
3373

3474
error: map with zero-sized value type
35-
--> $DIR/zero_sized_map_values.rs:31:49
75+
--> $DIR/zero_sized_map_values.rs:55:49
3676
|
3777
LL | fn test(map: HashMap<String, ()>, key: &str) -> HashMap<String, ()> {
3878
| ^^^^^^^^^^^^^^^^^^^
3979
|
4080
= help: consider using a set instead
4181

4282
error: map with zero-sized value type
43-
--> $DIR/zero_sized_map_values.rs:41:9
83+
--> $DIR/zero_sized_map_values.rs:65:9
4484
|
4585
LL | let _: HashMap<String, ()> = HashMap::new();
4686
| ^
4787
|
4888
= help: consider using a set instead
4989

5090
error: map with zero-sized value type
51-
--> $DIR/zero_sized_map_values.rs:44:9
91+
--> $DIR/zero_sized_map_values.rs:65:12
92+
|
93+
LL | let _: HashMap<String, ()> = HashMap::new();
94+
| ^^^^^^^^^^^^^^^^^^^
95+
|
96+
= help: consider using a set instead
97+
98+
error: map with zero-sized value type
99+
--> $DIR/zero_sized_map_values.rs:68:9
52100
|
53101
LL | let _: HashMap<_, _> = std::iter::empty::<(String, ())>().collect();
54102
| ^
55103
|
56104
= help: consider using a set instead
57105

58-
error: aborting due to 7 previous errors
106+
error: aborting due to 13 previous errors
59107

0 commit comments

Comments
 (0)