Skip to content

Commit 94669d9

Browse files
committed
Add file and line metadata for closures
1 parent 5b23c38 commit 94669d9

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,15 +1212,23 @@ fn build_closure_env_di_node<'ll, 'tcx>(
12121212
let containing_scope = get_namespace_for_item(cx, def_id);
12131213
let type_name = compute_debuginfo_type_name(cx.tcx, closure_env_type, false);
12141214

1215+
let closure_span = cx.tcx.def_span(def_id);
1216+
let (file_metadata, line_number) = if !closure_span.is_dummy() {
1217+
let loc = cx.lookup_debug_loc(closure_span.lo());
1218+
(file_metadata(cx, &loc.file), loc.line)
1219+
} else {
1220+
(unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER)
1221+
};
1222+
12151223
type_map::build_type_with_children(
12161224
cx,
12171225
type_map::stub(
12181226
cx,
12191227
Stub::Struct,
12201228
unique_type_id,
12211229
&type_name,
1222-
unknown_file_metadata(cx),
1223-
UNKNOWN_LINE_NUMBER,
1230+
file_metadata,
1231+
line_number,
12241232
cx.size_and_align_of(closure_env_type),
12251233
Some(containing_scope),
12261234
DIFlags::FlagZero,

tests/codegen/issue-98678.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@
88
// CHECK: !DICompositeType({{.*"}}MyType{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]],
99
pub struct MyType;
1010

11-
pub fn foo(_: MyType) {}
11+
pub fn foo(_: MyType) {
12+
// CHECK: !DICompositeType({{.*"[{]}}closure_env#0{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]],
13+
let closure = |x| x;
14+
closure(0);
15+
}

0 commit comments

Comments
 (0)