summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/partialeq_to_none.fixed
blob: 4644ea8f51da1ecd6def7c067aff736cdcebfd8a (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
73
74
// run-rustfix
#![warn(clippy::partialeq_to_none)]

struct Foobar;

impl PartialEq<Option<()>> for Foobar {
    fn eq(&self, _: &Option<()>) -> bool {
        false
    }
}

#[allow(dead_code)]
fn foo(f: Option<u32>) -> &'static str {
    if f.is_some() { "yay" } else { "nay" }
}

fn foobar() -> Option<()> {
    None
}

fn bar() -> Result<(), ()> {
    Ok(())
}

fn optref() -> &'static &'static Option<()> {
    &&None
}

pub fn macro_expansion() {
    macro_rules! foo {
        () => {
            None::<()>
        };
    }

    let _ = foobar() == foo!();
    let _ = foo!() == foobar();
    let _ = foo!() == foo!();
}

fn main() {
    let x = Some(0);

    let _ = x.is_none();
    let _ = x.is_some();
    let _ = x.is_none();
    let _ = x.is_some();

    if foobar().is_none() {}

    if bar().ok().is_some() {}

    let _ = Some(1 + 2).is_some();

    let _ = { Some(0) }.is_none();

    let _ = {
        /*
          This comment runs long
        */
        Some(1)
    }.is_some();

    // Should not trigger, as `Foobar` is not an `Option` and has no `is_none`
    let _ = Foobar == None;

    let _ = optref().is_none();
    let _ = optref().is_some();
    let _ = optref().is_none();
    let _ = optref().is_some();

    let x = Box::new(Option::<()>::None);
    let _ = (*x).is_some();
}