You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
regression: cannot borrow ... as immutable because it is also borrowed as mutable #135671
I think we should probably revert #133734 (and the follow-up PR that fully removed the Len operand), and spend some more time on a solution that is both resilient to borrowck and also to miri.
Specifically, the problem here is that the borrow-checker treated the Len operand specially (as a kind of fake borrow) which allowed it to be interleaved with mutable live mutable references pointing into the slice. The same does not apply to the RawPtr operand (&raw const) that we emit as part of the new lowering (all of this happens because we must read the slice length to emit a bounds check before slice accesses). Instead, in MIR borrowck, we currently treat RawPtr operands like borrows, so the metadata access for let b = ... is treated like an access conflict with the mutable reference of let a = ....
After this revert, we could either think about:
Changing the semantics of &raw (const|mut) operand in borrowck to not act like an access
Emitting a new kind of special copy operand (much like CopyForDeref) that allows us to treat the access of an array for length access as disjoint.
Some other solution...
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 bar2 in the playground behind the last paragraph’s link.)
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 struct:
Activity
compiler-errors commentedon Jan 18, 2025
This regressed in #133734 cc @scottmcm
I assume that maybe there was something missing here 🤔
compiler-errors commentedon Jan 18, 2025
Minimal:
compiler-errors commentedon Jan 18, 2025
I think we should probably revert #133734 (and the follow-up PR that fully removed the
Lenoperand), and spend some more time on a solution that is both resilient to borrowck and also to miri.Specifically, the problem here is that the borrow-checker treated the
Lenoperand specially (as a kind of fake borrow) which allowed it to be interleaved with mutable live mutable references pointing into the slice. The same does not apply to theRawPtroperand (&raw const) that we emit as part of the new lowering (all of this happens because we must read the slice length to emit a bounds check before slice accesses). Instead, in MIR borrowck, we currently treatRawPtroperands like borrows, so the metadata access forlet b = ...is treated like an access conflict with the mutable reference oflet a = ....After this revert, we could either think about:
&raw (const|mut)operand in borrowck to not act like an accessCopyForDeref) that allows us to treat the access of an array for length access as disjoint.However, in the mean time, I'd rather we not crunch trying to find and more importantly validate the soundness of a solution 🤔
steffahn commentedon Jan 18, 2025
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
bar2in the playground behind the last paragraph’s link.)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
struct:And here’s an example similar to the latter one of my forum-examples linked above
compiler-errors commentedon Jan 18, 2025
@steffahn: If you want to contribute some tests that exercise disjoint borrows, feel free to. I'll review them.
Auto merge of rust-lang#135709 - lqd:bring-back-len, r=compiler-errors
lqd commentedon Jan 19, 2025
Fixed on nightly. Reopening to track beta backport.
6 remaining items
lqd commentedon Jan 29, 2025
Reopening as #135709 wasn't merged.
lqd commentedon Feb 3, 2025
This was already fixed on nightly. #136352 unblocked fixing it on beta. Reopening to track beta backport of #135709.
cuviper commentedon Feb 7, 2025
#136650 backported the fix to beta.
Auto merge of rust-lang#135709 - lqd:bring-back-len, r=compiler-errors
Auto merge of #135709 - lqd:bring-back-len, r=compiler-errors
Auto merge of #135709 - lqd:bring-back-len, r=compiler-errors