-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Change check_loans to use ExprUseVisitor #14318
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
Conversation
Maybe it would make more sense for the |
Going over the patch again, I realize that the changed results in |
I pushed my changes. The only difference is in the |
(Needs a rebase.) |
Rebased to account for the string refactoring. |
@zwarich I added some comments, a few things concern me, can you let me know what you think? |
I replied to your comments, although I can't seem to find them outside of my email inbox since they were on a pre-rebase version of my changes (is this just some GitHub UI issue?). The most concerning issue (the new incorrect test result) was fixed in a newer version of the changes, and I left questions for you about the others. Let me know what you think and I'll update my changes again. |
@nikomatsakis I pushed some updated commits to my branch. I changed some things in response to your previous comments:
|
I made two small changes to my branch. I noticed that all of the code in |
let y = &mut x.a; | ||
let z = &mut x.a; //~ ERROR cannot borrow `x.a` as mutable more than once at a time | ||
drop(*y); | ||
drop(*z); |
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 am surprised that we can drop *y
and *z
, as that is borrowed content. Is this simply an artifact of us not reporting an error for some other reason?
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.
It's fine because *y
and *z
are integers, and they seem to get copied rather than moved. This code compiles fine:
fn foo() {
let mut x = A { a: 1, b: box 2 };
let y = &mut x.a;
drop(*y);
}
but if I use the x.b
field, which is a Box<int>
, like this:
fn bar() {
let mut x = A { a: 1, b: box 2 };
let y = &mut x.b;
drop(*y);
}
then I get an error:
test.rs:24:10: 24:12 error: cannot move out of dereference of `&mut`-pointer
test.rs:24 drop(*y);
^~
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.
On Wed, May 28, 2014 at 12:46:04PM -0700, Cameron Zwarich wrote:
It's fine because
*y
and*z
are integers, and they seem to get copied rather than moved.
Indeed. I overlooked that.
Refactor a number of functions in check_loans to take node IDs and spans rather than taking expressions directly. Also rename some variables to make them less ambiguous. This is the first step towards using ExprUseVisitor in check_loans, as now some of the interfaces more closely match those used in ExprUseVisitor.
Currently mem_categorization categorizes an AutoObject adjustment the same as the original expression. This can cause two moves to be generated for the same underlying expression. Currently this isn't a problem in practice, since check_loans doesn't rely on ExprUseVisitor.
This isn't necessary right now, but check_loans needs to be able to distinguish between initialization and writes in the ExprUseVisitor mutate callback.
Currently it is not possible to distinguish moves caused by captures in the ExprUseVisitor interface. Since check_Loans needs to make that distinction for generating good diagnostics, this is necessary for check_loans to switch to ExprUseVisitor.
When converting check_loans to use ExprUseVisitor I encountered a few issues where the wrong number of errors were being emitted for multiple closure captures, but there is no existing test for this.
I tried to split up the less mechanical changes into separate commits so they are easier to review. One thing I'm not quite sure of is whether `MoveReason` should just be replaced with `move_data::MoveKind`.
After sitting down to build on the work merged in #14318, I realized that some of the test names were not clear, others probably weren't testing the right thing, and they were also not as exhaustive as they could have been.
I tried to split up the less mechanical changes into separate commits so they are easier to review. One thing I'm not quite sure of is whether
MoveReason
should just be replaced withmove_data::MoveKind
.