From 154a2231b2f00a63ed178d264e7987e0f11093a5 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Tue, 24 Jun 2025 13:34:11 +0200 Subject: [PATCH] return FrameKind in FramStack::current_frame by value --- crates/wasmparser/src/binary_reader.rs | 14 +++++++------- crates/wasmparser/src/readers/core/operators.rs | 16 ++++++++-------- crates/wasmparser/src/validator/core.rs | 4 ++-- crates/wasmparser/src/validator/operators.rs | 4 ++-- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/crates/wasmparser/src/binary_reader.rs b/crates/wasmparser/src/binary_reader.rs index 8754a604d0..df1c0f6a12 100644 --- a/crates/wasmparser/src/binary_reader.rs +++ b/crates/wasmparser/src/binary_reader.rs @@ -882,7 +882,7 @@ impl<'a> BinaryReader<'a> { } #[inline] - fn expect_frame(&mut self, stack: &impl FrameStack, k: &FrameKind, found: &str) -> Result<()> { + fn expect_frame(&mut self, stack: &impl FrameStack, k: FrameKind, found: &str) -> Result<()> { if stack.current_frame() == Some(k) { return Ok(()); } @@ -918,7 +918,7 @@ impl<'a> BinaryReader<'a> { 0x03 => visitor.visit_loop(self.read_block_type()?), 0x04 => visitor.visit_if(self.read_block_type()?), 0x05 => { - self.expect_frame(visitor, &FrameKind::If, "else")?; + self.expect_frame(visitor, FrameKind::If, "else")?; visitor.visit_else() } 0x06 => { @@ -937,9 +937,9 @@ impl<'a> BinaryReader<'a> { "legacy_exceptions feature required for catch instruction" ); } - match self.expect_frame(visitor, &FrameKind::LegacyCatch, "catch") { + match self.expect_frame(visitor, FrameKind::LegacyCatch, "catch") { Ok(()) => (), - Err(_) => self.expect_frame(visitor, &FrameKind::LegacyTry, "catch")?, + Err(_) => self.expect_frame(visitor, FrameKind::LegacyTry, "catch")?, } visitor.visit_catch(self.read_var_u32()?) } @@ -962,7 +962,7 @@ impl<'a> BinaryReader<'a> { 0x14 => visitor.visit_call_ref(self.read()?), 0x15 => visitor.visit_return_call_ref(self.read()?), 0x18 => { - self.expect_frame(visitor, &FrameKind::LegacyTry, "delegate")?; + self.expect_frame(visitor, FrameKind::LegacyTry, "delegate")?; visitor.visit_delegate(self.read_var_u32()?) } 0x19 => { @@ -972,9 +972,9 @@ impl<'a> BinaryReader<'a> { "legacy_exceptions feature required for catch_all instruction" ); } - match self.expect_frame(visitor, &FrameKind::LegacyCatch, "catch_all") { + match self.expect_frame(visitor, FrameKind::LegacyCatch, "catch_all") { Ok(()) => (), - Err(_) => self.expect_frame(visitor, &FrameKind::LegacyTry, "catch_all")?, + Err(_) => self.expect_frame(visitor, FrameKind::LegacyTry, "catch_all")?, } visitor.visit_catch_all() } diff --git a/crates/wasmparser/src/readers/core/operators.rs b/crates/wasmparser/src/readers/core/operators.rs index 176db94f6b..0169cc794d 100644 --- a/crates/wasmparser/src/readers/core/operators.rs +++ b/crates/wasmparser/src/readers/core/operators.rs @@ -338,7 +338,7 @@ crate::for_each_operator!(define_operator); /// requirements of the binary format. pub trait FrameStack { /// The current frame kind. - fn current_frame(&self) -> Option<&FrameKind>; + fn current_frame(&self) -> Option; } /// Adapters from VisitOperators to FrameStacks @@ -348,8 +348,8 @@ struct FrameStackAdapter<'a, T> { } impl FrameStack for FrameStackAdapter<'_, T> { - fn current_frame(&self) -> Option<&FrameKind> { - self.stack.last() + fn current_frame(&self) -> Option { + self.stack.last().copied() } } @@ -359,8 +359,8 @@ struct SingleFrameAdapter<'a, T> { } impl FrameStack for SingleFrameAdapter<'_, T> { - fn current_frame(&self) -> Option<&FrameKind> { - Some(&self.current_frame) + fn current_frame(&self) -> Option { + Some(self.current_frame) } } @@ -547,8 +547,8 @@ impl<'a> OperatorsReader<'a> { } impl<'a> FrameStack for OperatorsReader<'a> { - fn current_frame(&self) -> Option<&FrameKind> { - self.stack.last() + fn current_frame(&self) -> Option { + self.stack.last().copied() } } @@ -1051,7 +1051,7 @@ impl<'a> BinaryReader<'a> { /// the `Operator`, or if the input is malformed. pub fn peek_operator(&self, stack: &T) -> Result> { self.clone().visit_operator(&mut SingleFrameAdapter { - current_frame: *stack.current_frame().ok_or_else(|| { + current_frame: stack.current_frame().ok_or_else(|| { format_err!( self.original_position(), "operators remaining after end of function body or expression" diff --git a/crates/wasmparser/src/validator/core.rs b/crates/wasmparser/src/validator/core.rs index 34e3ab78ed..ab38a0daf4 100644 --- a/crates/wasmparser/src/validator/core.rs +++ b/crates/wasmparser/src/validator/core.rs @@ -468,8 +468,8 @@ impl ModuleState { } impl<'a> FrameStack for VisitConstOperator<'a> { - fn current_frame(&self) -> Option<&FrameKind> { - Some(&self.ops.get_frame(0)?.kind) + fn current_frame(&self) -> Option { + Some(self.ops.get_frame(0)?.kind) } } } diff --git a/crates/wasmparser/src/validator/operators.rs b/crates/wasmparser/src/validator/operators.rs index 5f23d6ede3..65cb9dfa2e 100644 --- a/crates/wasmparser/src/validator/operators.rs +++ b/crates/wasmparser/src/validator/operators.rs @@ -4380,7 +4380,7 @@ impl FrameStack for WasmProposalValidator<'_, '_, R> where R: WasmModuleResources, { - fn current_frame(&self) -> Option<&FrameKind> { - Some(&self.0.control.last()?.kind) + fn current_frame(&self) -> Option { + Some(self.0.control.last()?.kind) } }