Got a borrow checking issue in a simple if-else statement

Beware, polonius is still incomplete and may accept some code aren't meant to be accepted. Only use it for experimental purpose!

2 Likes

Yes, I just enabled it for fun :rofl:

IMO, the most useful way of using the flag is for peace of mind that it's (most likely) the borrow checker's fault that your code doesn't work. I often use it (via godbolt.org) to test code posted to this forum that remotely looks like it could be a "solved by polonius" kind of lifetime issue. Which is something I can easily do before spending any effort in understanding the code myself.

Also it can be a useful way to double-check that solving the problem with polonius_the_crab is (most likely) going to be possible, before you need to tackle problem of how to actually best refractor your code with the relevant macros to make it compile on stable Rust. Of course, as documentation of that crate, too, specifies, if the problem can be easily (and at least somewhat elegantly) avoided on the first place, than using the polonius_the_crab crate would be overkill.

1 Like

Nice point. I totally got paniced today, and keep thinking that "I wrote Rust for a while, and still not be able to write borrow safety code in such an easy if-else statement". :rofl:

To state the positives: you can now officially claim that you are (occasionally) smarter than the borrow checker :laughing:

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.