rust-clippy/tests/ui/less_concise_than.fixed
2020-10-14 22:16:48 +02:00

43 lines
782 B
Rust

// run-rustfix
#![warn(clippy::less_concise_than_option_unwrap_or)]
#![allow(dead_code)]
fn unwrap_or() {
// int case
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() {}