rustc
thinks that two non-intersecting borrows intersect. And fails compilation
#139930
Labels
A-borrow-checker
Area: The borrow checker
C-bug
Category: This is a bug.
fixed-by-polonius
Compiling with `-Zpolonius` fixes this issue.
Here is a minimal example
I expected to see this happen:
Instead, this happened: I have got a compile error on a perfectly valid code.
The code being valid can be proved by the fact that if we remove the
loop
- the function compiles perfectly:Moreover, breaking the loop by returning in no way breaks any borrowing rules. If reference is returned - then line that mutates data cannot be executed, and this error message makes no sense. If reference is not returned - this error message also make no sense.
UPD: Moreover, manually unwinding the loop also breaks compilation:
Gives:
Even though immutable borrow ends after
match {}
ends -rustc
for some invalid reason thinks that returning a reference makes it borrowed "forever".Meta
Bug works the same both on stable and nightly.
rustc --version --verbose
of stable:of nightly:
Backtrace does not exist since program does not compile.
The text was updated successfully, but these errors were encountered: