2018-04-21 17:06:48 -05:00
|
|
|
// Issue #50124 - Test warning for unused operator expressions
|
|
|
|
|
2019-11-05 18:00:00 -06:00
|
|
|
// check-pass
|
2018-04-21 17:06:48 -05:00
|
|
|
|
|
|
|
#![warn(unused_must_use)]
|
2022-11-13 06:02:52 -06:00
|
|
|
#![feature(never_type)]
|
|
|
|
|
|
|
|
fn deref_never(x: &!) {
|
|
|
|
// Don't lint for uninhabited typess
|
|
|
|
*x;
|
|
|
|
}
|
2018-04-21 17:06:48 -05:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let val = 1;
|
|
|
|
let val_pointer = &val;
|
|
|
|
|
2022-11-13 06:02:52 -06:00
|
|
|
// Comparison Operators
|
2019-11-05 18:00:00 -06:00
|
|
|
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
|
2018-04-21 17:06:48 -05:00
|
|
|
|
2022-11-13 06:02:52 -06:00
|
|
|
// Arithmetic Operators
|
2019-11-05 18:00:00 -06:00
|
|
|
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
|
2018-04-21 17:06:48 -05:00
|
|
|
|
2022-11-13 06:02:52 -06:00
|
|
|
// Logical Operators
|
2019-11-05 18:00:00 -06:00
|
|
|
true && true; //~ WARNING unused logical operation
|
|
|
|
false || true; //~ WARNING unused logical operation
|
2018-04-21 17:06:48 -05:00
|
|
|
|
2022-11-13 06:02:52 -06:00
|
|
|
// Bitwise Operators
|
2019-11-05 18:00:00 -06:00
|
|
|
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
|
2018-04-21 17:06:48 -05:00
|
|
|
|
2022-11-13 06:02:52 -06:00
|
|
|
// Unary Operators
|
2019-11-05 18:00:00 -06:00
|
|
|
!val; //~ WARNING unused unary operation
|
|
|
|
-val; //~ WARNING unused unary operation
|
|
|
|
*val_pointer; //~ WARNING unused unary operation
|
2022-11-13 06:02:52 -06:00
|
|
|
|
|
|
|
if false {
|
|
|
|
deref_never(&panic!());
|
|
|
|
}
|
2018-04-21 17:06:48 -05:00
|
|
|
}
|