summaryrefslogtreecommitdiffstats
path: root/tests/ui/lint/unused/must-use-ops.rs
blob: 60f877aa8b30327ad6f60fe740ae995cf02d7716 (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
// Issue #50124 - Test warning for unused operator expressions

// check-pass

#![warn(unused_must_use)]
#![feature(never_type)]

fn deref_never(x: &!) {
    // Don't lint for uninhabited typess
    *x;
}

fn main() {
    let val = 1;
    let val_pointer = &val;

    // Comparison Operators
    val == 1; //~ WARNING unused comparison
    val < 1; //~ WARNING unused comparison
    val <= 1; //~ WARNING unused comparison
    val != 1; //~ WARNING unused comparison
    val >= 1; //~ WARNING unused comparison
    val > 1; //~ WARNING unused comparison

    // Arithmetic Operators
    val + 2; //~ WARNING unused arithmetic operation
    val - 2; //~ WARNING unused arithmetic operation
    val / 2; //~ WARNING unused arithmetic operation
    val * 2; //~ WARNING unused arithmetic operation
    val % 2; //~ WARNING unused arithmetic operation

    // Logical Operators
    true && true; //~ WARNING unused logical operation
    false || true; //~ WARNING unused logical operation

    // Bitwise Operators
    5 ^ val; //~ WARNING unused bitwise operation
    5 & val; //~ WARNING unused bitwise operation
    5 | val; //~ WARNING unused bitwise operation
    5 << val; //~ WARNING unused bitwise operation
    5 >> val; //~ WARNING unused bitwise operation

    // Unary Operators
    !val; //~ WARNING unused unary operation
    -val; //~ WARNING unused unary operation
    *val_pointer; //~ WARNING unused unary operation

    if false {
        deref_never(&panic!());
    }
}