Skip to content

Commit

Permalink
Add tests for const, static, type alias, enum, and method
Browse files Browse the repository at this point in the history
  • Loading branch information
korrat committed Nov 14, 2020
1 parent 76fb981 commit e5d8eb2
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 9 deletions.
1 change: 1 addition & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dev = "run --target-dir clippy_dev/target --package clippy_dev --bin clippy_dev

[build]
rustflags = ["-Zunstable-options"]
rustc-wrapper = ""
24 changes: 24 additions & 0 deletions tests/ui/zero_sized_map_values.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
#![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, ()>,
Expand All @@ -16,6 +30,16 @@ trait TestTrait {
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, ()>;

Expand Down
66 changes: 57 additions & 9 deletions tests/ui/zero_sized_map_values.stderr
Original file line number Diff line number Diff line change
@@ -1,59 +1,107 @@
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<HashMap<String, ()>> = 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<HashMap<String, ()>> = 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<String, ()>;
| ^^^^^^^^^^^^^^^^^^^
|
= help: consider using a set instead

error: map with zero-sized value type
--> $DIR/zero_sized_map_values.rs:15:11
|
LL | NotOk(HashMap<String, ()>),
| ^^^^^^^^^^^^^^^^^^^
|
= 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<String, ()>,
| ^^^^^^^^^^^^^^^^^^^
|
= 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<HashMap<usize, ()>>,
| ^^^^^^^^^^^^^^^^^^
|
= 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<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:38:25
|
LL | fn not_ok(&self) -> HashMap<String, ()> {
| ^^^^^^^^^^^^^^^^^^^
|
= 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<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:55:49
|
LL | fn test(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:41:9
--> $DIR/zero_sized_map_values.rs:65:9
|
LL | let _: HashMap<String, ()> = 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<String, ()> = 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

0 comments on commit e5d8eb2

Please sign in to comment.