-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[MIR Borrowck] Handle borrows of array elements #46014
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
r? @arielb1 |
|
||
// `&a[i][j]` borrows entire `a` | ||
while let mir::Lvalue::Projection(ref proj) = *lvalue { | ||
if let mir::ProjectionElem::Index(_) = proj.elem { |
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.
Don't we need to recur on walk down other variants of ProjectionElem
as well here? E.g. what if we there is a Field-access or a Downcast mixed into the projection?
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.
Thinking more about it, the real bug here may be the use of Lvalue
within the struct BorrowData
. It probably needs to be an abstraction of Lvalue
, in order to unify cases like a[0]
with a[1]
while still allowing us to differentiate cases like a[0].foo
and a[0].bar
...
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.
Here is a concrete example that this PR does not currently handle:
struct S<T> { x: T, y: T, }
let mut v = [S { x: 1, y: 2 },
S { x: 3, y: 4 },
S { x: 5, y: 6 }];
let p = &v[0].x;
if true {
use_x(*p);
} else {
use_x(22);
}
v[0].x += 1; //[ast]~ ERROR cannot assign to `v[..]`
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.
Note that when I said "It probably needs to be an abstraction of Lvalue", I was basically talking about what the move paths code does; see here: https://github.com/rust-lang/rust/blob/master/src/librustc_mir/dataflow/move_paths/abs_domain.rs (and here)
1a17080
to
26fc1f8
Compare
☔ The latest upstream changes (presumably #46032) made this pull request unmergeable. Please resolve the merge conflicts. |
8e72c70
to
919bc8e
Compare
919bc8e
to
c55200a
Compare
So, to start off: I have not read this version of the PR in depth yet. To be honest I was actually expecting a change to the Skimming over this version of the change, I'm a little surprised by the need to revise how the various kinds of prefixes are handled. Well, let me put it another way: I thought the previous version of the code was pretty readable, in terms of being able to tell immediately, at each iterator, which kind of iteration was being performed. This new version is doing calculations involving
|
Hi @sinkuu by the way, thank you for working on this Pull Request, and sorry it took so long for me to look at your revised version I just spoke with @arielb1 and it sounds like they have a more general fix in the works for this bug, so I am going to close this Pull Request. If you would like to help out with other issues related to the NLL work, I invite you to join the WG-compiler-nll gitter instance ( https://gitter.im/rust-impl-period/WG-compiler-nll ) so that we can all coordinate work accordingly. |
Fixes #45537.