Closed
Description
Assignment expressions where the right-hand side is a FRU or has a reborrow adjustment are not evaluated in the strict right to left order that they usually are. The following example should compile and the assertions shouldn't be triggered
fn evaluate_reborrow_before_assign() {
let mut x = &1;
let y = &mut &2;
let z = &3;
// There's an implicit reborrow of `x` on the right-hand side of the
// assignement. Note that writing an explicit reborrow would not show this
// bug, as now there would be two reborrows on the right-hand side and at
// least one of them would happen before the left-hand side is evaluated.
*{ x = z; &mut *y } = x;
assert_eq!(*x, 3);
assert_eq!(**y, 1); // 3 on stable
}
fn evaluate_fru_to_temp_before_assign_box() {
let x = Box::new(S(0));
let y = &mut S(1);
*{ drop(x); &mut *y } = S { ..*x }; // error here on stable
assert_eq!(0, y.0);
}
fn main() {
evaluate_reborrow_before_assign();
evaluate_fru_to_temp_before_assign_box();
}