about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui-toml/expect_used/expect_used.rs
blob: 9955c9b6baa1d6522a0dc6babf0f8c242ebf7d04 (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
//@compile-flags: --test
//@no-rustfix
#![warn(clippy::expect_used)]
#![allow(clippy::unnecessary_literal_unwrap)]

fn expect_option() {
    let opt = Some(0);
    let _ = opt.expect("");
    //~^ expect_used
}

fn expect_result() {
    let res: Result<u8, ()> = Ok(0);
    let _ = res.expect("");
    //~^ expect_used
}

fn main() {
    expect_option();
    expect_result();

    const SOME: Option<i32> = Some(3);
    const UNWRAPPED: i32 = SOME.expect("Not three?");
    //~^ expect_used
    const {
        SOME.expect("Still not three?");
        //~^ expect_used
    }
}

#[test]
fn test_expect_option() {
    let opt = Some(0);
    let _ = opt.expect("");
}

#[test]
fn test_expect_result() {
    let res: Result<u8, ()> = Ok(0);
    let _ = res.expect("");
}

#[cfg(test)]
mod issue9612 {
    // should not lint in `#[cfg(test)]` modules
    #[test]
    fn test_fn() {
        let _a: u8 = 2.try_into().unwrap();
        let _a: u8 = 3.try_into().expect("");

        util();
    }

    fn util() {
        let _a: u8 = 4.try_into().unwrap();
        let _a: u8 = 5.try_into().expect("");
    }
}