-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
NLL non lexical lifetime not handling a (seemingly) simple case #88537
Comments
NLL doesn't change when destructors run (it can't, because this can change the observable behavior of the program). So this is working as intended. That |
I don't think there should even be anything to drop in this case though; the variable is moved via So as far as I understand it there's no need for any destructors / implicit drop for I only experimented with calling drop to see what influence it might have on the error, but due to the move above then if it weren't for the first error then I think attempting to drop() before the await should in itself give an error because the variable was already moved. |
Here's a smaller example exhibiting the issue: fn main() {
fn assert_send(_: impl Send) {}
assert_send(async { // error: not Send
let rc = std::rc::Rc::new(0);
drop(rc);
// rc is dropped but is still part of the state machine at the await point
async {}.await
})
} That this fails has nothing to do with the borrow checker and everything to do with how async lowering works (how the state machine is constructed). I'm not sure if this specific aspect of which variables end up in the state machine is subject to stability guarantees that prevent changing the behavior here, but my guess is that this is a known issue (and I'm hoping someone else who knows better can come along and link to it). |
Duplicate of #63768 |
Oh and also this higher level tracking issue: #69663 |
I tried this code:
I expected this to compile but it only compiles if I expand the scope that covers the locked write near the end so it encompasses
connection_status_handler
because otherwise the compiler will complain thatconnection_status_handler
is notSend
safe and might be used after the finalawait
.Considering that the await is at the end of the function (so there's no code that could possibly require
connection_status_handler
to live that long, and also asconnection_status_handler
is moved intodevice.ConnectionStatusChanged(connection_status_handler)
I don't really understand why the borrow checker isn't recognising thatconnection_status_handler
doesn't need to live beyond theawait
here?I tried adding an explicit
drop(connection_status_handler);
just before the last line and even then the compiler still says it's not dropped until the end of the function scope and gives the same error.Meta
rustc --version --verbose
:Compiler Error
For reference this is the some of windows-rs generated code for the TypedEventHandler struct:
Generated code
The text was updated successfully, but these errors were encountered: