[rust-dev] RFC: Future-proof for unboxed closures
niko at alum.mit.edu
Tue Jan 28 05:45:30 PST 2014
On Mon, Jan 27, 2014 at 08:33:57PM +0100, Gábor Lehel wrote:
> I think this question has a more general form, namely: when should I pass
> by value and when using &move/&my? I expect this will come up quite a bit
> if we add the latter.
Yes, I agree. The main reason to use `&move/&my` is to permit moves of
dynamically sized types. In the case of once closures, that is a trait
type. Given that, I have wondered if we can do without it, and instead
say that (e.g.) passing a DST as a by value argument is legal. Without
a region, though, we'd need some other rules to prevent that DST from
leaking. For example, you can pass a DST as an input parameter, but
you cannot have a local variable, field, or return type of DST type.
The last time I thought this through, those rules (or something like
them) seemed onerous, but now they seem quite reasonable to me. (More
or less the same as our old reference mode parameters.) They support
the important use case of passing in a (unboxed) `OnceFn` object and
permitting it to be called.
More information about the Rust-dev