-
Notifications
You must be signed in to change notification settings - Fork 13k
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
regression: cannot borrow ... as immutable because it is also borrowed as mutable #135671
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. |
The text was updated successfully, but these errors were encountered: