Skip to content
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

Suggest cloning Arc moved into closure #124595

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on May 1, 2024

  1. Suggest cloning Arc moved into closure

    ```
    error[E0382]: borrow of moved value: `x`
      --> $DIR/moves-based-on-type-capture-clause-bad.rs:9:20
       |
    LL |     let x = "Hello world!".to_string();
       |         - move occurs because `x` has type `String`, which does not implement the `Copy` trait
    LL |     thread::spawn(move || {
       |                   ------- value moved into closure here
    LL |         println!("{}", x);
       |                        - variable moved due to use in closure
    LL |     });
    LL |     println!("{}", x);
       |                    ^ value borrowed here after move
       |
       = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
    help: clone the value before moving it into the closure
       |
    LL ~     let value = x.clone();
    LL ~     thread::spawn(move || {
    LL ~         println!("{}", value);
       |
    ```
    
    Fix rust-lang#104232.
    estebank committed May 1, 2024
    Configuration menu
    Copy the full SHA
    d695130 View commit details
    Browse the repository at this point in the history