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
Wrong error: cannot move out of captured outer variable in an FnMut
closure
#47850
Comments
It works if you change the FnMut to FnOnce. |
But why can't it also work with FnMut? (Btw, the error should say it has to be FnOnce then.) |
@Boscop because you can only move things one time -- an
I don't entirely agree, but I also don't disagree. This kind of error is often hard to decide how to diagnose. There is a kind of tension here: the closure wants to take an action (a move), but the signature of Interestingly, if the closure is not given directly as an argument to
This is because of the tracking that @estebank (I think? or was it someone else...) put in to track why we decide a closure's "defining trait". Right now, that checking is not coming into play because we are deciding that the closure should be That happens in this code: rust/src/librustc_typeck/check/closure.rs Lines 151 to 155 in 70f7d58
When we go down that path, we never wind up storing the "origin" of the kind. In contrast, the upvar inference that would otherwise kick in does this: rust/src/librustc_typeck/check/upvar.rs Lines 182 to 188 in 70f7d58
So we probably need to be storing some kind of information in
|
Current output:
|
I came across this issue again.. foo.bar.f(|| {
let a = &mut *a;
let b = &mut *b;
*if true {a} else {b} = 42;
}); |
https://play.rust-lang.org/?gist=4ce6948a92c2fcb281b3cade8574691d&version=nightly
But the second case should work too!
The text was updated successfully, but these errors were encountered: