1 // Test evaluation order of assignment expressions is right to left.
5 // We would previously not finish evaluating borrow and FRU expressions before
10 fn evaluate_reborrow_before_assign() {
14 // There's an implicit reborrow of `x` on the right-hand side of the
15 // assignment. Note that writing an explicit reborrow would not show this
16 // bug, as now there would be two reborrows on the right-hand side and at
17 // least one of them would happen before the left-hand side is evaluated.
18 *{ x = z; &mut *y }
= x
;
20 assert_eq
!(**y
, 1); // y should be assigned the original value of `x`.
23 fn evaluate_mut_reborrow_before_assign() {
27 *{ x = z; &mut *y }
= x
;
29 assert_eq
!(**y
, 1); // y should be assigned the original value of `x`.
32 // We should evaluate `x[2]` and borrow the value out *before* evaluating the
33 // LHS and changing its value.
34 fn evaluate_ref_to_temp_before_assign_slice() {
35 let mut x
= &[S(0), S(1), S(2)][..];
37 *{ x = &[S(3), S(4), S(5)]; &mut *y }
= &x
[2];
39 assert_eq
!(5, x
[2].0);
42 // We should evaluate `x[2]` and copy the value out *before* evaluating the LHS
43 // and changing its value.
44 fn evaluate_fru_to_temp_before_assign_slice() {
45 let mut x
= &[S(0), S(1), S(2)][..];
47 *{ x = &[S(3), S(4), S(5)]; &mut *y }
= S { ..x[2] }
;
49 assert_eq
!(5, x
[2].0);
52 // We should evaluate `*x` and copy the value out *before* evaluating the LHS
54 fn evaluate_fru_to_temp_before_assign_box() {
55 let x
= Box
::new(S(0));
57 *{ drop(x); &mut *y }
= S { ..*x }
;
62 evaluate_reborrow_before_assign();
63 evaluate_mut_reborrow_before_assign();
64 evaluate_ref_to_temp_before_assign_slice();
65 evaluate_fru_to_temp_before_assign_slice();
66 evaluate_fru_to_temp_before_assign_box();