rust/tests/ui/manual_unwrap_or.fixed

46 lines
782 B
Rust
Raw Normal View History

// run-rustfix
#![allow(dead_code)]
fn unwrap_or() {
// int case
Some(1).unwrap_or(42);
2020-10-11 20:55:05 +00:00
// int case reversed
Some(1).unwrap_or(42);
// richer none expr
Some(1).unwrap_or_else(|| 1 + 42);
// multiline case
Some(1).unwrap_or_else(|| {
let a = 1 + 42;
let b = a + 42;
b + 42
});
// string case
Some("Bob").unwrap_or("Alice");
// don't lint
match Some(1) {
Some(i) => i + 2,
None => 42,
};
match Some(1) {
Some(i) => i,
None => return,
};
for j in 0..4 {
match Some(j) {
Some(i) => i,
None => continue,
};
match Some(j) {
Some(i) => i,
None => break,
};
}
}
fn main() {}