Skip to content
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

MIR-borrowck: Adding notes to E0506 #44811

Merged
merged 3 commits into from
Sep 29, 2017
Merged

Conversation

zilbuz
Copy link
Contributor

@zilbuz zilbuz commented Sep 24, 2017

This PR adds notes to the MIR borrowck error E0506.

Part of #44596

@rust-highfive
Copy link
Collaborator

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.

@GuillaumeGomez
Copy link
Member

Could you please add a test for this change? Take a look at how they're done in src/test/compile-fail.

@zilbuz
Copy link
Contributor Author

zilbuz commented Sep 24, 2017

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 ?

@KiChjang
Copy link
Member

KiChjang commented Sep 24, 2017

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.

@pnkfelix
Copy link
Member

In principle we could add a test, by telling the test infrastructure to pass the necessary -Z flags.

In particular, you can do // compile-flags: -Z emit-end-regions -Z borrowck-mir at the top of the file. (You can find other tests that pass other such flags in src/test/compile-fail/)

(I assume that the UI tests accept the same compile-flags comment.)

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.

@pnkfelix
Copy link
Member

(After discussion in rust-impl-period/WG-compiler-nll, we decided that we will try the approach of extending the existing tests under compile-fail/ via the // revisions: ... system so that we can keep a single test file and list different sets of expected error messages based on whether or not we are passing -Z borrowck-mir.)

@carols10cents carols10cents added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Sep 25, 2017
@bors
Copy link
Contributor

bors commented Sep 26, 2017

☔ The latest upstream changes (presumably #44736) made this pull request unmergeable. Please resolve the merge conflicts.

@zilbuz
Copy link
Contributor Author

zilbuz commented Sep 26, 2017

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.

@arielb1
Copy link
Contributor

arielb1 commented Sep 27, 2017

Nice. I suppose we'll also want to add "borrow ends here" when we start supporting these, which should be soon.

@bors r+

@bors
Copy link
Contributor

bors commented Sep 27, 2017

📌 Commit b683538 has been approved by arielb1

@@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be moved to borrowck_errors actually, but that could be done in another commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean like @mikhail-m1 has done in #44882 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done here: #44922

}

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)
Copy link
Member

@pnkfelix pnkfelix Sep 27, 2017

Choose a reason for hiding this comment

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

the ~^^ here could just be ~|

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

}

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)
Copy link
Member

@pnkfelix pnkfelix Sep 27, 2017

Choose a reason for hiding this comment

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

the ~^^ here could just be ~|

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

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)
Copy link
Member

Choose a reason for hiding this comment

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

the ~^^ here could just be ~|

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

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

the ~^^ here could just be ~|

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

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

the ~^^ here could just be ~|

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bors
Copy link
Contributor

bors commented Sep 29, 2017

⌛ Testing commit b683538 with merge a379780...

bors added a commit that referenced this pull request Sep 29, 2017
MIR-borrowck: Adding notes to E0506

This PR adds notes to the MIR borrowck error E0506.

Part of #44596
@bors
Copy link
Contributor

bors commented Sep 29, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: arielb1
Pushing a379780 to master...

@bors bors merged commit b683538 into rust-lang:master Sep 29, 2017
@zilbuz zilbuz deleted the issue-44596/E0506 branch September 29, 2017 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants