Rust Reference says:
The left operand of an assignment expression or compound assignment is an lvalue context, as is the only unary borrow operand.
[...]
When the rvalue value is used in the context of an lvalue, a temporary unnamed lvalue is created and used.
This rvalue promotion obviously works with borrowing:
let ref_to_i32 = &27;
But it does not work in the task (although the link talks about all lvalue contexts, not just borrowing):
27 = 28; // error[E0070]: invalid left-hand side expression
error description E0070 does not mention this rvalue advertisement. Is this a mistake in the link, or is there really some way to initiate the rvalue promotion using assignment expressions or compound assignments?
There is a third type of lvalue context that also incorrectly describes the link. Whenever there is a template with ref , binding the left value to this template represents the lvalue context. It turns out that promotion works in this case:
let ref x = 3;
So, apparently, promotion just doesn't work for (composite) appointments?
source share