From: Jason Ish Date: Mon, 29 Jun 2020 17:09:16 +0000 (-0600) Subject: rust: macro debug_validate_fail to fail with message X-Git-Tag: suricata-6.0.0-beta1~295 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca6b70ea1b9383df1367bdddfc86ddb0380ff7a9;p=thirdparty%2Fsuricata.git rust: macro debug_validate_fail to fail with message Add a new debug_validate macro that unconditionally panics with a message. Useful in Rust pattern matching. --- diff --git a/rust/src/common.rs b/rust/src/common.rs index ce386e695b..d9341881f7 100644 --- a/rust/src/common.rs +++ b/rust/src/common.rs @@ -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