summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/zero_sized_hashmap_values.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/tools/clippy/tests/ui/zero_sized_hashmap_values.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui/zero_sized_hashmap_values.rs')
-rw-r--r--src/tools/clippy/tests/ui/zero_sized_hashmap_values.rs68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/zero_sized_hashmap_values.rs b/src/tools/clippy/tests/ui/zero_sized_hashmap_values.rs
new file mode 100644
index 000000000..a1608d863
--- /dev/null
+++ b/src/tools/clippy/tests/ui/zero_sized_hashmap_values.rs
@@ -0,0 +1,68 @@
+#![warn(clippy::zero_sized_map_values)]
+use std::collections::HashMap;
+
+const CONST_OK: Option<HashMap<String, usize>> = None;
+const CONST_NOT_OK: Option<HashMap<String, ()>> = None;
+
+static STATIC_OK: Option<HashMap<String, usize>> = None;
+static STATIC_NOT_OK: Option<HashMap<String, ()>> = None;
+
+type OkMap = HashMap<String, usize>;
+type NotOkMap = HashMap<String, ()>;
+
+enum TestEnum {
+ Ok(HashMap<String, usize>),
+ NotOk(HashMap<String, ()>),
+}
+
+struct Test {
+ ok: HashMap<String, usize>,
+ not_ok: HashMap<String, ()>,
+
+ also_not_ok: Vec<HashMap<usize, ()>>,
+}
+
+trait TestTrait {
+ type Output;
+
+ fn produce_output() -> Self::Output;
+
+ fn weird_map(&self, map: HashMap<usize, ()>);
+}
+
+impl Test {
+ fn ok(&self) -> HashMap<String, usize> {
+ todo!()
+ }
+
+ fn not_ok(&self) -> HashMap<String, ()> {
+ todo!()
+ }
+}
+
+impl TestTrait for Test {
+ type Output = HashMap<String, ()>;
+
+ fn produce_output() -> Self::Output {
+ todo!();
+ }
+
+ fn weird_map(&self, map: HashMap<usize, ()>) {
+ todo!();
+ }
+}
+
+fn test(map: HashMap<String, ()>, key: &str) -> HashMap<String, ()> {
+ todo!();
+}
+
+fn test2(map: HashMap<String, usize>, key: &str) -> HashMap<String, usize> {
+ todo!();
+}
+
+fn main() {
+ let _: HashMap<String, ()> = HashMap::new();
+ let _: HashMap<String, usize> = HashMap::new();
+
+ let _: HashMap<_, _> = std::iter::empty::<(String, ())>().collect();
+}