Skip to content

Commit 35b9bd0

Browse files
committed
Fixed refs being marked used mutably on mut deref
Boxes are the exception - since a Box is as mutable as its contents.
1 parent e772c28 commit 35b9bd0

File tree

1 file changed

+13
-0
lines changed
  • src/librustc_borrowck/borrowck/gather_loans

1 file changed

+13
-0
lines changed

src/librustc_borrowck/borrowck/gather_loans/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,19 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
441441
LpUpvar(ty::UpvarId{ var_id: local_id, closure_expr_id: _ }) => {
442442
self.tcx().used_mut_nodes.borrow_mut().insert(local_id);
443443
}
444+
LpExtend(ref base, mc::McInherited, LpDeref(pointer_kind)) |
445+
LpExtend(ref base, mc::McDeclared, LpDeref(pointer_kind)) => {
446+
match base.kind {
447+
LpVar(_) if pointer_kind != mc::Unique => {
448+
// If you mutate the inside of a ref var, the var itself
449+
// is not used mutably [Issue #25049]
450+
// Unless it's a Box! (mc::Unique)
451+
}
452+
_ => {
453+
self.mark_loan_path_as_mutated(&base);
454+
}
455+
}
456+
}
444457
LpDowncast(ref base, _) |
445458
LpExtend(ref base, mc::McInherited, _) |
446459
LpExtend(ref base, mc::McDeclared, _) => {

0 commit comments

Comments
 (0)