fixed-by-polonius loops/functions have very bad diagnostics #125217
Labels
A-borrow-checker
Area: The borrow checker
A-diagnostics
Area: Messages for errors, warnings, and lints
D-confusing
Diagnostics: Confusing error or lint that should be reworked.
D-terse
Diagnostics: An error or lint that doesn't give enough information about the problem at hand.
fixed-by-polonius
Compiling with `-Zpolonius` fixes this issue.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Code
Current output
Desired output
"use -Zpolonius lol"
Rationale and extra context
"immutable borrow used here" pointing at the same span as "mutable borrow used here" is very unhelpful. the only case this could possibly make sense is when the code is in a loop, which this is not.
i originally ran into this problem inside of an (unrelated) loop, making the diagnostic even more confusing.
Other cases
removing
break
makes the error a little better, but it still would be nice to say "this is a limitation of lifetimes" instead of "your code is broken"the recursive case is also pretty confusing, although it looks more like a "traditional" polonius error so maybe it's easier to recognize
another workaround is to add an extra unwrap() so it doesn't look to the compiler like the lifetimes are related:
Rust Version
Anything else?
@rustbot label fixed-by-polonius
The text was updated successfully, but these errors were encountered: