Skip to content

Commit

Permalink
Also check for BTreeMap with zero-sized value type
Browse files Browse the repository at this point in the history
  • Loading branch information
korrat committed Nov 14, 2020
1 parent 86592ee commit 9aa5d48
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/zero_sized_map_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl ZeroSizedMapValues {
}

if_chain! {
if match_type(cx, ty, &paths::HASHMAP);
if match_type(cx, ty, &paths::HASHMAP) || match_type(cx, ty, &paths::BTREEMAP);
if let Adt(_, ref substs) = ty.kind();
let ty = substs.type_at(1);
if let Ok(layout) = cx.layout_of(ty);
Expand Down
22 changes: 15 additions & 7 deletions tests/ui/zero_sized_map_values.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ LL | fn weird_map(&self, map: HashMap<usize, ()>);
= help: consider using a set instead

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

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

Expand All @@ -50,10 +50,18 @@ LL | let _: HashMap<String, ()> = HashMap::new();
error: map with zero-sized value type
--> $DIR/zero_sized_map_values.rs:44:9
|
LL | let _: BTreeMap<String, ()> = BTreeMap::new();
| ^
|
= help: consider using a set instead

error: map with zero-sized value type
--> $DIR/zero_sized_map_values.rs:47:9
|
LL | let _: HashMap<_, _> = std::iter::empty::<(String, ())>().collect();
| ^
|
= help: consider using a set instead

error: aborting due to 7 previous errors
error: aborting due to 8 previous errors

0 comments on commit 9aa5d48

Please sign in to comment.