summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/result_unit_error.rs
blob: a4ec803024edf68689d732abaf090ac9ec21fa87 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#![warn(clippy::result_unit_err)]

pub fn returns_unit_error() -> Result<u32, ()> {
    Err(())
}

fn private_unit_errors() -> Result<String, ()> {
    Err(())
}

pub trait HasUnitError {
    fn get_that_error(&self) -> Result<bool, ()>;

    fn get_this_one_too(&self) -> Result<bool, ()> {
        Err(())
    }
}

impl HasUnitError for () {
    fn get_that_error(&self) -> Result<bool, ()> {
        Ok(true)
    }
}

trait PrivateUnitError {
    fn no_problem(&self) -> Result<usize, ()>;
}

pub struct UnitErrorHolder;

impl UnitErrorHolder {
    pub fn unit_error(&self) -> Result<usize, ()> {
        Ok(0)
    }
}

// https://github.com/rust-lang/rust-clippy/issues/6546
pub mod issue_6546 {
    type ResInv<A, B> = Result<B, A>;

    pub fn should_lint() -> ResInv<(), usize> {
        Ok(0)
    }

    pub fn should_not_lint() -> ResInv<usize, ()> {
        Ok(())
    }

    type MyRes<A, B> = Result<(A, B), Box<dyn std::error::Error>>;

    pub fn should_not_lint2(x: i32) -> MyRes<i32, ()> {
        Ok((x, ()))
    }
}

fn main() {}