I don't have a concrete example in mind.
Yeah, all initializer arguments are consuming by default, which is how the ABI is implemented today. Whether a copyable type is implicitly copied or not depends on whether it's the last use of the value; if the construction isn't the last use, and the parameter is used as part of the new constructed value, then a copy has to occur somewhere, but the consuming convention allows a copy to be avoided by forwarding when the construction is the final use of a value.
I use the explicit consume
operator in these situations primarily because noncopyable types can't be used in these situations today, but I want to establish the conventions these operations have for future reference when we do have noncopyable types available in these situations. Extending if let
, for
, and friends to work with borrows is being discussed under the proposal for borrow
and inout
bindings. As you noted, you will most likely use a different syntax form to explicitly borrow.
Primarily that forgetting to specify the convention and getting the wrong default could leave you stuck with the wrong behavior for move-only types, whereas when working with copyable types the difference is more of an optimization.
As part of the borrow
and inout
bindings, we're proposing that those bindings don't allow for implicit copying, which I think will allow you to get the effect you like by choosing those bindings over the typical var
and let
.
Maybe, though nonmovable types are pretty niche in their applications. In Rust, you usually interact with global literals through &'static
borrows. Since the values are owned by global constants, and globals can't be consumed out of because any code anywhere in the program can access them, they are effectively nonmovable.