Skip to content

Commit a71a13c

Browse files
committed
Separate tests for BTreeMap with zero-sized values
1 parent 4e2bfa2 commit a71a13c

4 files changed

+190
-25
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#![warn(clippy::zero_sized_map_values)]
2+
use std::collections::BTreeMap;
3+
4+
const CONST_OK: Option<BTreeMap<String, usize>> = None;
5+
const CONST_NOT_OK: Option<BTreeMap<String, ()>> = None;
6+
7+
static STATIC_OK: Option<BTreeMap<String, usize>> = None;
8+
static STATIC_NOT_OK: Option<BTreeMap<String, ()>> = None;
9+
10+
type OkMap = BTreeMap<String, usize>;
11+
type NotOkMap = BTreeMap<String, ()>;
12+
13+
enum TestEnum {
14+
Ok(BTreeMap<String, usize>),
15+
NotOk(BTreeMap<String, ()>),
16+
}
17+
18+
struct Test {
19+
ok: BTreeMap<String, usize>,
20+
not_ok: BTreeMap<String, ()>,
21+
22+
also_not_ok: Vec<BTreeMap<usize, ()>>,
23+
}
24+
25+
trait TestTrait {
26+
type Output;
27+
28+
fn produce_output() -> Self::Output;
29+
30+
fn weird_map(&self, map: BTreeMap<usize, ()>);
31+
}
32+
33+
impl Test {
34+
fn ok(&self) -> BTreeMap<String, usize> {
35+
todo!()
36+
}
37+
38+
fn not_ok(&self) -> BTreeMap<String, ()> {
39+
todo!()
40+
}
41+
}
42+
43+
impl TestTrait for Test {
44+
type Output = BTreeMap<String, ()>;
45+
46+
fn produce_output() -> Self::Output {
47+
todo!();
48+
}
49+
50+
fn weird_map(&self, map: BTreeMap<usize, ()>) {
51+
todo!();
52+
}
53+
}
54+
55+
fn test(map: BTreeMap<String, ()>, key: &str) -> BTreeMap<String, ()> {
56+
todo!();
57+
}
58+
59+
fn test2(map: BTreeMap<String, usize>, key: &str) -> BTreeMap<String, usize> {
60+
todo!();
61+
}
62+
63+
fn main() {
64+
let _: BTreeMap<String, ()> = BTreeMap::new();
65+
let _: BTreeMap<String, usize> = BTreeMap::new();
66+
67+
let _: BTreeMap<_, _> = std::iter::empty::<(String, ())>().collect();
68+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
error: map with zero-sized value type
2+
--> $DIR/zero_sized_btreemap_values.rs:5:28
3+
|
4+
LL | const CONST_NOT_OK: Option<BTreeMap<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_btreemap_values.rs:8:30
12+
|
13+
LL | static STATIC_NOT_OK: Option<BTreeMap<String, ()>> = None;
14+
| ^^^^^^^^^^^^^^^^^^^^
15+
|
16+
= help: consider using a set instead
17+
18+
error: map with zero-sized value type
19+
--> $DIR/zero_sized_btreemap_values.rs:11:17
20+
|
21+
LL | type NotOkMap = BTreeMap<String, ()>;
22+
| ^^^^^^^^^^^^^^^^^^^^
23+
|
24+
= help: consider using a set instead
25+
26+
error: map with zero-sized value type
27+
--> $DIR/zero_sized_btreemap_values.rs:15:11
28+
|
29+
LL | NotOk(BTreeMap<String, ()>),
30+
| ^^^^^^^^^^^^^^^^^^^^
31+
|
32+
= help: consider using a set instead
33+
34+
error: map with zero-sized value type
35+
--> $DIR/zero_sized_btreemap_values.rs:20:13
36+
|
37+
LL | not_ok: BTreeMap<String, ()>,
38+
| ^^^^^^^^^^^^^^^^^^^^
39+
|
40+
= help: consider using a set instead
41+
42+
error: map with zero-sized value type
43+
--> $DIR/zero_sized_btreemap_values.rs:22:22
44+
|
45+
LL | also_not_ok: Vec<BTreeMap<usize, ()>>,
46+
| ^^^^^^^^^^^^^^^^^^^
47+
|
48+
= help: consider using a set instead
49+
50+
error: map with zero-sized value type
51+
--> $DIR/zero_sized_btreemap_values.rs:30:30
52+
|
53+
LL | fn weird_map(&self, map: BTreeMap<usize, ()>);
54+
| ^^^^^^^^^^^^^^^^^^^
55+
|
56+
= help: consider using a set instead
57+
58+
error: map with zero-sized value type
59+
--> $DIR/zero_sized_btreemap_values.rs:38:25
60+
|
61+
LL | fn not_ok(&self) -> BTreeMap<String, ()> {
62+
| ^^^^^^^^^^^^^^^^^^^^
63+
|
64+
= help: consider using a set instead
65+
66+
error: map with zero-sized value type
67+
--> $DIR/zero_sized_btreemap_values.rs:55:14
68+
|
69+
LL | fn test(map: BTreeMap<String, ()>, key: &str) -> BTreeMap<String, ()> {
70+
| ^^^^^^^^^^^^^^^^^^^^
71+
|
72+
= help: consider using a set instead
73+
74+
error: map with zero-sized value type
75+
--> $DIR/zero_sized_btreemap_values.rs:55:50
76+
|
77+
LL | fn test(map: BTreeMap<String, ()>, key: &str) -> BTreeMap<String, ()> {
78+
| ^^^^^^^^^^^^^^^^^^^^
79+
|
80+
= help: consider using a set instead
81+
82+
error: map with zero-sized value type
83+
--> $DIR/zero_sized_btreemap_values.rs:64:35
84+
|
85+
LL | let _: BTreeMap<String, ()> = BTreeMap::new();
86+
| ^^^^^^^^^^^^^
87+
|
88+
= help: consider using a set instead
89+
90+
error: map with zero-sized value type
91+
--> $DIR/zero_sized_btreemap_values.rs:64:12
92+
|
93+
LL | let _: BTreeMap<String, ()> = BTreeMap::new();
94+
| ^^^^^^^^^^^^^^^^^^^^
95+
|
96+
= help: consider using a set instead
97+
98+
error: map with zero-sized value type
99+
--> $DIR/zero_sized_btreemap_values.rs:67:12
100+
|
101+
LL | let _: BTreeMap<_, _> = std::iter::empty::<(String, ())>().collect();
102+
| ^^^^^^^^^^^^^^
103+
|
104+
= help: consider using a set instead
105+
106+
error: aborting due to 13 previous errors
107+

tests/ui/zero_sized_map_values.rs renamed to tests/ui/zero_sized_hashmap_values.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![warn(clippy::zero_sized_map_values)]
2-
use std::collections::{BTreeMap, HashMap};
2+
use std::collections::HashMap;
33

44
const CONST_OK: Option<HashMap<String, usize>> = None;
55
const CONST_NOT_OK: Option<HashMap<String, ()>> = None;
@@ -61,10 +61,8 @@ fn test2(map: HashMap<String, usize>, key: &str) -> HashMap<String, usize> {
6161
}
6262

6363
fn main() {
64-
// test code goes here
6564
let _: HashMap<String, ()> = HashMap::new();
6665
let _: HashMap<String, usize> = HashMap::new();
6766

6867
let _: HashMap<_, _> = std::iter::empty::<(String, ())>().collect();
69-
let _: BTreeMap<_, _> = std::iter::empty::<(String, ())>().collect();
7068
}
Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: map with zero-sized value type
2-
--> $DIR/zero_sized_map_values.rs:5:28
2+
--> $DIR/zero_sized_hashmap_values.rs:5:28
33
|
44
LL | const CONST_NOT_OK: Option<HashMap<String, ()>> = None;
55
| ^^^^^^^^^^^^^^^^^^^
@@ -8,108 +8,100 @@ LL | const CONST_NOT_OK: Option<HashMap<String, ()>> = None;
88
= help: consider using a set instead
99

1010
error: map with zero-sized value type
11-
--> $DIR/zero_sized_map_values.rs:8:30
11+
--> $DIR/zero_sized_hashmap_values.rs:8:30
1212
|
1313
LL | static STATIC_NOT_OK: Option<HashMap<String, ()>> = None;
1414
| ^^^^^^^^^^^^^^^^^^^
1515
|
1616
= help: consider using a set instead
1717

1818
error: map with zero-sized value type
19-
--> $DIR/zero_sized_map_values.rs:11:17
19+
--> $DIR/zero_sized_hashmap_values.rs:11:17
2020
|
2121
LL | type NotOkMap = HashMap<String, ()>;
2222
| ^^^^^^^^^^^^^^^^^^^
2323
|
2424
= help: consider using a set instead
2525

2626
error: map with zero-sized value type
27-
--> $DIR/zero_sized_map_values.rs:15:11
27+
--> $DIR/zero_sized_hashmap_values.rs:15:11
2828
|
2929
LL | NotOk(HashMap<String, ()>),
3030
| ^^^^^^^^^^^^^^^^^^^
3131
|
3232
= help: consider using a set instead
3333

3434
error: map with zero-sized value type
35-
--> $DIR/zero_sized_map_values.rs:20:13
35+
--> $DIR/zero_sized_hashmap_values.rs:20:13
3636
|
3737
LL | not_ok: HashMap<String, ()>,
3838
| ^^^^^^^^^^^^^^^^^^^
3939
|
4040
= help: consider using a set instead
4141

4242
error: map with zero-sized value type
43-
--> $DIR/zero_sized_map_values.rs:22:22
43+
--> $DIR/zero_sized_hashmap_values.rs:22:22
4444
|
4545
LL | also_not_ok: Vec<HashMap<usize, ()>>,
4646
| ^^^^^^^^^^^^^^^^^^
4747
|
4848
= help: consider using a set instead
4949

5050
error: map with zero-sized value type
51-
--> $DIR/zero_sized_map_values.rs:30:30
51+
--> $DIR/zero_sized_hashmap_values.rs:30:30
5252
|
5353
LL | fn weird_map(&self, map: HashMap<usize, ()>);
5454
| ^^^^^^^^^^^^^^^^^^
5555
|
5656
= help: consider using a set instead
5757

5858
error: map with zero-sized value type
59-
--> $DIR/zero_sized_map_values.rs:38:25
59+
--> $DIR/zero_sized_hashmap_values.rs:38:25
6060
|
6161
LL | fn not_ok(&self) -> HashMap<String, ()> {
6262
| ^^^^^^^^^^^^^^^^^^^
6363
|
6464
= help: consider using a set instead
6565

6666
error: map with zero-sized value type
67-
--> $DIR/zero_sized_map_values.rs:55:14
67+
--> $DIR/zero_sized_hashmap_values.rs:55:14
6868
|
6969
LL | fn test(map: HashMap<String, ()>, key: &str) -> HashMap<String, ()> {
7070
| ^^^^^^^^^^^^^^^^^^^
7171
|
7272
= help: consider using a set instead
7373

7474
error: map with zero-sized value type
75-
--> $DIR/zero_sized_map_values.rs:55:49
75+
--> $DIR/zero_sized_hashmap_values.rs:55:49
7676
|
7777
LL | fn test(map: HashMap<String, ()>, key: &str) -> HashMap<String, ()> {
7878
| ^^^^^^^^^^^^^^^^^^^
7979
|
8080
= help: consider using a set instead
8181

8282
error: map with zero-sized value type
83-
--> $DIR/zero_sized_map_values.rs:65:34
83+
--> $DIR/zero_sized_hashmap_values.rs:64:34
8484
|
8585
LL | let _: HashMap<String, ()> = HashMap::new();
8686
| ^^^^^^^^^^^^
8787
|
8888
= help: consider using a set instead
8989

9090
error: map with zero-sized value type
91-
--> $DIR/zero_sized_map_values.rs:65:12
91+
--> $DIR/zero_sized_hashmap_values.rs:64:12
9292
|
9393
LL | let _: HashMap<String, ()> = HashMap::new();
9494
| ^^^^^^^^^^^^^^^^^^^
9595
|
9696
= help: consider using a set instead
9797

9898
error: map with zero-sized value type
99-
--> $DIR/zero_sized_map_values.rs:68:12
99+
--> $DIR/zero_sized_hashmap_values.rs:67:12
100100
|
101101
LL | let _: HashMap<_, _> = std::iter::empty::<(String, ())>().collect();
102102
| ^^^^^^^^^^^^^
103103
|
104104
= help: consider using a set instead
105105

106-
error: map with zero-sized value type
107-
--> $DIR/zero_sized_map_values.rs:69:12
108-
|
109-
LL | let _: BTreeMap<_, _> = std::iter::empty::<(String, ())>().collect();
110-
| ^^^^^^^^^^^^^^
111-
|
112-
= help: consider using a set instead
113-
114-
error: aborting due to 14 previous errors
106+
error: aborting due to 13 previous errors
115107

0 commit comments

Comments
 (0)