rust/tests/ui/unit_hash.fixed

35 lines
915 B
Rust
Raw Normal View History

2023-07-27 06:40:22 -05:00
#![warn(clippy::unit_hash)]
#![allow(clippy::let_unit_value)]
use std::collections::hash_map::DefaultHasher;
use std::hash::Hash;
enum Foo {
Empty,
WithValue(u8),
}
fn do_nothing() {}
fn main() {
let mut state = DefaultHasher::new();
let my_enum = Foo::Empty;
match my_enum {
Foo::Empty => 0_u8.hash(&mut state),
//~^ ERROR: this call to `hash` on the unit type will do nothing
//~| NOTE: the implementation of `Hash` for `()` is a no-op
2023-07-27 06:40:22 -05:00
Foo::WithValue(x) => x.hash(&mut state),
}
let res = ();
0_u8.hash(&mut state);
//~^ ERROR: this call to `hash` on the unit type will do nothing
//~| NOTE: the implementation of `Hash` for `()` is a no-op
2023-07-27 06:40:22 -05:00
#[allow(clippy::unit_arg)]
0_u8.hash(&mut state);
//~^ ERROR: this call to `hash` on the unit type will do nothing
//~| NOTE: the implementation of `Hash` for `()` is a no-op
2023-07-27 06:40:22 -05:00
}