summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/panic_in_result_fn.rs
blob: 41e2f5226899d3f894b72758b0fb4a8e86a7e5a4 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#![warn(clippy::panic_in_result_fn)]
#![allow(clippy::unnecessary_wraps)]
struct A;

impl A {
    fn result_with_panic() -> Result<bool, String> // should emit lint
    //~^ ERROR: used `panic!()` or assertion in a function that returns `Result`
    {
        panic!("error");
    }

    fn result_with_unimplemented() -> Result<bool, String> // should emit lint
    {
        unimplemented!();
    }

    fn result_with_unreachable() -> Result<bool, String> // should emit lint
    {
        unreachable!();
    }

    fn result_with_todo() -> Result<bool, String> // should emit lint
    {
        todo!("Finish this");
    }

    fn other_with_panic() // should not emit lint
    {
        panic!("");
    }

    fn other_with_unreachable() // should not emit lint
    {
        unreachable!();
    }

    fn other_with_unimplemented() // should not emit lint
    {
        unimplemented!();
    }

    fn other_with_todo() // should not emit lint
    {
        todo!("finish this")
    }

    fn result_without_banned_functions() -> Result<bool, String> // should not emit lint
    {
        Ok(true)
    }
}

fn function_result_with_panic() -> Result<bool, String> // should emit lint
//~^ ERROR: used `panic!()` or assertion in a function that returns `Result`
{
    panic!("error");
}

fn todo() {
    println!("something");
}

fn function_result_with_custom_todo() -> Result<bool, String> // should not emit lint
{
    todo();
    Ok(true)
}

fn main() -> Result<(), String> {
    todo!("finish main method");
    Ok(())
}