Skip to content

Fix upvars sometimes not being marked as used mutably #18802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/librustc/middle/borrowck/gather_loans/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,10 @@ 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, _) => {
LpExtend(ref base, mc::McInherited, _) |
LpExtend(ref base, mc::McDeclared, _) => {
self.mark_loan_path_as_mutated(&**base);
}
LpExtend(_, mc::McDeclared, _) |
LpExtend(_, mc::McImmutable, _) => {
// Nothing to do.
}
Expand Down
12 changes: 11 additions & 1 deletion src/test/run-pass/unboxed-closures-move-mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
// Test that mutating a mutable upvar in a capture-by-value unboxed
// closure does not ice (issue #18238) and marks the upvar as used
// mutably so we do not get a spurious warning about it not needing to
// be declared mutable (issue #18336).
// be declared mutable (issue #18336 and #18769)

fn set(x: &mut uint) { *x = 42; }

fn main() {
{
Expand All @@ -25,4 +27,12 @@ fn main() {
let mut x = 0u;
move |:| x += 1;
}
{
let mut x = 0u;
move |&mut:| set(&mut x);
}
{
let mut x = 0u;
move |:| set(&mut x);
}
}