]> git.lizzy.rs Git - rust.git/commitdiff
Simplify if else as suggested in PR feedback
authorThomas Etter <thomas.etter@auterion.com>
Tue, 19 Nov 2019 20:35:07 +0000 (21:35 +0100)
committerThomas Etter <thomas.etter@auterion.com>
Tue, 19 Nov 2019 20:44:45 +0000 (21:44 +0100)
src/libtest/test_result.rs

index 5dbbd71554e984bcf9b6c11ebe311f6deaf669e5..bfabe1722dbedc53d2c693a8a06da24a06d3faa3 100644 (file)
@@ -42,29 +42,25 @@ pub fn calc_result<'a>(
                 .map(|e| &**e)
                 .or_else(|| err.downcast_ref::<&'static str>().map(|e| *e));
 
-            if maybe_panic_str
-                .map(|e| e.contains(msg))
-                .unwrap_or(false)
-            {
+            if maybe_panic_str.map(|e| e.contains(msg)).unwrap_or(false) {
                 TestResult::TrOk
-            } else {
-                if desc.allow_fail {
-                    TestResult::TrAllowedFail
-                } else {
-                    if let Some(panic_str) = maybe_panic_str{
-                        TestResult::TrFailedMsg(
-                            format!(r#"panic did not contain expected string
+            } else if desc.allow_fail {
+                TestResult::TrAllowedFail
+            } else if let Some(panic_str) = maybe_panic_str {
+                TestResult::TrFailedMsg(format!(
+                    r#"panic did not contain expected string
       panic message: `{:?}`,
- expected substring: `{:?}`"#, panic_str, &*msg)
-                        )
-                    } else {
-                        TestResult::TrFailedMsg(
-                            format!(r#"expected panic with string value,
+ expected substring: `{:?}`"#,
+                    panic_str, msg
+                ))
+            } else {
+                TestResult::TrFailedMsg(format!(
+                    r#"expected panic with string value,
  found non-string value: `{:?}`
-     expected substring: `{:?}`"#, (**err).type_id(), &*msg)
-                        )
-                    }
-                }
+     expected substring: `{:?}`"#,
+                    (**err).type_id(),
+                    msg
+                ))
             }
         }
         (&ShouldPanic::Yes, Ok(())) => {