diff --git a/src/hyperlight_common/clippy.toml b/src/hyperlight_common/clippy.toml new file mode 100644 index 000000000..05fdbf5a2 --- /dev/null +++ b/src/hyperlight_common/clippy.toml @@ -0,0 +1,5 @@ +disallowed-macros = [ + { path = "std::assert", reason = "no asserts in release builds" }, + { path = "std::assert_eq", reason = "no asserts in release builds" }, + { path = "std::assert_ne", reason = "no asserts in release builds" }, +] diff --git a/src/hyperlight_common/src/lib.rs b/src/hyperlight_common/src/lib.rs index eb4be220c..e6773714b 100644 --- a/src/hyperlight_common/src/lib.rs +++ b/src/hyperlight_common/src/lib.rs @@ -17,6 +17,16 @@ limitations under the License. #![cfg_attr(not(any(test, debug_assertions)), warn(clippy::panic))] #![cfg_attr(not(any(test, debug_assertions)), warn(clippy::expect_used))] #![cfg_attr(not(any(test, debug_assertions)), warn(clippy::unwrap_used))] +// clippy.toml disallows assert!/assert_eq!/assert_ne! via disallowed-macros. +// That lint is active by default, so we suppress it globally here, then +// selectively re-enable it for release host builds (feature = "std"). +// Guest targets (no std) are allowed asserts — panics are contained in the +// micro-VM and cannot crash the host. Tests and debug builds are also allowed. +#![allow(clippy::disallowed_macros)] +#![cfg_attr( + not(any(test, debug_assertions, not(feature = "std"))), + warn(clippy::disallowed_macros) +)] // We use Arbitrary during fuzzing, which requires std #![cfg_attr(not(feature = "fuzzing"), no_std)] diff --git a/src/hyperlight_common/src/version_note.rs b/src/hyperlight_common/src/version_note.rs index 643dbd8ef..91a33a863 100644 --- a/src/hyperlight_common/src/version_note.rs +++ b/src/hyperlight_common/src/version_note.rs @@ -90,6 +90,7 @@ impl ElfNote { /// /// Panics at compile time if `NAME_SZ` or `DESC_SZ` don't match /// `padded_name_size(name.len() + 1)` or `padded_desc_size(desc.len() + 1)`. + #[allow(clippy::disallowed_macros)] // These asserts are evaluated at compile time only (const fn). pub const fn new(name: &str, desc: &str, n_type: u32) -> Self { // NAME_SZ and DESC_SZ must match the padded sizes. assert!(