about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/expect.rs
blob: 1ab01ecfcfe3a2d1a2d503349d9c9b77e8db5eff (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
#![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, u8> = Ok(0);
    let _ = res.expect("");
    //~^ expect_used

    let _ = res.expect_err("");
    //~^ expect_used
}

#[allow(clippy::ok_expect)]
#[allow(clippy::err_expect)]
fn issue_15247() {
    let x: Result<u8, u8> = Err(0);
    x.ok().expect("Huh");
    //~^ expect_used

    { x.ok() }.expect("...");
    //~^ expect_used

    let y: Result<u8, u8> = Ok(0);
    y.err().expect("Huh");
    //~^ expect_used

    { y.err() }.expect("...");
    //~^ expect_used
}

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