From 3e65c76996d6ddd89ddfea64fbcd47153edf206f Mon Sep 17 00:00:00 2001 From: Sebastien Tardif Date: Fri, 19 Jun 2026 15:02:59 -0700 Subject: [PATCH 1/2] fix: add CoroutineClosure to maybe_drop_guard type list Signed-off-by: Sebastien Tardif --- compiler/rustc_mir_transform/src/liveness.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_mir_transform/src/liveness.rs b/compiler/rustc_mir_transform/src/liveness.rs index 795b0b9cac82e..c02eb471e71e5 100644 --- a/compiler/rustc_mir_transform/src/liveness.rs +++ b/compiler/rustc_mir_transform/src/liveness.rs @@ -238,6 +238,7 @@ fn maybe_drop_guard<'tcx>( matches!( ty.kind(), ty::Closure(..) + | ty::CoroutineClosure(..) | ty::Coroutine(..) | ty::Tuple(..) | ty::Adt(..) From 0fb2281b0f93d9bb9460542de3144a39d2626256 Mon Sep 17 00:00:00 2001 From: Sebastien Tardif Date: Fri, 19 Jun 2026 15:44:53 -0700 Subject: [PATCH 2/2] test: add regression test for liveness CoroutineClosure drop guard Signed-off-by: Sebastien Tardif --- .../async-closures/liveness-drop-guard.rs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/ui/async-await/async-closures/liveness-drop-guard.rs diff --git a/tests/ui/async-await/async-closures/liveness-drop-guard.rs b/tests/ui/async-await/async-closures/liveness-drop-guard.rs new file mode 100644 index 0000000000000..0f3dde71e1d39 --- /dev/null +++ b/tests/ui/async-await/async-closures/liveness-drop-guard.rs @@ -0,0 +1,25 @@ +// Regression test for #479: maybe_drop_guard missing CoroutineClosure in type list. +// Before the fix, async closures holding Drop types could produce false +// "unused variable" warnings because liveness analysis did not recognize +// CoroutineClosure as a type that may have drop guards. + +//@ edition:2021 +//@ check-pass + +#![deny(unused_variables)] + +struct NeedsDrop(i32); + +impl Drop for NeedsDrop { + fn drop(&mut self) {} +} + +fn main() { + let _ = async { + let d = NeedsDrop(1); + let c = async move || { + let _ = &d; + }; + c().await; + }; +}