about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-04-30 22:46:28 +0000
committerbors <bors@rust-lang.org>2019-04-30 22:46:28 +0000
commit96ee0ba59e12f5350e799ba724a58fd488a739f2 (patch)
treefcf4b51d0a71e3cea9a06dbc74bd1e486e01026e
parent7c71bc3208031b1307573de45a3b3e18fa45787a (diff)
parent942831eef4ddc75c72e3f9921a219a00f1622082 (diff)
downloadrust-96ee0ba59e12f5350e799ba724a58fd488a739f2.tar.gz
rust-96ee0ba59e12f5350e799ba724a58fd488a739f2.zip
Auto merge of #60204 - jethrogb:jb/rtunwrap-debug-print, r=alexcrichton
Debug-print error when using rtunwrap

When I added this macro a while back I didn't have a way to make it print the failure for all types that you might want to unwrap. Now, I came up with a solution.
-rw-r--r--src/libstd/sys_common/mod.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/libstd/sys_common/mod.rs b/src/libstd/sys_common/mod.rs
index 6260c3b77ff..78e15994264 100644
--- a/src/libstd/sys_common/mod.rs
+++ b/src/libstd/sys_common/mod.rs
@@ -30,10 +30,12 @@ macro_rules! rtassert {
 
 #[allow(unused_macros)] // not used on all platforms
 macro_rules! rtunwrap {
-    ($ok:ident, $e:expr) => (if let $ok(v) = $e {
-        v
-    } else {
-        rtabort!(concat!("unwrap failed: ", stringify!($e)));
+    ($ok:ident, $e:expr) => (match $e {
+        $ok(v) => v,
+        ref err => {
+            let err = err.as_ref().map(|_|()); // map Ok/Some which might not be Debug
+            rtabort!(concat!("unwrap failed: ", stringify!($e), " = {:?}"), err)
+        },
     })
 }