Skip to content

Commit f88440c

Browse files
authored
return FrameKind in FramStack::current_frame by value (#2248)
1 parent d953307 commit f88440c

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

crates/wasmparser/src/binary_reader.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ impl<'a> BinaryReader<'a> {
882882
}
883883

884884
#[inline]
885-
fn expect_frame(&mut self, stack: &impl FrameStack, k: &FrameKind, found: &str) -> Result<()> {
885+
fn expect_frame(&mut self, stack: &impl FrameStack, k: FrameKind, found: &str) -> Result<()> {
886886
if stack.current_frame() == Some(k) {
887887
return Ok(());
888888
}
@@ -918,7 +918,7 @@ impl<'a> BinaryReader<'a> {
918918
0x03 => visitor.visit_loop(self.read_block_type()?),
919919
0x04 => visitor.visit_if(self.read_block_type()?),
920920
0x05 => {
921-
self.expect_frame(visitor, &FrameKind::If, "else")?;
921+
self.expect_frame(visitor, FrameKind::If, "else")?;
922922
visitor.visit_else()
923923
}
924924
0x06 => {
@@ -937,9 +937,9 @@ impl<'a> BinaryReader<'a> {
937937
"legacy_exceptions feature required for catch instruction"
938938
);
939939
}
940-
match self.expect_frame(visitor, &FrameKind::LegacyCatch, "catch") {
940+
match self.expect_frame(visitor, FrameKind::LegacyCatch, "catch") {
941941
Ok(()) => (),
942-
Err(_) => self.expect_frame(visitor, &FrameKind::LegacyTry, "catch")?,
942+
Err(_) => self.expect_frame(visitor, FrameKind::LegacyTry, "catch")?,
943943
}
944944
visitor.visit_catch(self.read_var_u32()?)
945945
}
@@ -962,7 +962,7 @@ impl<'a> BinaryReader<'a> {
962962
0x14 => visitor.visit_call_ref(self.read()?),
963963
0x15 => visitor.visit_return_call_ref(self.read()?),
964964
0x18 => {
965-
self.expect_frame(visitor, &FrameKind::LegacyTry, "delegate")?;
965+
self.expect_frame(visitor, FrameKind::LegacyTry, "delegate")?;
966966
visitor.visit_delegate(self.read_var_u32()?)
967967
}
968968
0x19 => {
@@ -972,9 +972,9 @@ impl<'a> BinaryReader<'a> {
972972
"legacy_exceptions feature required for catch_all instruction"
973973
);
974974
}
975-
match self.expect_frame(visitor, &FrameKind::LegacyCatch, "catch_all") {
975+
match self.expect_frame(visitor, FrameKind::LegacyCatch, "catch_all") {
976976
Ok(()) => (),
977-
Err(_) => self.expect_frame(visitor, &FrameKind::LegacyTry, "catch_all")?,
977+
Err(_) => self.expect_frame(visitor, FrameKind::LegacyTry, "catch_all")?,
978978
}
979979
visitor.visit_catch_all()
980980
}

crates/wasmparser/src/readers/core/operators.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ crate::for_each_operator!(define_operator);
338338
/// requirements of the binary format.
339339
pub trait FrameStack {
340340
/// The current frame kind.
341-
fn current_frame(&self) -> Option<&FrameKind>;
341+
fn current_frame(&self) -> Option<FrameKind>;
342342
}
343343

344344
/// Adapters from VisitOperators to FrameStacks
@@ -348,8 +348,8 @@ struct FrameStackAdapter<'a, T> {
348348
}
349349

350350
impl<T> FrameStack for FrameStackAdapter<'_, T> {
351-
fn current_frame(&self) -> Option<&FrameKind> {
352-
self.stack.last()
351+
fn current_frame(&self) -> Option<FrameKind> {
352+
self.stack.last().copied()
353353
}
354354
}
355355

@@ -359,8 +359,8 @@ struct SingleFrameAdapter<'a, T> {
359359
}
360360

361361
impl<T> FrameStack for SingleFrameAdapter<'_, T> {
362-
fn current_frame(&self) -> Option<&FrameKind> {
363-
Some(&self.current_frame)
362+
fn current_frame(&self) -> Option<FrameKind> {
363+
Some(self.current_frame)
364364
}
365365
}
366366

@@ -547,8 +547,8 @@ impl<'a> OperatorsReader<'a> {
547547
}
548548

549549
impl<'a> FrameStack for OperatorsReader<'a> {
550-
fn current_frame(&self) -> Option<&FrameKind> {
551-
self.stack.last()
550+
fn current_frame(&self) -> Option<FrameKind> {
551+
self.stack.last().copied()
552552
}
553553
}
554554

@@ -1051,7 +1051,7 @@ impl<'a> BinaryReader<'a> {
10511051
/// the `Operator`, or if the input is malformed.
10521052
pub fn peek_operator<T: FrameStack>(&self, stack: &T) -> Result<Operator<'a>> {
10531053
self.clone().visit_operator(&mut SingleFrameAdapter {
1054-
current_frame: *stack.current_frame().ok_or_else(|| {
1054+
current_frame: stack.current_frame().ok_or_else(|| {
10551055
format_err!(
10561056
self.original_position(),
10571057
"operators remaining after end of function body or expression"

crates/wasmparser/src/validator/core.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,8 @@ impl ModuleState {
468468
}
469469

470470
impl<'a> FrameStack for VisitConstOperator<'a> {
471-
fn current_frame(&self) -> Option<&FrameKind> {
472-
Some(&self.ops.get_frame(0)?.kind)
471+
fn current_frame(&self) -> Option<FrameKind> {
472+
Some(self.ops.get_frame(0)?.kind)
473473
}
474474
}
475475
}

crates/wasmparser/src/validator/operators.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4380,7 +4380,7 @@ impl<R> FrameStack for WasmProposalValidator<'_, '_, R>
43804380
where
43814381
R: WasmModuleResources,
43824382
{
4383-
fn current_frame(&self) -> Option<&FrameKind> {
4384-
Some(&self.0.control.last()?.kind)
4383+
fn current_frame(&self) -> Option<FrameKind> {
4384+
Some(self.0.control.last()?.kind)
43854385
}
43864386
}

0 commit comments

Comments
 (0)