E0507’s explanation does mention closure bodies, but there’s definitely room for improvement. The error message itself is pretty fine IMO. I don’t think that it’s necessarily the job of the error message to explain why one “cannot move out of a captured variable in an
Fn closure”. That’s just a fact, the error code explanation should handle the rest. A separate error code for moving out of captured variables in non-
FnOnce closures could help.
Well, actually ... the error message itself could be rephrased to be more clear about that it’s a fact that “it’s impossible to move out of a captured variable in an
Fn closure”. I don’t know, maybe:
cannot move out of `clone` because it’s a captured variable in an `Fn` closure.
Next to the options listed in the explanation
- Try to avoid moving the variable. not possible when calling
- Somehow reclaim the ownership. e.g. with the extra
- Implement the
Copy trait on the type. impossible for
there’s also the option of downgrading from
FnOnce, in case you don’t actually need an
Fn when calling