Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upMIR-borrowck: Adding notes to E0506 #44811
Conversation
rust-highfive
assigned
arielb1
Sep 24, 2017
This comment has been minimized.
This comment has been minimized.
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @arielb1 (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
|
Could you please add a test for this change? Take a look at how they're done in |
This comment has been minimized.
This comment has been minimized.
|
There is a test for E0506 (https://github.com/rust-lang/rust/blob/master/src/test/compile-fail/E0506.rs), but it doesn't test this message because the compiler uses the AST borrowck instead of the MIR borrowck. I manually checked that the messages were the same though. I assumed that the tests for MIR borrowck would be added on a later PR (@pnkfelix ?). Or maybe you're asking for a different kind of test ? |
This comment has been minimized.
This comment has been minimized.
|
We could actually use a UI test for this, but it's not feasible right now because we can't properly display lvalues in the MIR borrowck. |
This comment has been minimized.
This comment has been minimized.
|
In principle we could add a test, by telling the test infrastructure to pass the necessary In particular, you can do (I assume that the UI tests accept the same Whether its a good idea to put in tests for MIR-borrowck at this stage... it probably is worth it, just to make sure we don't regress. But maybe they should go into their own sub-directory or something, just to keep them isolated from "real tests" of current functionality. |
This comment has been minimized.
This comment has been minimized.
|
(After discussion in rust-impl-period/WG-compiler-nll, we decided that we will try the approach of extending the existing tests under |
carols10cents
added
the
S-waiting-on-author
label
Sep 25, 2017
pnkfelix
referenced this pull request
Sep 25, 2017
Merged
Add span label to E0384 for MIR borrowck #44806
This comment has been minimized.
This comment has been minimized.
|
|
zilbuz
added some commits
Sep 24, 2017
zilbuz
force-pushed the
zilbuz:issue-44596/E0506
branch
from
09f85ed
to
b683538
Sep 26, 2017
This comment has been minimized.
This comment has been minimized.
|
Alright I edited the tests on compile-fail that raise E0506. I omitted the tests that triggers ICE as other issues are supposed to fix them. |
This comment has been minimized.
This comment has been minimized.
|
Nice. I suppose we'll also want to add "borrow ends here" when we start supporting these, which should be soon. @bors r+ |
This comment has been minimized.
This comment has been minimized.
|
|
arielb1
reviewed
Sep 27, 2017
| @@ -975,10 +975,19 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx> | |||
| err.emit(); | |||
| } | |||
|
|
|||
| fn report_illegal_mutation_of_borrowed(&mut self, _: Context, (lvalue, span): (&Lvalue, Span)) { | |||
| fn report_illegal_mutation_of_borrowed(&mut self, | |||
This comment has been minimized.
This comment has been minimized.
arielb1
Sep 27, 2017
Contributor
I think this should be moved to borrowck_errors actually, but that could be done in another commit.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
pnkfelix
reviewed
Sep 27, 2017
| } | ||
|
|
||
| fn double_borrow2<T>(x: &mut Box<T>) { | ||
| borrow2(x, x); | ||
| //~^ ERROR cannot borrow `*x` as immutable because it is also borrowed as mutable | ||
| //[ast]~^ ERROR cannot borrow `*x` as immutable because it is also borrowed as mutable | ||
| //[mir]~^^ ERROR cannot borrow `*x` as immutable because it is also borrowed as mutable (Ast) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
zilbuz
Sep 27, 2017
Author
Contributor
No, it seems that when using revisions, the comments of the revision not currently compiled aren't processed. If I use ~|, I have the following error :
compile-fail\coerce-overloaded-autoderef.rs' panicked at 'encountered //~| without preceding //~^ line.', src\libcore\option.rs:839:4
pnkfelix
reviewed
Sep 27, 2017
| } | ||
|
|
||
| fn double_mut_borrow2<T>(x: &mut Box<T>) { | ||
| borrow_mut2(x, x); | ||
| //~^ ERROR cannot borrow `*x` as mutable more than once at a time | ||
| //[ast]~^ ERROR cannot borrow `*x` as mutable more than once at a time | ||
| //[mir]~^^ ERROR cannot borrow `*x` as mutable more than once at a time (Ast) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
pnkfelix
reviewed
Sep 27, 2017
| } | ||
|
|
||
| fn double_imm_borrow(x: &mut Box<i32>) { | ||
| let y = borrow(x); | ||
| let z = borrow(x); | ||
| **x += 1; | ||
| //~^ ERROR cannot assign to `**x` because it is borrowed | ||
| //[ast]~^ ERROR cannot assign to `**x` because it is borrowed | ||
| //[mir]~^^ ERROR cannot assign to `**x` because it is borrowed (Ast) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
pnkfelix
reviewed
Sep 27, 2017
| @@ -17,24 +20,32 @@ fn borrow2<T>(_: &mut T, _: &T) {} | |||
| fn double_mut_borrow<T>(x: &mut Box<T>) { | |||
| let y = borrow_mut(x); | |||
| let z = borrow_mut(x); | |||
| //~^ ERROR cannot borrow `*x` as mutable more than once at a time | |||
| //[ast]~^ ERROR cannot borrow `*x` as mutable more than once at a time | |||
| //[mir]~^^ ERROR cannot borrow `*x` as mutable more than once at a time (Ast) | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
pnkfelix
reviewed
Sep 27, 2017
| @@ -39,7 +42,9 @@ fn main() { | |||
| let mut v = MyVec { x: MyPtr { x: Foo { f: 22 } } }; | |||
| let i = &v[0].f; | |||
| v = MyVec { x: MyPtr { x: Foo { f: 23 } } }; | |||
| //~^ ERROR cannot assign to `v` | |||
| //[ast]~^ ERROR cannot assign to `v` | |||
| //[mir]~^^ ERROR cannot assign to `v` because it is borrowed (Ast) | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Sep 29, 2017
This comment has been minimized.
This comment has been minimized.
|
|
zilbuz commentedSep 24, 2017
This PR adds notes to the MIR borrowck error E0506.
Part of #44596