Skip to content

MIR-borrowck: fix diagnostics for closures - #45927

Merged
bors merged 2 commits into
rust-lang:masterfrom
sinkuu:mir-borrowck-closure
Nov 13, 2017
Merged

MIR-borrowck: fix diagnostics for closures#45927
bors merged 2 commits into
rust-lang:masterfrom
sinkuu:mir-borrowck-closure

Conversation

@sinkuu

Copy link
Copy Markdown
Contributor

Emit notes for captured variables in the same manner as AST borrowck.

error[E0499]: cannot borrow `x` as mutable more than once at a time (Ast)
--> $DIR/borrowck-closures-two-mut.rs:24:24
|
23 | let c1 = to_fn_mut(|| x = 4);
| -- - previous borrow occurs due to use of `x` in closure
| |
| first mutable borrow occurs here
24 | let c2 = to_fn_mut(|| x = 5); //~ ERROR cannot borrow `x` as mutable more than once
| ^^ - borrow occurs due to use of `x` in closure
| |
| second mutable borrow occurs here
25 | }
| - first borrow ends here
error[E0499]: cannot borrow `x` as mutable more than once at a time (Mir)
--> $DIR/borrowck-closures-two-mut.rs:24:24
|
23 | let c1 = to_fn_mut(|| x = 4);
| -- - previous borrow occurs due to use of `x` in closure
| |
| first mutable borrow occurs here
24 | let c2 = to_fn_mut(|| x = 5); //~ ERROR cannot borrow `x` as mutable more than once
| ^^ - borrow occurs due to use of `x` in closure
| |
| second mutable borrow occurs here
25 | }
| - first borrow ends here

Fixes#45362.

@sinkuu
sinkuuforce-pushed the mir-borrowck-closure branch 2 times, most recently from 5788bd7 to 1872d84CompareNovember 11, 2017 09:47
@kennytmkennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 11, 2017
@sinkuu
sinkuuforce-pushed the mir-borrowck-closure branch 2 times, most recently from e0eafb3 to 5961908CompareNovember 12, 2017 02:26
@sinkuu
sinkuuforce-pushed the mir-borrowck-closure branch from 5961908 to d3e9881CompareNovember 12, 2017 02:27
@alexcrichton

Copy link
Copy Markdown
Member

r? @estebank

@estebankestebank left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me after updating the copyright year.

@@ -0,0 +1,62 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update copyright year


/// Finds the span of arguments of aclosure (within `maybe_closure_span`) and its usage of
/// the local assigned at `location`.
fn find_closure_span(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to add some comments explaining what is being done in the code, but this method is short enough that it is not necessary.

@estebank

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@bors

bors commented Nov 13, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit f99142b has been approved by estebank

kennytm added a commit to kennytm/rust that referenced this pull request Nov 13, 2017
…bank
MIR-borrowck: fix diagnostics for closures
Emit notes for captured variables in the same manner as AST borrowck.
```
error[E0499]: cannot borrow `x` as mutable more than once at a time (Ast)
--> $DIR/borrowck-closures-two-mut.rs:24:24
|
23 | let c1 = to_fn_mut(|| x = 4);
| -- - previous borrow occurs due to use of `x` in closure
| |
| first mutable borrow occurs here
24 | let c2 = to_fn_mut(|| x = 5); //~ ERROR cannot borrow `x` as mutable more than once
| ^^ - borrow occurs due to use of `x` in closure
| |
| second mutable borrow occurs here
25 | }
| - first borrow ends here
error[E0499]: cannot borrow `x` as mutable more than once at a time (Mir)
--> $DIR/borrowck-closures-two-mut.rs:24:24
|
23 | let c1 = to_fn_mut(|| x = 4);
| -- - previous borrow occurs due to use of `x` in closure
| |
| first mutable borrow occurs here
24 | let c2 = to_fn_mut(|| x = 5); //~ ERROR cannot borrow `x` as mutable more than once
| ^^ - borrow occurs due to use of `x` in closure
| |
| second mutable borrow occurs here
25 | }
| - first borrow ends here
```
Fixesrust-lang#45362.
@kennytmkennytm mentioned this pull request Nov 13, 2017
bors added a commit that referenced this pull request Nov 13, 2017
Rollup of 9 pull requests
- Successful merges: #45828, #45892, #45893, #45914, #45917, #45927, #45933, #45952, #45954
- Failed merges:
@bors
bors merged commit f99142b into rust-lang:masterNov 13, 2017
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-reviewStatus: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@sinkuu@alexcrichton@estebank@bors@kennytm