-
Notifications
You must be signed in to change notification settings - Fork 13.3k
regression: cannot borrow ... as immutable because it is also borrowed as mutable #135671
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
Comments
Minimal: struct Test {
a: i32,
b: i32,
}
fn main() {
let inputs: &mut [_] = &mut [Test { a: 0, b: 0 }];
let a = &mut inputs[0].a;
let b = &mut inputs[0].b;
*a = 0;
*b = 1;
} |
I think we should probably revert #133734 (and the follow-up PR that fully removed the Specifically, the problem here is that the borrow-checker treated the After this revert, we could either think about:
However, in the mean time, I'd rather we not crunch trying to find and more importantly validate the soundness of a solution 🤔 |
Oh wow, that minimal repro is … just normal code very deliberately supported by borrow checking for a long time!? There was no UI test for that? I’ve even shared code examples like this in the forums before … multiple times o.O (One example is here, e.g. the very first code block is broken on beta. And here’s another one, the example I suppose, this means I should write down some of this stuff as UI tests, right? By the way, tuples could be used, too… e.g. for a minimal repro without defining a fn main() {
let slice = &mut [(0, 0)][..];
std::mem::swap(&mut slice[0].0, &mut slice[0].1);
} And here’s an example similar to the latter one of my forum-examples linked above fn foo(a: &mut [(i32, i32)], i: usize, j: usize) -> (&mut i32, &mut i32) {
(&mut a[i].0, &mut a[j].1)
} |
@steffahn: If you want to contribute some tests that exercise disjoint borrows, feel free to. I'll review them. |
Fixed on nightly. Reopening to track beta backport. |
WG-prioritization assigning priority (Zulip discussion). @rustbot label -I-prioritize +P-critical |
closing since #135709 was merged |
Reopening as #135709 wasn't merged. |
#136650 backported the fix to beta. |
Temporarily bring back `Rvalue::Len` r? `@compiler-errors` as requested in rust-lang#135671 (comment) > However, in the mean time, I'd rather we not crunch trying to find and more importantly validate the soundness of a solution 🤔 Agreed. To fix the IMO P-critical rust-lang#135671 for which we somehow didn't have test coverage, this PR temporarily reverts: - rust-lang#133734 - its bugfix rust-lang#134371 - rust-lang#134330 cc `@scottmcm` I added the few samples from that issue as a test, but we can add more in the future, in particular it seems `@steffahn` [will work on that](rust-lang#135671 (comment)). Fixes rust-lang#135671. And if we want to land this, it should also be nominated for beta backport.
The text was updated successfully, but these errors were encountered: