// run-rustfix
#![allow(dead_code)]
-#![allow(unused_variables)]
+#![allow(unused_variables, clippy::unnecessary_wraps)]
fn option_unwrap_or() {
// int case
Err(_) => 42,
};
- // int case, suggestion must surround with parenthesis
+ // int case, suggestion must surround Result expr with parenthesis
match Ok(1) as Result<i32, &str> {
Ok(i) => i,
Err(_) => 42,
};
+ // method call case, suggestion must not surround Result expr `s.method()` with parenthesis
+ struct S {}
+ impl S {
+ fn method(self) -> Option<i32> {
+ Some(42)
+ }
+ }
+ let s = S {};
+ match s.method() {
+ Some(i) => i,
+ None => 42,
+ };
+
// int case reversed
match Ok::<i32, &str>(1) {
Err(_) => 42,
};
}
+// don't lint in const fn
+const fn const_fn_option_unwrap_or() {
+ match Some(1) {
+ Some(s) => s,
+ None => 0,
+ };
+}
+
+const fn const_fn_result_unwrap_or() {
+ match Ok::<&str, &str>("Alice") {
+ Ok(s) => s,
+ Err(_) => "Bob",
+ };
+}
+
+mod issue6965 {
+ macro_rules! some_macro {
+ () => {
+ if 1 > 2 { Some(1) } else { None }
+ };
+ }
+
+ fn test() {
+ let _ = match some_macro!() {
+ Some(val) => val,
+ None => 0,
+ };
+ }
+}
+
fn main() {}