Skip to content

Commit 66e6430

Browse files
committed
Also check for BTreeMap with zero-sized value type
1 parent a2e460c commit 66e6430

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

clippy_lints/src/zero_sized_map_values.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl ZeroSizedMapValues {
139139
}
140140

141141
if_chain! {
142-
if match_type(cx, ty, &paths::HASHMAP);
142+
if match_type(cx, ty, &paths::HASHMAP) || match_type(cx, ty, &paths::BTREEMAP);
143143
if let Adt(_, ref substs) = ty.kind();
144144
let ty = substs.type_at(1);
145145
if let Ok(layout) = cx.layout_of(ty);

tests/ui/zero_sized_map_values.stderr

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ LL | fn weird_map(&self, map: HashMap<usize, ()>);
2424
= help: consider using a set instead
2525

2626
error: map with zero-sized value type
27-
--> $DIR/zero_sized_map_values.rs:31:14
27+
--> $DIR/zero_sized_map_values.rs:31:24
2828
|
29-
LL | fn test(map: HashMap<String, ()>, key: &str) -> HashMap<String, ()> {
30-
| ^^^^^^^^^^^^^^^^^^^
29+
LL | fn hashmap_not_ok(map: HashMap<String, ()>, key: &str) -> HashMap<String, ()> {
30+
| ^^^^^^^^^^^^^^^^^^^
3131
|
3232
= help: consider using a set instead
3333

3434
error: map with zero-sized value type
35-
--> $DIR/zero_sized_map_values.rs:31:49
35+
--> $DIR/zero_sized_map_values.rs:31:59
3636
|
37-
LL | fn test(map: HashMap<String, ()>, key: &str) -> HashMap<String, ()> {
38-
| ^^^^^^^^^^^^^^^^^^^
37+
LL | fn hashmap_not_ok(map: HashMap<String, ()>, key: &str) -> HashMap<String, ()> {
38+
| ^^^^^^^^^^^^^^^^^^^
3939
|
4040
= help: consider using a set instead
4141

@@ -50,10 +50,18 @@ LL | let _: HashMap<String, ()> = HashMap::new();
5050
error: map with zero-sized value type
5151
--> $DIR/zero_sized_map_values.rs:44:9
5252
|
53+
LL | let _: BTreeMap<String, ()> = BTreeMap::new();
54+
| ^
55+
|
56+
= help: consider using a set instead
57+
58+
error: map with zero-sized value type
59+
--> $DIR/zero_sized_map_values.rs:47:9
60+
|
5361
LL | let _: HashMap<_, _> = std::iter::empty::<(String, ())>().collect();
5462
| ^
5563
|
5664
= help: consider using a set instead
5765

58-
error: aborting due to 7 previous errors
66+
error: aborting due to 8 previous errors
5967

0 commit comments

Comments
 (0)