]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust: macro debug_validate_fail to fail with message
authorJason Ish <jason.ish@oisf.net>
Mon, 29 Jun 2020 17:09:16 +0000 (11:09 -0600)
committerVictor Julien <victor@inliniac.net>
Mon, 29 Jun 2020 18:10:46 +0000 (20:10 +0200)
Add a new debug_validate macro that unconditionally panics
with a message. Useful in Rust pattern matching.

rust/src/common.rs

index ce386e695b7f9ba7553d3090564b8e3869e09f75..d9341881f7e33a72a03f57949095914956c3ca46 100644 (file)
@@ -30,6 +30,23 @@ macro_rules! debug_validate_bug_on (
   };
 );
 
+#[cfg(not(feature = "debug-validate"))]
+#[macro_export]
+macro_rules! debug_validate_fail (
+  ($msg:expr) => {};
+);
+
+#[cfg(feature = "debug-validate")]
+#[macro_export]
+macro_rules! debug_validate_fail (
+  ($msg:expr) => {
+    // Wrap in a conditional to prevent unreachable code warning in caller.
+    if true {
+      panic!($msg);
+    }
+  };
+);
+
 /// Convert a String to C-compatible string
 ///
 /// This function will consume the provided data and use the underlying bytes to construct a new