-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Conversation
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. |
Could you please add a test for this change? Take a look at how they're done in |
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 ? |
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. |
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. |
(After discussion in rust-impl-period/WG-compiler-nll, we decided that we will try the approach of extending the existing tests under |
☔ The latest upstream changes (presumably #44736) made this pull request unmergeable. Please resolve the merge conflicts. |
09f85ed
to
b683538
Compare
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. |
Nice. I suppose we'll also want to add "borrow ends here" when we start supporting these, which should be soon. @bors r+ |
📌 Commit b683538 has been approved by |
@@ -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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 ~|
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 ~|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cf. #44811 (comment)
} | ||
|
||
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) |
There was a problem hiding this comment.
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 ~|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cf. #44811 (comment)
@@ -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) |
There was a problem hiding this comment.
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 ~|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cf. #44811 (comment)
@@ -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) |
There was a problem hiding this comment.
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 ~|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cf. #44811 (comment)
MIR-borrowck: Adding notes to E0506 This PR adds notes to the MIR borrowck error E0506. Part of #44596
☀️ Test successful - status-appveyor, status-travis |
This PR adds notes to the MIR borrowck error E0506.
Part of #44596