Skip to content

Unexpected evaluation order of assignments #65910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
matthewjasper opened this issue Oct 28, 2019 · 0 comments · Fixed by #65608
Closed

Unexpected evaluation order of assignments #65910

matthewjasper opened this issue Oct 28, 2019 · 0 comments · Fixed by #65608
Assignees
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthewjasper
Copy link
Contributor

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();
}
@matthewjasper matthewjasper added the A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html label Oct 28, 2019
@matthewjasper matthewjasper self-assigned this Oct 28, 2019
@jonas-schievink jonas-schievink added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 28, 2019
@bors bors closed this as completed in 4f03f4a Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants