about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorjumbatm <jumbatm@gmail.com>2020-04-23 20:17:15 +1000
committerjumbatm <jumbatm@gmail.com>2020-05-01 21:52:43 +1000
commit14d90deab9cbbc1bfb45af52f9dc9fbce945da91 (patch)
tree6b831afce64007ae4fd8cf264135198554132da4 /src
parentbd0bacc694d7d8175804bb6f690cb846bfa4a9ee (diff)
downloadrust-14d90deab9cbbc1bfb45af52f9dc9fbce945da91.tar.gz
rust-14d90deab9cbbc1bfb45af52f9dc9fbce945da91.zip
Don't duplicate macro for optional arg.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_mir/interpret/validity.rs30
1 files changed, 6 insertions, 24 deletions
diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs
index df3c3532203..0b6422316ea 100644
--- a/src/librustc_mir/interpret/validity.rs
+++ b/src/librustc_mir/interpret/validity.rs
@@ -24,43 +24,25 @@ use super::{
 };
 
 macro_rules! throw_validation_failure {
-    ($what:expr, $where:expr, $details:expr) => {{
-        let mut msg = format!("encountered {}", $what);
-        let where_ = &$where;
-        if !where_.is_empty() {
-            msg.push_str(" at ");
-            write_path(&mut msg, where_);
-        }
-        write!(&mut msg, ", but expected {}", $details).unwrap();
-        throw_ub!(ValidationFailure(msg))
-    }};
-    ($what:expr, $where:expr) => {{
+    ($what:expr, $where:expr $(, $details:expr )?) => {{
         let mut msg = format!("encountered {}", $what);
         let where_ = &$where;
         if !where_.is_empty() {
             msg.push_str(" at ");
             write_path(&mut msg, where_);
         }
+        $( write!(&mut msg, ", but expected {}", $details).unwrap(); )?
         throw_ub!(ValidationFailure(msg))
     }};
 }
 
 macro_rules! try_validation {
-    ($e:expr, $what:expr, $where:expr, $details:expr) => {{
-        match $e {
-            Ok(x) => x,
-            // We re-throw the error, so we are okay with allocation:
-            // this can only slow down builds that fail anyway.
-            Err(_) => throw_validation_failure!($what, $where, $details),
-        }
-    }};
-
-    ($e:expr, $what:expr, $where:expr) => {{
+    ($e:expr, $what:expr, $where:expr $(, $details:expr )?) => {{
         match $e {
             Ok(x) => x,
-            // We re-throw the error, so we are okay with allocation:
-            // this can only slow down builds that fail anyway.
-            Err(_) => throw_validation_failure!($what, $where),
+            // We catch the error and turn it into a validation failure. We are okay with
+            // allocation here as this can only slow down builds that fail anyway.
+            Err(_) => throw_validation_failure!($what, $where $(, $details)?),
         }
     }};
 }