// 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 Result expr with parenthesis
+ // int case, suggestion must surround Result expr with parentheses
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 {}
+ // method call case, suggestion must not surround Result expr `s.method()` with parentheses
+ struct S;
impl S {
fn method(self) -> Option<i32> {
Some(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,
+ };
+ }
+}
+
+use std::rc::Rc;
+fn format_name(name: Option<&Rc<str>>) -> &str {
+ match name {
+ None => "<anon>",
+ Some(name) => name,
+ }
+}
+
+fn implicit_deref_ref() {
+ let _: &str = match Some(&"bye") {
+ None => "hi",
+ Some(s) => s,
+ };
+}
+
fn main() {}