From 35b9bd0559746196fe0bc9f39b86c47d8c3afb8c Mon Sep 17 00:00:00 2001 From: Isaac van Bakel Date: Mon, 31 Jul 2017 19:38:20 +0100 Subject: [PATCH] Fixed refs being marked used mutably on mut deref Boxes are the exception - since a Box is as mutable as its contents. --- src/librustc_borrowck/borrowck/gather_loans/mod.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/librustc_borrowck/borrowck/gather_loans/mod.rs b/src/librustc_borrowck/borrowck/gather_loans/mod.rs index 7dcb6ce76a4..ba865e12533 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/mod.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/mod.rs @@ -441,6 +441,19 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> { LpUpvar(ty::UpvarId{ var_id: local_id, closure_expr_id: _ }) => { self.tcx().used_mut_nodes.borrow_mut().insert(local_id); } + LpExtend(ref base, mc::McInherited, LpDeref(pointer_kind)) | + LpExtend(ref base, mc::McDeclared, LpDeref(pointer_kind)) => { + match base.kind { + LpVar(_) if pointer_kind != mc::Unique => { + // If you mutate the inside of a ref var, the var itself + // is not used mutably [Issue #25049] + // Unless it's a Box! (mc::Unique) + } + _ => { + self.mark_loan_path_as_mutated(&base); + } + } + } LpDowncast(ref base, _) | LpExtend(ref base, mc::McInherited, _) | LpExtend(ref base, mc::McDeclared, _) => {