Skip to content

bug in suggestion with reborrowing of mutable value reference #101119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
proohit opened this issue Aug 28, 2022 · 2 comments · Fixed by #101429
Closed

bug in suggestion with reborrowing of mutable value reference #101119

proohit opened this issue Aug 28, 2022 · 2 comments · Fixed by #101429
Labels
C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example

Comments

@proohit
Copy link

proohit commented Aug 28, 2022

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
@proohit proohit added the C-bug Category: This is a bug. label Aug 28, 2022
@compiler-errors
Copy link
Member

@proohit, I think I may have fixed this, but is there a way you could share a sample of code that actually is complete? I don't know all of these structs that you're using, and reverse-engineering this is proving difficult.

@compiler-errors compiler-errors added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Sep 2, 2022
@proohit
Copy link
Author

proohit commented Sep 3, 2022

@compiler-errors, I wasn't able to create a smaller example, as the error did not show up and I don't know which path exactly causes that behaviour. But I prepared an environment of the actual code in this branch (proohit/rust-argon2-wasm/rust-lang/rust/#101119-mcve), in that I tried to trim any excess code. Please see if that helps.

The affected file is src/core.rs which is called by src/argon2.rs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants