async fn whatever(self) {
let r: Ref<Foo> = self.foo.borrow(); // tokio::sync::watch::Ref
// no await here
drop(r);
some_other_stuff.await;
}
The compiler assumes r is dropped at the end of the function, not at the drop call and complains r can be used accross await. As if it ignored the call to drop.
If I modify the code to use lexical scope instead of drop, everything works fine:
async fn whatever(self) {
{
let r: Ref<Foo> = self.foo.borrow(); // tokio::sync::watch::Ref
// no await here
}
some_other_stuff.await;
}
Note also that in general, drop is “just a function”; the compiler is not aware that drop discards the value rather than doing something else with it. That doesn't affect this situation, because the compiler does know that the value was definitely moved out of the whatever future, and should be able to make use of that fact, as per the linked issue; but it is something to be aware of in general, and a reason you might need to use a scope rather than drop.