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

Uninformative "cannot move out of captured variable" error #37150

Closed
alexcrichton opened this issue Oct 13, 2016 · 2 comments
Closed

Uninformative "cannot move out of captured variable" error #37150

alexcrichton opened this issue Oct 13, 2016 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@alexcrichton
Copy link
Member

For this code:

#![feature(conservative_impl_trait)]
use std::rc::Rc;

fn bar<R, F: FnMut() -> R>(_: F) -> R {
    loop {}
}

fn foo() -> impl FnOnce() {
    let a = Rc::new(());
    bar(move || {
        let _b = a.clone();
        move || {
            a.clone();
        }
    })
}

it yields the error:

error[E0507]: cannot move out of captured outer variable in an `FnMut` closure
  --> foo.rs:12:9
   |
12 |         move || {
   |         ^^^^^^^ cannot move out of captured outer variable in an `FnMut` closure

error: aborting due to previous error

I recently found this error when I misspelled a captured variable as connnections (should be connections) and it'd be mega-helpful if the error message could mention which captured variable cannot be moved out of. (a span pointing at the variable would also work).

cc @jonathandturner

@alexcrichton alexcrichton added the A-diagnostics Area: Messages for errors, warnings, and lints label Oct 13, 2016
@insaneinside
Copy link
Contributor

This is a duplicate of #31752.

@steveklabnik
Copy link
Member

Looks like it, closing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

3 participants