Skip to content

Commit

Permalink
cranelift: fix build warning
Browse files Browse the repository at this point in the history
In bytecodealliance#4375 we introduced a code pattern that appears as a warning when
building the `cranelift-interpreter` crate:

```
warning: cannot borrow `*state` as mutable because it is also borrowed as immutable
   --> cranelift/interpreter/src/step.rs:412:13
    |
47  |     let arg = |index: usize| -> Result<V, StepError> {
    |               -------------------------------------- immutable borrow occurs here
48  |         let value_ref = inst_context.args()[index];
49  |         state
    |         ----- first borrow occurs due to use of `*state` in closure
...
412 |             state.set_pinned_reg(arg(0)?);
    |             ^^^^^^^^^^^^^^^^^^^^^---^^^^^
    |             |                    |
    |             |                    immutable borrow later used here
    |             mutable borrow occurs here
    |
    = note: `#[warn(mutable_borrow_reservation_conflict)]` on by default
    = warning: this borrowing pattern was not meant to be accepted, and may become a hard error in the future
    = note: for more information, see issue #59159 <rust-lang/rust#59159>
```

This change fixes the warning.
  • Loading branch information
abrown committed Aug 11, 2022
1 parent 3ea1813 commit 904ef98
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cranelift/interpreter/src/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@ where
}
Opcode::GetPinnedReg => assign(state.get_pinned_reg()),
Opcode::SetPinnedReg => {
state.set_pinned_reg(arg(0)?);
let arg0 = arg(0)?;
state.set_pinned_reg(arg0);
ControlFlow::Continue
}
Opcode::TableAddr => {
Expand Down

0 comments on commit 904ef98

Please sign in to comment.