]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/unnecessary_wraps.rs
Auto merge of #9684 - kraktus:ref_option_ref, r=xFrednet
[rust.git] / tests / ui / unnecessary_wraps.rs
index a53dec8f91ac50acae35e3d5c02ec13a501e8456..63648ef5826f6e1f2c5009050393c4b884e9a735 100644 (file)
@@ -22,29 +22,17 @@ fn func2(a: bool, b: bool) -> Option<i32> {
     if a && b {
         return Some(10);
     }
-    if a {
-        Some(20)
-    } else {
-        Some(30)
-    }
+    if a { Some(20) } else { Some(30) }
 }
 
 // public fns should not be linted
 pub fn func3(a: bool) -> Option<i32> {
-    if a {
-        Some(1)
-    } else {
-        Some(1)
-    }
+    if a { Some(1) } else { Some(1) }
 }
 
 // should not be linted
 fn func4(a: bool) -> Option<i32> {
-    if a {
-        Some(1)
-    } else {
-        None
-    }
+    if a { Some(1) } else { None }
 }
 
 // should be linted
@@ -64,11 +52,7 @@ fn func7() -> Result<i32, ()> {
 
 // should not be linted
 fn func8(a: bool) -> Result<i32, ()> {
-    if a {
-        Ok(1)
-    } else {
-        Err(())
-    }
+    if a { Ok(1) } else { Err(()) }
 }
 
 // should not be linted
@@ -81,7 +65,7 @@ fn func10() -> Option<()> {
     unimplemented!()
 }
 
-struct A;
+pub struct A;
 
 impl A {
     // should not be linted
@@ -109,8 +93,52 @@ fn func13() -> Option<i32> {
     }
 }
 
+fn issue_6384(s: &str) -> Option<&str> {
+    Some(match s {
+        "a" => "A",
+        _ => return None,
+    })
+}
+
+// should be linted
+fn issue_6640_1(a: bool, b: bool) -> Option<()> {
+    if a && b {
+        return Some(());
+    }
+    if a {
+        Some(());
+        Some(())
+    } else {
+        return Some(());
+    }
+}
+
+// should be linted
+fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> {
+    if a && b {
+        return Ok(());
+    }
+    if a {
+        Ok(())
+    } else {
+        return Ok(());
+    }
+}
+
+// should not be linted
+fn issue_6640_3() -> Option<()> {
+    if true { Some(()) } else { None }
+}
+
+// should not be linted
+fn issue_6640_4() -> Result<(), ()> {
+    if true { Ok(()) } else { Err(()) }
+}
+
 fn main() {
     // method calls are not linted
     func1(true, true);
     func2(true, true);
+    issue_6640_1(true, true);
+    issue_6640_2(true, true);
 }