diff --git a/crates/wasmtime/src/runtime/vm/gc/enabled/drc.rs b/crates/wasmtime/src/runtime/vm/gc/enabled/drc.rs index 2d391774133d..38057577f108 100644 --- a/crates/wasmtime/src/runtime/vm/gc/enabled/drc.rs +++ b/crates/wasmtime/src/runtime/vm/gc/enabled/drc.rs @@ -54,7 +54,7 @@ use crate::runtime::vm::{ VMGcObjectData, VMGcRef, }; use crate::vm::VMMemoryDefinition; -use crate::{Engine, bail_bug, prelude::*}; +use crate::{Engine, Trap, bail_bug, prelude::*}; use core::sync::atomic::AtomicUsize; use core::{ alloc::Layout, @@ -1070,8 +1070,7 @@ unsafe impl GcHeap for DrcHeap { } let object_size = u32::try_from(layout.size()).unwrap(); - let alloc_size = FreeList::aligned_size(object_size) - .ok_or_else(|| format_err!("allocation size too large"))?; + let alloc_size = FreeList::aligned_size(object_size).ok_or(Trap::AllocationTooLarge)?; let gc_ref = match self.free_list.as_mut().unwrap().alloc_fast(alloc_size) { None => return Ok(Err(u64::try_from(layout.size())?)), @@ -1136,9 +1135,7 @@ unsafe impl GcHeap for DrcHeap { length: u32, layout: &GcArrayLayout, ) -> Result> { - let layout = layout - .layout(length) - .ok_or_else(|| format_err!("allocation size too large"))?; + let layout = layout.layout(length).ok_or(Trap::AllocationTooLarge)?; let gc_ref = match self.alloc_raw( VMGcHeader::from_kind_and_index(VMGcKind::ArrayRef, ty), layout, diff --git a/crates/wasmtime/src/runtime/vm/gc/enabled/null.rs b/crates/wasmtime/src/runtime/vm/gc/enabled/null.rs index 8d310307511d..9ab201e61b72 100644 --- a/crates/wasmtime/src/runtime/vm/gc/enabled/null.rs +++ b/crates/wasmtime/src/runtime/vm/gc/enabled/null.rs @@ -6,7 +6,7 @@ use super::*; use crate::{ - Engine, + Engine, Trap, prelude::*, vm::{ ExternRefHostDataId, ExternRefHostDataTable, GarbageCollection, GcHeap, GcHeapObject, @@ -311,9 +311,7 @@ unsafe impl GcHeap for NullHeap { length: u32, layout: &GcArrayLayout, ) -> Result> { - let layout = layout - .layout(length) - .ok_or_else(|| format_err!("allocation size too large"))?; + let layout = layout.layout(length).ok_or(Trap::AllocationTooLarge)?; let gc_ref = match self.alloc( VMGcHeader::from_kind_and_index(VMGcKind::ArrayRef, ty), layout,