From 9aa5d48fe4b671540dabee931eaf8b712734fc20 Mon Sep 17 00:00:00 2001 From: Korrat Date: Sat, 24 Oct 2020 19:03:50 +0200 Subject: [PATCH] Also check for BTreeMap with zero-sized value type --- clippy_lints/src/zero_sized_map_values.rs | 2 +- tests/ui/zero_sized_map_values.stderr | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index 3e3a8e835fc8..22d008de758a 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -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); diff --git a/tests/ui/zero_sized_map_values.stderr b/tests/ui/zero_sized_map_values.stderr index 3806bb93fb42..3642dbcf94ea 100644 --- a/tests/ui/zero_sized_map_values.stderr +++ b/tests/ui/zero_sized_map_values.stderr @@ -24,18 +24,18 @@ LL | fn weird_map(&self, map: HashMap); = 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, key: &str) -> HashMap { - | ^^^^^^^^^^^^^^^^^^^ +LL | fn hashmap_not_ok(map: HashMap, key: &str) -> HashMap { + | ^^^^^^^^^^^^^^^^^^^ | = 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, key: &str) -> HashMap { - | ^^^^^^^^^^^^^^^^^^^ +LL | fn hashmap_not_ok(map: HashMap, key: &str) -> HashMap { + | ^^^^^^^^^^^^^^^^^^^ | = help: consider using a set instead @@ -50,10 +50,18 @@ LL | let _: HashMap = HashMap::new(); error: map with zero-sized value type --> $DIR/zero_sized_map_values.rs:44:9 | +LL | let _: BTreeMap = 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