diff --git a/tests/ui/zero_sized_btreemap_values.rs b/tests/ui/zero_sized_btreemap_values.rs new file mode 100644 index 000000000000..5cd254787d83 --- /dev/null +++ b/tests/ui/zero_sized_btreemap_values.rs @@ -0,0 +1,68 @@ +#![warn(clippy::zero_sized_map_values)] +use std::collections::BTreeMap; + +const CONST_OK: Option> = None; +const CONST_NOT_OK: Option> = None; + +static STATIC_OK: Option> = None; +static STATIC_NOT_OK: Option> = None; + +type OkMap = BTreeMap; +type NotOkMap = BTreeMap; + +enum TestEnum { + Ok(BTreeMap), + NotOk(BTreeMap), +} + +struct Test { + ok: BTreeMap, + not_ok: BTreeMap, + + also_not_ok: Vec>, +} + +trait TestTrait { + type Output; + + fn produce_output() -> Self::Output; + + fn weird_map(&self, map: BTreeMap); +} + +impl Test { + fn ok(&self) -> BTreeMap { + todo!() + } + + fn not_ok(&self) -> BTreeMap { + todo!() + } +} + +impl TestTrait for Test { + type Output = BTreeMap; + + fn produce_output() -> Self::Output { + todo!(); + } + + fn weird_map(&self, map: BTreeMap) { + todo!(); + } +} + +fn test(map: BTreeMap, key: &str) -> BTreeMap { + todo!(); +} + +fn test2(map: BTreeMap, key: &str) -> BTreeMap { + todo!(); +} + +fn main() { + let _: BTreeMap = BTreeMap::new(); + let _: BTreeMap = BTreeMap::new(); + + let _: BTreeMap<_, _> = std::iter::empty::<(String, ())>().collect(); +} diff --git a/tests/ui/zero_sized_btreemap_values.stderr b/tests/ui/zero_sized_btreemap_values.stderr new file mode 100644 index 000000000000..334d921a9af3 --- /dev/null +++ b/tests/ui/zero_sized_btreemap_values.stderr @@ -0,0 +1,107 @@ +error: map with zero-sized value type + --> $DIR/zero_sized_btreemap_values.rs:5:28 + | +LL | const CONST_NOT_OK: Option> = None; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::zero-sized-map-values` implied by `-D warnings` + = help: consider using a set instead + +error: map with zero-sized value type + --> $DIR/zero_sized_btreemap_values.rs:8:30 + | +LL | static STATIC_NOT_OK: Option> = None; + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: consider using a set instead + +error: map with zero-sized value type + --> $DIR/zero_sized_btreemap_values.rs:11:17 + | +LL | type NotOkMap = BTreeMap; + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: consider using a set instead + +error: map with zero-sized value type + --> $DIR/zero_sized_btreemap_values.rs:15:11 + | +LL | NotOk(BTreeMap), + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: consider using a set instead + +error: map with zero-sized value type + --> $DIR/zero_sized_btreemap_values.rs:20:13 + | +LL | not_ok: BTreeMap, + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: consider using a set instead + +error: map with zero-sized value type + --> $DIR/zero_sized_btreemap_values.rs:22:22 + | +LL | also_not_ok: Vec>, + | ^^^^^^^^^^^^^^^^^^^ + | + = help: consider using a set instead + +error: map with zero-sized value type + --> $DIR/zero_sized_btreemap_values.rs:30:30 + | +LL | fn weird_map(&self, map: BTreeMap); + | ^^^^^^^^^^^^^^^^^^^ + | + = help: consider using a set instead + +error: map with zero-sized value type + --> $DIR/zero_sized_btreemap_values.rs:38:25 + | +LL | fn not_ok(&self) -> BTreeMap { + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: consider using a set instead + +error: map with zero-sized value type + --> $DIR/zero_sized_btreemap_values.rs:55:14 + | +LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: consider using a set instead + +error: map with zero-sized value type + --> $DIR/zero_sized_btreemap_values.rs:55:50 + | +LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: consider using a set instead + +error: map with zero-sized value type + --> $DIR/zero_sized_btreemap_values.rs:64:35 + | +LL | let _: BTreeMap = BTreeMap::new(); + | ^^^^^^^^^^^^^ + | + = help: consider using a set instead + +error: map with zero-sized value type + --> $DIR/zero_sized_btreemap_values.rs:64:12 + | +LL | let _: BTreeMap = BTreeMap::new(); + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: consider using a set instead + +error: map with zero-sized value type + --> $DIR/zero_sized_btreemap_values.rs:67:12 + | +LL | let _: BTreeMap<_, _> = std::iter::empty::<(String, ())>().collect(); + | ^^^^^^^^^^^^^^ + | + = help: consider using a set instead + +error: aborting due to 13 previous errors + diff --git a/tests/ui/zero_sized_map_values.rs b/tests/ui/zero_sized_hashmap_values.rs similarity index 90% rename from tests/ui/zero_sized_map_values.rs rename to tests/ui/zero_sized_hashmap_values.rs index 09519b0011c5..a1608d863fb5 100644 --- a/tests/ui/zero_sized_map_values.rs +++ b/tests/ui/zero_sized_hashmap_values.rs @@ -1,5 +1,5 @@ #![warn(clippy::zero_sized_map_values)] -use std::collections::{BTreeMap, HashMap}; +use std::collections::HashMap; const CONST_OK: Option> = None; const CONST_NOT_OK: Option> = None; @@ -61,10 +61,8 @@ fn test2(map: HashMap, key: &str) -> HashMap { } fn main() { - // test code goes here let _: HashMap = HashMap::new(); let _: HashMap = HashMap::new(); let _: HashMap<_, _> = std::iter::empty::<(String, ())>().collect(); - let _: BTreeMap<_, _> = std::iter::empty::<(String, ())>().collect(); } diff --git a/tests/ui/zero_sized_map_values.stderr b/tests/ui/zero_sized_hashmap_values.stderr similarity index 75% rename from tests/ui/zero_sized_map_values.stderr rename to tests/ui/zero_sized_hashmap_values.stderr index 984ac401aa24..43987b3d01d1 100644 --- a/tests/ui/zero_sized_map_values.stderr +++ b/tests/ui/zero_sized_hashmap_values.stderr @@ -1,5 +1,5 @@ error: map with zero-sized value type - --> $DIR/zero_sized_map_values.rs:5:28 + --> $DIR/zero_sized_hashmap_values.rs:5:28 | LL | const CONST_NOT_OK: Option> = None; | ^^^^^^^^^^^^^^^^^^^ @@ -8,7 +8,7 @@ LL | const CONST_NOT_OK: Option> = None; = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_map_values.rs:8:30 + --> $DIR/zero_sized_hashmap_values.rs:8:30 | LL | static STATIC_NOT_OK: Option> = None; | ^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | static STATIC_NOT_OK: Option> = None; = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_map_values.rs:11:17 + --> $DIR/zero_sized_hashmap_values.rs:11:17 | LL | type NotOkMap = HashMap; | ^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | type NotOkMap = HashMap; = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_map_values.rs:15:11 + --> $DIR/zero_sized_hashmap_values.rs:15:11 | LL | NotOk(HashMap), | ^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | NotOk(HashMap), = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_map_values.rs:20:13 + --> $DIR/zero_sized_hashmap_values.rs:20:13 | LL | not_ok: HashMap, | ^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | not_ok: HashMap, = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_map_values.rs:22:22 + --> $DIR/zero_sized_hashmap_values.rs:22:22 | LL | also_not_ok: Vec>, | ^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | also_not_ok: Vec>, = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_map_values.rs:30:30 + --> $DIR/zero_sized_hashmap_values.rs:30:30 | LL | fn weird_map(&self, map: HashMap); | ^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ 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:38:25 + --> $DIR/zero_sized_hashmap_values.rs:38:25 | LL | fn not_ok(&self) -> HashMap { | ^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | fn not_ok(&self) -> HashMap { = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_map_values.rs:55:14 + --> $DIR/zero_sized_hashmap_values.rs:55:14 | LL | fn test(map: HashMap, key: &str) -> HashMap { | ^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | fn test(map: HashMap, key: &str) -> HashMap { = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_map_values.rs:55:49 + --> $DIR/zero_sized_hashmap_values.rs:55:49 | LL | fn test(map: HashMap, key: &str) -> HashMap { | ^^^^^^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL | fn test(map: HashMap, key: &str) -> HashMap { = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_map_values.rs:65:34 + --> $DIR/zero_sized_hashmap_values.rs:64:34 | LL | let _: HashMap = HashMap::new(); | ^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | let _: HashMap = HashMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_map_values.rs:65:12 + --> $DIR/zero_sized_hashmap_values.rs:64:12 | LL | let _: HashMap = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^ @@ -96,20 +96,12 @@ LL | let _: HashMap = HashMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_map_values.rs:68:12 + --> $DIR/zero_sized_hashmap_values.rs:67:12 | LL | let _: HashMap<_, _> = std::iter::empty::<(String, ())>().collect(); | ^^^^^^^^^^^^^ | = help: consider using a set instead -error: map with zero-sized value type - --> $DIR/zero_sized_map_values.rs:69:12 - | -LL | let _: BTreeMap<_, _> = std::iter::empty::<(String, ())>().collect(); - | ^^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: aborting due to 14 previous errors +error: aborting due to 13 previous errors