I thought the purpose was to make sure that the programmer realizes that values are being moved. The compiler always knows when it’s missing, so it could infer it, but having the programmer put it in explicitly is a way of saying “hey, are you sure you meant to move these?”. It also makes
FnOnce closures more greppable.
But then I came across this example, where
string is moved into
closure, but the
move keyword is not necessary:
let string = "string".to_string(); let closure = || drop(string); closure();
So I guess my notion that
move is there to flag
FnOnce closures and make them opt in is misguided, since they can clearly exist without it? Or maybe the situations in which it can be left out are all very trivial, like the one above, so in practice,
move still plays this role, even though in theory, it is not always obligatory?