summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/unit_hash.rs
blob: f3636d1644da93e27fe2be1ad5d477b03fd1469c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#![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 => ().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
        Foo::WithValue(x) => x.hash(&mut state),
    }

    let res = ();
    res.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

    #[allow(clippy::unit_arg)]
    do_nothing().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
}