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

Capturing arguments to format! doesn't work #3

Open
Saruniks opened this issue Jul 30, 2023 · 0 comments
Open

Capturing arguments to format! doesn't work #3

Saruniks opened this issue Jul 30, 2023 · 0 comments

Comments

@Saruniks
Copy link
Owner

#[clone_on_capture(debug)]
fn test_add() {
    let a = "a".to_string();
    let closure = move || {
        format!("{a}");
    };
    format!("{a}");
}

Compile error:

error[E0382]: borrow of moved value: `a`
  --> tests/integration_tests.rs:10:14
   |
6  |     let a = "a".to_string();
   |         - move occurs because `a` has type `String`, which does not implement the `Copy` trait
7  |     let closure = move || {
   |                   ------- value moved into closure here
8  |         format!("{a}");
   |                   - variable moved due to use in closure
9  |     };
10 |     format!("{a}");
   |              ^^^ value borrowed here after move

Macro token stream:

TokenStream [
    Literal {
        kind: Str,
        symbol: "{a}",
        suffix: None,
        span: #0 bytes(171..176),
    },
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant