Skip to content

Commit 13b5a4e

Browse files
committed
Auto merge of #129716 - compiler-errors:closure-debuginfo, r=cjgillot
Don't use `typeck_root_def_id` in codegen for finding closure's root Generating debuginfo in codegen currently peels off all the closure-specific generics (which presumably is done because they're redundant). This doesn't currently work correctly for the bodies we synthesize for async closures's returned coroutines (#128506), leading to #129702. Specifically, `typeck_root_def_id` for some `DefKind::SyntheticCoroutineBody` just returns itself (because it loops while `is_typeck_child` is `true`, and that returns `false` for this defkind), which means we don't end up peeling off the coroutine-specific generics, and we end up encountering an otherwise unreachable `CoroutineWitness` type leading to an ICE. This PR fixes `is_typeck_child` to consider `DefKind::SyntheticCorotuineBody` to be a typeck child, fixing `typeck_root_def_id` and suppressing this debuginfo bug. Fixes #129702
2 parents 170d6cb + 63405fc commit 13b5a4e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

compiler/rustc_middle/src/ty/util.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,10 @@ impl<'tcx> TyCtxt<'tcx> {
571571
/// Returns `true` if `def_id` refers to a definition that does not have its own
572572
/// type-checking context, i.e. closure, coroutine or inline const.
573573
pub fn is_typeck_child(self, def_id: DefId) -> bool {
574-
matches!(self.def_kind(def_id), DefKind::Closure | DefKind::InlineConst)
574+
matches!(
575+
self.def_kind(def_id),
576+
DefKind::Closure | DefKind::InlineConst | DefKind::SyntheticCoroutineBody
577+
)
575578
}
576579

577580
/// Returns `true` if `def_id` refers to a trait (i.e., `trait Foo { ... }`).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ aux-build:block-on.rs
2+
//@ edition: 2021
3+
//@ build-pass
4+
//@ compile-flags: -Cdebuginfo=2
5+
6+
#![feature(async_closure)]
7+
8+
extern crate block_on;
9+
10+
async fn call_once(f: impl async FnOnce()) {
11+
f().await;
12+
}
13+
14+
pub fn main() {
15+
block_on::block_on(async {
16+
let async_closure = async move || {};
17+
call_once(async_closure).await;
18+
});
19+
}

0 commit comments

Comments
 (0)