From 63405fc2b3a15194e47712b738275c6d76de6b27 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 14 Sep 2024 16:33:25 -0400 Subject: [PATCH] Consider synthetic closure bodies to be typeck children --- compiler/rustc_middle/src/ty/util.rs | 5 ++++- .../async-closures/debuginfo-by-move-body.rs | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/ui/async-await/async-closures/debuginfo-by-move-body.rs diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index d70ff8258d0..a0262f12cb5 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -571,7 +571,10 @@ impl<'tcx> TyCtxt<'tcx> { /// Returns `true` if `def_id` refers to a definition that does not have its own /// type-checking context, i.e. closure, coroutine or inline const. pub fn is_typeck_child(self, def_id: DefId) -> bool { - matches!(self.def_kind(def_id), DefKind::Closure | DefKind::InlineConst) + matches!( + self.def_kind(def_id), + DefKind::Closure | DefKind::InlineConst | DefKind::SyntheticCoroutineBody + ) } /// Returns `true` if `def_id` refers to a trait (i.e., `trait Foo { ... }`). diff --git a/tests/ui/async-await/async-closures/debuginfo-by-move-body.rs b/tests/ui/async-await/async-closures/debuginfo-by-move-body.rs new file mode 100644 index 00000000000..6f339f0c8ef --- /dev/null +++ b/tests/ui/async-await/async-closures/debuginfo-by-move-body.rs @@ -0,0 +1,19 @@ +//@ aux-build:block-on.rs +//@ edition: 2021 +//@ build-pass +//@ compile-flags: -Cdebuginfo=2 + +#![feature(async_closure)] + +extern crate block_on; + +async fn call_once(f: impl async FnOnce()) { + f().await; +} + +pub fn main() { + block_on::block_on(async { + let async_closure = async move || {}; + call_once(async_closure).await; + }); +}