You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In code like this there’s some algorithm in place which makes the capture of variable x by-value rather than the default by-ref:
fnmain(){let x = Some(vec![0]);(||{drop(x);// takes `x` by-value, therefore closure captures `x` by-value as well.})()}
However, x will not be captured by-value when the x is matched on in a moving manner:
fnmain(){let x = Some(vec![0]);(|| {match x {// cannot move out of captured outer variable in an `Fn` closure [E0507]Some(x) => {},// attempting to move value to hereNone => {}}})()}
It would be nice if the algorithm handled more cases (including one presented here).
The text was updated successfully, but these errors were encountered:
fnmain(){let x = (vec![0],);(|| {drop(x);// takes `x` by-value, therefore closure captures `x` by-value as well.})()}
fnmain(){let x = (vec![0],);(|| {drop(x.0);// cannot move out of captured outer variable in an `Fn` closure [E0507]})()}
Basically, as far as I can tell, the capture inference doesn't see drop(x.0) as a by-value use of x and so captures x by-ref. I think this is the same problem in @nagisa's examples, where matching x and extracting the contents in the Some case is also like accessing a subfield. (It's like (x as Some).0 in MIR-like syntax.)
In code like this there’s some algorithm in place which makes the capture of variable
x
by-value rather than the default by-ref:However,
x
will not be captured by-value when thex
is matched on in a moving manner:It would be nice if the algorithm handled more cases (including one presented here).
The text was updated successfully, but these errors were encountered: