From e5d8eb2fef4feed9fd7652f87e25b77bc78e1913 Mon Sep 17 00:00:00 2001 From: Korrat Date: Sat, 14 Nov 2020 13:48:58 +0100 Subject: [PATCH] Add tests for const, static, type alias, enum, and method --- .cargo/config | 1 + tests/ui/zero_sized_map_values.rs | 24 ++++++++++ tests/ui/zero_sized_map_values.stderr | 66 +++++++++++++++++++++++---- 3 files changed, 82 insertions(+), 9 deletions(-) diff --git a/.cargo/config b/.cargo/config index e70da43ab47a..8df7a8a275b2 100644 --- a/.cargo/config +++ b/.cargo/config @@ -4,3 +4,4 @@ dev = "run --target-dir clippy_dev/target --package clippy_dev --bin clippy_dev [build] rustflags = ["-Zunstable-options"] +rustc-wrapper = "" diff --git a/tests/ui/zero_sized_map_values.rs b/tests/ui/zero_sized_map_values.rs index 3a0f11ddf2f4..822d09254897 100644 --- a/tests/ui/zero_sized_map_values.rs +++ b/tests/ui/zero_sized_map_values.rs @@ -1,6 +1,20 @@ #![warn(clippy::zero_sized_map_values)] use std::collections::HashMap; +const CONST_OK: Option> = None; +const CONST_NOT_OK: Option> = None; + +static STATIC_OK: Option> = None; +static STATIC_NOT_OK: Option> = None; + +type OkMap = HashMap; +type NotOkMap = HashMap; + +enum TestEnum { + Ok(HashMap), + NotOk(HashMap), +} + struct Test { ok: HashMap, not_ok: HashMap, @@ -16,6 +30,16 @@ trait TestTrait { fn weird_map(&self, map: HashMap); } +impl Test { + fn ok(&self) -> HashMap { + todo!() + } + + fn not_ok(&self) -> HashMap { + todo!() + } +} + impl TestTrait for Test { type Output = HashMap; diff --git a/tests/ui/zero_sized_map_values.stderr b/tests/ui/zero_sized_map_values.stderr index 3806bb93fb42..31258ec73ac0 100644 --- a/tests/ui/zero_sized_map_values.stderr +++ b/tests/ui/zero_sized_map_values.stderr @@ -1,14 +1,46 @@ error: map with zero-sized value type - --> $DIR/zero_sized_map_values.rs:6:13 + --> $DIR/zero_sized_map_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_map_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_map_values.rs:11:17 + | +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 + | +LL | NotOk(HashMap), + | ^^^^^^^^^^^^^^^^^^^ + | + = help: consider using a set instead + +error: map with zero-sized value type + --> $DIR/zero_sized_map_values.rs:20:13 | LL | not_ok: HashMap, | ^^^^^^^^^^^^^^^^^^^ | - = 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_map_values.rs:8:22 + --> $DIR/zero_sized_map_values.rs:22:22 | LL | also_not_ok: Vec>, | ^^^^^^^^^^^^^^^^^^ @@ -16,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:16:30 + --> $DIR/zero_sized_map_values.rs:30:30 | LL | fn weird_map(&self, map: HashMap); | ^^^^^^^^^^^^^^^^^^ @@ -24,7 +56,15 @@ 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:38:25 + | +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 | LL | fn test(map: HashMap, key: &str) -> HashMap { | ^^^^^^^^^^^^^^^^^^^ @@ -32,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:31:49 + --> $DIR/zero_sized_map_values.rs:55:49 | LL | fn test(map: HashMap, key: &str) -> HashMap { | ^^^^^^^^^^^^^^^^^^^ @@ -40,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:41:9 + --> $DIR/zero_sized_map_values.rs:65:9 | LL | let _: HashMap = HashMap::new(); | ^ @@ -48,12 +88,20 @@ LL | let _: HashMap = HashMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_map_values.rs:44:9 + --> $DIR/zero_sized_map_values.rs:65: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: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 13 previous errors