about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatt Weber <30441572+mweber15@users.noreply.github.com>2022-11-16 15:37:31 -0500
committerMatt Weber <30441572+mweber15@users.noreply.github.com>2024-11-06 22:12:03 -0500
commit94669d9d47e3a594f4179a2aca9997fa1aeea7ad (patch)
treece1155f0a4e6e67567c627af79a31efc316e5362
parent5b23c38dd56b2695c5af9b801ad14f795d138b1c (diff)
downloadrust-94669d9d47e3a594f4179a2aca9997fa1aeea7ad.tar.gz
rust-94669d9d47e3a594f4179a2aca9997fa1aeea7ad.zip
Add file and line metadata for closures
-rw-r--r--compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs12
-rw-r--r--tests/codegen/issue-98678.rs6
2 files changed, 15 insertions, 3 deletions
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
index 6b5f53e40bd..ebc452286b6 100644
--- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
+++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
@@ -1212,6 +1212,14 @@ fn build_closure_env_di_node<'ll, 'tcx>(
     let containing_scope = get_namespace_for_item(cx, def_id);
     let type_name = compute_debuginfo_type_name(cx.tcx, closure_env_type, false);
 
+    let closure_span = cx.tcx.def_span(def_id);
+    let (file_metadata, line_number) = if !closure_span.is_dummy() {
+        let loc = cx.lookup_debug_loc(closure_span.lo());
+        (file_metadata(cx, &loc.file), loc.line)
+    } else {
+        (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER)
+    };
+
     type_map::build_type_with_children(
         cx,
         type_map::stub(
@@ -1219,8 +1227,8 @@ fn build_closure_env_di_node<'ll, 'tcx>(
             Stub::Struct,
             unique_type_id,
             &type_name,
-            unknown_file_metadata(cx),
-            UNKNOWN_LINE_NUMBER,
+            file_metadata,
+            line_number,
             cx.size_and_align_of(closure_env_type),
             Some(containing_scope),
             DIFlags::FlagZero,
diff --git a/tests/codegen/issue-98678.rs b/tests/codegen/issue-98678.rs
index 72ccbddc59b..a6143117b9f 100644
--- a/tests/codegen/issue-98678.rs
+++ b/tests/codegen/issue-98678.rs
@@ -8,4 +8,8 @@
 // CHECK: !DICompositeType({{.*"}}MyType{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]],
 pub struct MyType;
 
-pub fn foo(_: MyType) {}
+pub fn foo(_: MyType) {
+    // CHECK: !DICompositeType({{.*"[{]}}closure_env#0{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]],
+    let closure = |x| x;
+    closure(0);
+}