The borrow checker can't prove correctness for all possible valid code. It has some limitations, but it's constantly evolving. In older versions of Rust, it considered values to be borrowed for their entire scope in these cases; a not-so-recent improvement called "non-lexical lifetimes" lifted this restriction and made borrowck smarter. In yet another update called "Polonius", it will be even smarter. Until then, you'll sometimes need to rewrite these patterns in a way that it can prove correctness.
H2CO3
2
Related topics
| Topic | Replies | Views | Activity | |
|---|---|---|---|---|
| Why can a mutable reference exist together with a shared reference but not with another mutable reference? | 2 | 446 | April 10, 2023 | |
|
Simple borrow error
|
5 | 604 | January 6, 2024 | |
| Why does the "Two-phase borrows" not work for these cases? | 9 | 695 | April 8, 2024 | |
| Multiple borrowing in one statement | 11 | 418 | August 18, 2024 | |
| Question for "Rust Programming Language" book, Page 132 | 5 | 768 | July 2, 2019 |