-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Borrow Checker allowing mutable and immutable reference out on a vec [Nightly] #41774
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Labels
I-unsound
Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
regression-from-stable-to-nightly
Performance or correctness regression from stable to nightly.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
Here's an even more compressed example demonstrating the bad behavior: struct Data(i32);
impl Data {
fn oh_no(&mut self, other: &mut Data) {
// shouldn't ever succeed, but does
assert!(std::ptr::eq(self, other));
}
}
fn main() {
let mut v = vec![Data(0)];
v[0].oh_no(&mut v[0]);
} |
Seems to have been introduced between nightly on 2017-04-30 (correctly errors) and 2017-05-01 (no error). |
|
OK, I can confirm that #41651 is at fault (tested before/after). I don't have time now to look in more depth at the patch itself. |
arielb1
added a commit
to arielb1/rust
that referenced
this issue
May 8, 2017
Hopefully this is the last PR needed. Fixes rust-lang#41726. Fixes rust-lang#41742. Fixes rust-lang#41774.
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this issue
May 9, 2017
try to fix lvalue ops for real Hopefully this is the last PR needed. Fixes rust-lang#41726. Fixes rust-lang#41742. Fixes rust-lang#41774.
nikomatsakis
pushed a commit
to nikomatsakis/rust
that referenced
this issue
May 22, 2017
Hopefully this is the last PR needed. Fixes rust-lang#41726. Fixes rust-lang#41742. Fixes rust-lang#41774.
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Labels
I-unsound
Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
regression-from-stable-to-nightly
Performance or correctness regression from stable to nightly.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
When using array indexing, the borrow checking is allowing for both an immutable and mutable reference to be taken out on a vec.
Playground: https://play.rust-lang.org/?gist=558d7e98834c5e269eed35b335823220&version=nightly&backtrace=0
Version: rustc 1.19.0-nightly (59f1a2f 2017-05-04)
Offending Code:
Expected Result:
Actual Result:
[Data { x: 6, y: 9 }, Data { x: 6, y: 8 }, Data { x: 4, y: 5 }]
The text was updated successfully, but these errors were encountered: