diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 95dd8dd48a0..07d6ce20821 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -347,6 +347,13 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx match stmt.kind { StatementKind::Assign(ref lhs, ref rhs) => { + self.consume_rvalue( + ContextKind::AssignRhs.new(location), + (rhs, span), + location, + flow_state, + ); + self.mutate_place( ContextKind::AssignLhs.new(location), (lhs, span), @@ -354,13 +361,6 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx JustWrite, flow_state, ); - - self.consume_rvalue( - ContextKind::AssignRhs.new(location), - (rhs, span), - location, - flow_state, - ); } StatementKind::SetDiscriminant { ref place, diff --git a/src/test/compile-fail/nll/reference-carried-through-struct-field.rs b/src/test/compile-fail/nll/reference-carried-through-struct-field.rs index e64fecbe701..efa6cc273b6 100644 --- a/src/test/compile-fail/nll/reference-carried-through-struct-field.rs +++ b/src/test/compile-fail/nll/reference-carried-through-struct-field.rs @@ -19,7 +19,7 @@ fn foo() { let mut x = 22; let wrapper = Wrap { w: &mut x }; x += 1; //[ast]~ ERROR cannot assign to `x` because it is borrowed [E0506] - //[mir]~^ ERROR cannot assign to `x` because it is borrowed [E0506] + //[mir]~^ ERROR cannot use `x` because it was mutably borrowed [E0503] *wrapper.w += 1; } diff --git a/src/test/ui/issue-45697.rs b/src/test/ui/issue-45697.rs index 7f44209d717..b69ba97cc9b 100644 --- a/src/test/ui/issue-45697.rs +++ b/src/test/ui/issue-45697.rs @@ -29,7 +29,7 @@ fn main() { let z = copy_borrowed_ptr(&mut y); *y.pointer += 1; //~^ ERROR cannot assign to `*y.pointer` because it is borrowed (Ast) [E0506] - //~| ERROR cannot assign to `*y.pointer` because it is borrowed (Mir) [E0506] + //~| ERROR cannot use `*y.pointer` because it was mutably borrowed (Mir) [E0503] *z.pointer += 1; } } diff --git a/src/test/ui/issue-45697.stderr b/src/test/ui/issue-45697.stderr index 007bfbfc9b0..e9b723d57b5 100644 --- a/src/test/ui/issue-45697.stderr +++ b/src/test/ui/issue-45697.stderr @@ -6,13 +6,13 @@ error[E0506]: cannot assign to `*y.pointer` because it is borrowed (Ast) 30 | *y.pointer += 1; | ^^^^^^^^^^^^^^^ assignment to borrowed `*y.pointer` occurs here -error[E0506]: cannot assign to `*y.pointer` because it is borrowed (Mir) +error[E0503]: cannot use `*y.pointer` because it was mutably borrowed (Mir) --> $DIR/issue-45697.rs:30:9 | 29 | let z = copy_borrowed_ptr(&mut y); - | ------ borrow of `*y.pointer` occurs here + | ------ borrow of `y` occurs here 30 | *y.pointer += 1; - | ^^^^^^^^^^^^^^^ assignment to borrowed `*y.pointer` occurs here + | ^^^^^^^^^^^^^^^ use of borrowed `y` error: aborting due to 2 previous errors