I tried this code:
struct NeedsDrop<'a>(&'a Vec<i32>);
impl Drop for NeedsDrop<'_> {
fn drop(&mut self) {
println!("dropping {:#?}", self.0);
}
}
async fn await_point() {}
fn main() {
let v = vec![1, 2, 3];
let x = NeedsDrop(&v);
let c = async {
std::future::ready(()).await;
drop(x);
};
drop(v);
}
I expected it to fail, since dropping the coroutine c requires that NeedsDrop's 'a lifetime is live, since dropping the coroutine also performs a drop of NeedsDrop (as an upvar).
Instead, it compiled. This is UB.
This fails on rustc as of nightly 2025-07-18. Not sure if this has either always been incorrect, or if this was introduced due to the fix in #117134.
I tried this code:
I expected it to fail, since dropping the coroutine
crequires thatNeedsDrop's'alifetime is live, since dropping the coroutine also performs a drop ofNeedsDrop(as an upvar).Instead, it compiled. This is UB.
This fails on rustc as of nightly 2025-07-18.
Not sure if this has either always been incorrect, or ifthis was introduced due to the fix in #117134.