Skip to content

bug in suggestion with reborrowing of mutable value reference #101119

Closed
@proohit

Description

@proohit

I tried this code:

#[cfg(feature = "crossbeam-utils")]
fn fill_memory_blocks_mt(context: &Context, memory: &mut Memory, state: &mut Argon2Result) {
    for p in 0..context.config.time_cost {
        for s in 0..common::SYNC_POINTS {
            let _ = scope(|scoped| {
                for (l, mem) in (0..context.config.lanes).zip(memory.as_lanes_mut()) {
                    let position = Position {
                        pass: p,
                        lane: l,
                        slice: s,
                        index: 0,
                    };
                    scoped.spawn(move |_| {
                        fill_segment(context, &position, mem, state);
                    });
                }
            });
        }
    }
}

I expected to see this happen: Some suggestion that may be a solution (which even I don't know yet) or no suggestion at all

Instead, this happened: The following message, including a suggestion which doesn't help

error[E0382]: use of moved value: `state`
   --> src/core.rs:223:34
    |
223 |                     scoped.spawn(move |_| {
    |                                  ^^^^^^^^ value moved into closure here, in previous iteration of loop
224 |                         fill_segment(context, &position, mem, state);
    |                                                               ----- use occurs due to use in closure
    |
    = note: move occurs because `state` has type `&mut Argon2Result`, which does not implement the `Copy` trait
help: consider creating a fresh reborrow of `state` here
    |
223 |                     scoped.spawn(&mut *move |_| {
    |                                  ++++++

error[E0382]: use of moved value: `state`
   --> src/core.rs:215:27
    |
212 | fn fill_memory_blocks_mt(context: &Context, memory: &mut Memory, state: &mut Argon2Result) {
    |                                                                  ----- move occurs because `state` has type `&mut Argon2Result`, which does not implement the `Copy` trait
...
215 |             let _ = scope(|scoped| {
    |                           ^^^^^^^^ value moved into closure here, in previous iteration of loop
...
224 |                         fill_segment(context, &position, mem, state);
    |                                                               ----- use occurs due to use in closure
    |
help: consider creating a fresh reborrow of `state` here
    |
215 |             let _ = scope(&mut *|scoped| {
    |                           ++++++

For more information about this error, try `rustc --explain E0382`.
error: could not compile `rust-argon2-wasm` due to 2 previous errors

Meta

rustc --version --verbose:

rustc 1.61.0 (fe5b13d68 2022-05-18)
binary: rustc
commit-hash: fe5b13d681f25ee6474be29d748c65adcd91f69e
commit-date: 2022-05-18
host: x86_64-unknown-linux-gnu
release: 1.61.0
LLVM version: 14.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions