-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Polonius fails to infer lifetimes of borrows #134554
Comments
|
Gotcha. Just for the record, I get an error with |
I don't have that much time to look into it, so I may also be missing something, but at first glance the error looks correct to me.
Your If this reading is correct, it kind of looks like the following, which is clearer to see why it errors fn read_non_empty(foo: &mut u32) {
let a = read(foo);
let _ = read(foo);
drop(a);
}
fn read(_: &mut u32) -> &u32 {
unimplemented!();
} Now if |
But why should me returning the value, make the borrow last for the entire scope of the function? 🤔 If I return the value, nothing else in the function can access it anymore. If I do not return the value, the scope of the borrow should ensure that it's dropped (explicitly dropping doesn't help here either).
but that's not my use case. I need to return the value if it satisfied a certain condition, otherwise keep reading it. |
Ah, you meant to reduce the reproducer. Sorry, I misunderstood. |
I tried this code:
I expected to see this happen: Compilation to succeed.
Instead, this happened: Got an error:
If I modify the code to not use a loop, I still get the same:
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: