Skip to content

Commit a30b72b

Browse files
committed
auto merge of #18802 : bkoropoff/rust/issue-18769, r=luqmana
Drill down the loan path for `McDeclared` references as well since it might lead to an upvar. Closes #18769
2 parents f187573 + c0a7d55 commit a30b72b

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,10 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
395395
LpUpvar(ty::UpvarId{ var_id: local_id, closure_expr_id: _ }) => {
396396
self.tcx().used_mut_nodes.borrow_mut().insert(local_id);
397397
}
398-
LpExtend(ref base, mc::McInherited, _) => {
398+
LpExtend(ref base, mc::McInherited, _) |
399+
LpExtend(ref base, mc::McDeclared, _) => {
399400
self.mark_loan_path_as_mutated(&**base);
400401
}
401-
LpExtend(_, mc::McDeclared, _) |
402402
LpExtend(_, mc::McImmutable, _) => {
403403
// Nothing to do.
404404
}

src/test/run-pass/unboxed-closures-move-mutable.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
// Test that mutating a mutable upvar in a capture-by-value unboxed
1515
// closure does not ice (issue #18238) and marks the upvar as used
1616
// mutably so we do not get a spurious warning about it not needing to
17-
// be declared mutable (issue #18336).
17+
// be declared mutable (issue #18336 and #18769)
18+
19+
fn set(x: &mut uint) { *x = 42; }
1820

1921
fn main() {
2022
{
@@ -25,4 +27,12 @@ fn main() {
2527
let mut x = 0u;
2628
move |:| x += 1;
2729
}
30+
{
31+
let mut x = 0u;
32+
move |&mut:| set(&mut x);
33+
}
34+
{
35+
let mut x = 0u;
36+
move |:| set(&mut x);
37+
}
2838
}

0 commit comments

Comments
 (0)