2024-03-21 21:20:40 +00:00
|
|
|
#![warn(clippy::manual_unwrap_or_default)]
|
|
|
|
#![allow(clippy::unnecessary_literal_unwrap)]
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let x: Option<Vec<String>> = None;
|
|
|
|
x.unwrap_or_default();
|
|
|
|
|
|
|
|
let x: Option<Vec<String>> = None;
|
|
|
|
x.unwrap_or_default();
|
|
|
|
|
|
|
|
let x: Option<String> = None;
|
|
|
|
x.unwrap_or_default();
|
|
|
|
|
|
|
|
let x: Option<Vec<String>> = None;
|
|
|
|
x.unwrap_or_default();
|
|
|
|
|
|
|
|
let x: Option<Vec<String>> = None;
|
|
|
|
x.unwrap_or_default();
|
|
|
|
}
|
2024-04-04 17:52:55 +00:00
|
|
|
|
|
|
|
// Issue #12531
|
|
|
|
unsafe fn no_deref_ptr(a: Option<i32>, b: *const Option<i32>) -> i32 {
|
|
|
|
match a {
|
|
|
|
// `*b` being correct depends on `a == Some(_)`
|
|
|
|
Some(_) => (*b).unwrap_or_default(),
|
|
|
|
_ => 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const fn issue_12568(opt: Option<bool>) -> bool {
|
|
|
|
match opt {
|
|
|
|
Some(s) => s,
|
|
|
|
None => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_12569() {
|
|
|
|
let match_none_se = match 1u32.checked_div(0) {
|
|
|
|
Some(v) => v,
|
|
|
|
None => {
|
|
|
|
println!("important");
|
|
|
|
0
|
|
|
|
},
|
|
|
|
};
|
|
|
|
let match_some_se = match 1u32.checked_div(0) {
|
|
|
|
Some(v) => {
|
|
|
|
println!("important");
|
|
|
|
v
|
|
|
|
},
|
|
|
|
None => 0,
|
|
|
|
};
|
|
|
|
let iflet_else_se = if let Some(v) = 1u32.checked_div(0) {
|
|
|
|
v
|
|
|
|
} else {
|
|
|
|
println!("important");
|
|
|
|
0
|
|
|
|
};
|
|
|
|
let iflet_then_se = if let Some(v) = 1u32.checked_div(0) {
|
|
|
|
println!("important");
|
|
|
|
v
|
|
|
|
} else {
|
|
|
|
0
|
|
|
|
};
|
|
|
|
}
|