diff --git a/crates/wasmparser/src/validator/component_types.rs b/crates/wasmparser/src/validator/component_types.rs index 894b86e8de..ca42e6be15 100644 --- a/crates/wasmparser/src/validator/component_types.rs +++ b/crates/wasmparser/src/validator/component_types.rs @@ -476,9 +476,10 @@ pub struct ComponentDefinedTypeId { alias_id: u32, } -const _: () = { +#[test] +fn assert_defined_type_small() { assert!(core::mem::size_of::() <= 8); -}; +} impl TypeIdentifier for ComponentDefinedTypeId { type Data = ComponentDefinedType; diff --git a/crates/wasmparser/src/validator/operators.rs b/crates/wasmparser/src/validator/operators.rs index 59dd403f1b..758447f3de 100644 --- a/crates/wasmparser/src/validator/operators.rs +++ b/crates/wasmparser/src/validator/operators.rs @@ -252,9 +252,10 @@ enum MaybeType { // The validator is pretty performance-sensitive and `MaybeType` is the main // unit of storage, so assert that it doesn't exceed 4 bytes which is the // current expected size. -const _: () = { +#[test] +fn assert_maybe_type_small() { assert!(core::mem::size_of::() == 4); -}; +} impl core::fmt::Display for MaybeType { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { diff --git a/crates/wasmparser/src/validator/types.rs b/crates/wasmparser/src/validator/types.rs index ad88f09f1f..e999a170df 100644 --- a/crates/wasmparser/src/validator/types.rs +++ b/crates/wasmparser/src/validator/types.rs @@ -89,6 +89,7 @@ macro_rules! define_type_id { } } + // The size of type IDs was seen to have a large-ish impact in #844, so // this assert ensures that it stays relatively small. const _: () = { @@ -106,9 +107,10 @@ pub struct CoreTypeId { index: u32, } -const _: () = { +#[test] +fn assert_core_type_id_small() { assert!(core::mem::size_of::() <= 4); -}; +} impl TypeIdentifier for CoreTypeId { type Data = SubType; diff --git a/crates/wast/src/core/expr.rs b/crates/wast/src/core/expr.rs index 228f46b914..9fb25ffe52 100644 --- a/crates/wast/src/core/expr.rs +++ b/crates/wast/src/core/expr.rs @@ -1208,11 +1208,12 @@ instructions! { // since big `*.wat` files will have a lot of these. This is a small ratchet to // make sure that this enum doesn't become larger than it already is, although // ideally it also wouldn't be as large as it is now. -const _: () = { +#[test] +fn assert_instruction_not_too_large() { let size = std::mem::size_of::>(); let pointer = std::mem::size_of::(); assert!(size <= pointer * 11); -}; +} impl<'a> Instruction<'a> { pub(crate) fn needs_data_count(&self) -> bool {