Skip to content

Commit 108fd89

Browse files
authored
feat(clippy): add disallowed macros for asserts in clippy.toml and suppress globally (#1376)
Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
1 parent d9a280f commit 108fd89

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/hyperlight_common/clippy.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
disallowed-macros = [
2+
{ path = "std::assert", reason = "no asserts in release builds" },
3+
{ path = "std::assert_eq", reason = "no asserts in release builds" },
4+
{ path = "std::assert_ne", reason = "no asserts in release builds" },
5+
]

src/hyperlight_common/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ limitations under the License.
1717
#![cfg_attr(not(any(test, debug_assertions)), warn(clippy::panic))]
1818
#![cfg_attr(not(any(test, debug_assertions)), warn(clippy::expect_used))]
1919
#![cfg_attr(not(any(test, debug_assertions)), warn(clippy::unwrap_used))]
20+
// clippy.toml disallows assert!/assert_eq!/assert_ne! via disallowed-macros.
21+
// That lint is active by default, so we suppress it globally here, then
22+
// selectively re-enable it for release host builds (feature = "std").
23+
// Guest targets (no std) are allowed asserts — panics are contained in the
24+
// micro-VM and cannot crash the host. Tests and debug builds are also allowed.
25+
#![allow(clippy::disallowed_macros)]
26+
#![cfg_attr(
27+
not(any(test, debug_assertions, not(feature = "std"))),
28+
warn(clippy::disallowed_macros)
29+
)]
2030
// We use Arbitrary during fuzzing, which requires std
2131
#![cfg_attr(not(feature = "fuzzing"), no_std)]
2232

src/hyperlight_common/src/version_note.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ impl<const NAME_SZ: usize, const DESC_SZ: usize> ElfNote<NAME_SZ, DESC_SZ> {
9090
///
9191
/// Panics at compile time if `NAME_SZ` or `DESC_SZ` don't match
9292
/// `padded_name_size(name.len() + 1)` or `padded_desc_size(desc.len() + 1)`.
93+
#[allow(clippy::disallowed_macros)] // These asserts are evaluated at compile time only (const fn).
9394
pub const fn new(name: &str, desc: &str, n_type: u32) -> Self {
9495
// NAME_SZ and DESC_SZ must match the padded sizes.
9596
assert!(

0 commit comments

Comments
 (0)