Conditional return
seems to hold the reference forever
#124070
Labels
A-borrow-checker
Area: The borrow checker
C-bug
Category: This is a bug.
fixed-by-polonius
Compiling with `-Zpolonius` fixes this issue.
T-types
Relevant to the types team, which will review and decide on the PR/issue.
Hi, thanks for the language! However, I am facing a compilation error and cannot use it :(
I tried this code:
P.S. The real world case requires
mut
(though this simple demo does not).I expected to see this happen: explanation
No error.
IMHO, there are two cases:
If the
if
gets true, it will immediately return, and everything is OKIf the
if
gets false, the variablea
is never used afterwards. You can also add thatdrop
(but still error). Thus, it should not have problem.Instead, this happened: explanation
Meta
rustc --version --verbose
:Backtrace
P.S. More (roughly equivalent) examples that do not work
P.S. Another maybe related example that does not work
gives
Cross-posted: https://users.rust-lang.org/t/conditional-return-seems-to-hold-the-reference-forever/110090
The text was updated successfully, but these errors were encountered: