rust/tests/ui/is_unit_expr.rs

74 lines
1.1 KiB
Rust
Raw Normal View History

2017-09-18 12:47:33 +02:00
2017-09-03 19:39:28 +02:00
#![warn(unit_expr)]
2017-09-03 17:56:34 +02:00
#[allow(unused_variables)]
fn main() {
2017-09-03 22:46:49 +02:00
// lint should note removing the semicolon from "baz"
2017-09-03 17:56:34 +02:00
let x = {
"foo";
"baz";
};
2017-09-03 22:46:49 +02:00
// lint should ignore false positive.
let y = if true {
"foo"
} else {
return;
};
2017-09-03 22:46:49 +02:00
// lint should note removing semicolon from "bar"
let z = if true {
"foo";
2017-09-03 22:46:49 +02:00
} else {
"bar";
};
let a1 = Some(5);
2017-09-03 22:46:49 +02:00
// lint should ignore false positive
let a2 = match a1 {
Some(x) => x,
2017-09-03 22:46:49 +02:00
_ => {
return;
},
};
2017-09-03 22:46:49 +02:00
// lint should note removing the semicolon after `x;`
let a3 = match a1 {
2017-09-03 22:46:49 +02:00
Some(x) => {
x;
},
_ => {
0;
},
};
loop {
let a2 = match a1 {
Some(x) => x,
_ => {
break;
},
};
let a2 = match a1 {
Some(x) => x,
_ => {
continue;
},
};
}
}
pub fn foo() -> i32 {
let a2 = match None {
Some(x) => x,
_ => {
return 42;
},
};
55
2017-09-03 17:56:34 +02:00
}