Skip to content

Commit 114214b

Browse files
Don't use typeck_root_def_id in codegen for finding closure's root
1 parent ac77e88 commit 114214b

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,15 @@ impl DebugContext {
198198
let mut name = String::new();
199199
type_names::push_item_name(tcx, instance.def_id(), false, &mut name);
200200

201-
// Find the enclosing function, in case this is a closure.
202-
let enclosing_fn_def_id = tcx.typeck_root_def_id(instance.def_id());
201+
// Find the enclosing function, in case this is a closure, coroutine,
202+
// coroutine-closure, or synthetic MIR body.
203+
let mut enclosing_fn_def_id = def_id;
204+
while matches!(
205+
tcx.def_kind(enclosing_fn_def_id),
206+
DefKind::Closure | DefKind::SyntheticCoroutineBody
207+
) {
208+
enclosing_fn_def_id = tcx.parent(enclosing_fn_def_id);
209+
}
203210

204211
// We look up the generics of the enclosing function and truncate the args
205212
// to their length in order to cut off extra stuff that might be in there for

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext, Variab
1111
use rustc_codegen_ssa::traits::*;
1212
use rustc_data_structures::sync::Lrc;
1313
use rustc_data_structures::unord::UnordMap;
14+
use rustc_hir::def::DefKind;
1415
use rustc_hir::def_id::{DefId, DefIdMap};
1516
use rustc_index::IndexVec;
1617
use rustc_middle::mir;
@@ -332,8 +333,15 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
332333
let mut name = String::with_capacity(64);
333334
type_names::push_item_name(tcx, def_id, false, &mut name);
334335

335-
// Find the enclosing function, in case this is a closure.
336-
let enclosing_fn_def_id = tcx.typeck_root_def_id(def_id);
336+
// Find the enclosing function, in case this is a closure, coroutine,
337+
// coroutine-closure, or synthetic MIR body.
338+
let mut enclosing_fn_def_id = def_id;
339+
while matches!(
340+
tcx.def_kind(enclosing_fn_def_id),
341+
DefKind::Closure | DefKind::SyntheticCoroutineBody
342+
) {
343+
enclosing_fn_def_id = tcx.parent(enclosing_fn_def_id);
344+
}
337345

338346
// We look up the generics of the enclosing function and truncate the args
339347
// to their length in order to cut off extra stuff that might be in there for
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)