Skip to content

Commit d204cfd

Browse files
committed
Issue #5967: Make rvalues mutable
1 parent 5a2f65f commit d204cfd

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/librustc/middle/borrowck/gather_loans/lifetime.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl GuaranteeLifetimeContext {
9393
let omit_root = (
9494
ptr_mutbl == m_imm &&
9595
self.bccx.is_subregion_of(self.loan_region, base_scope) &&
96-
base.mutbl.is_immutable() &&
96+
self.is_rvalue_or_immutable(base) &&
9797
!self.is_moved(base)
9898
);
9999

@@ -168,6 +168,14 @@ impl GuaranteeLifetimeContext {
168168
}
169169
}
170170

171+
fn is_rvalue_or_immutable(&self,
172+
cmt: mc::cmt) -> bool {
173+
cmt.mutbl.is_immutable() || match cmt.guarantor().cat {
174+
mc::cat_rvalue => true,
175+
_ => false
176+
}
177+
}
178+
171179
fn check_root(&self,
172180
cmt_deref: mc::cmt,
173181
cmt_base: mc::cmt,

src/librustc/middle/mem_categorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ pub impl mem_categorization_ctxt {
551551
id:elt.id(),
552552
span:elt.span(),
553553
cat:cat_rvalue,
554-
mutbl:McImmutable,
554+
mutbl:McDeclared,
555555
ty:expr_ty
556556
}
557557
}

0 commit comments

Comments
 (0)