Skip to content

Commit caf665e

Browse files
committed
Use the fn_span when emitting function calls for better debug info.
This especially improves the developer experience for long chains of function calls that span multiple lines, which is common with builder patterns, chains of iterator/future combinators, etc.
1 parent e42bbfe commit caf665e

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11811181
(_, Some(llfn)) => llfn,
11821182
_ => span_bug!(span, "no instance or llfn for call"),
11831183
};
1184+
self.set_debug_loc(bx, mir::SourceInfo { span: fn_span, ..source_info });
11841185
helper.do_call(
11851186
self,
11861187
bx,

tests/debuginfo/multiline-calls.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//@ compile-flags:-g
2+
//@ min-gdb-version: 16.0
3+
4+
// === GDB TESTS ===================================================================================
5+
6+
// gdb-command: run
7+
// gdb-check:[...]#break[...]
8+
// gdb-command: up
9+
// gdb-check:[...]zzz[...]
10+
11+
// === LLDB TESTS ==================================================================================
12+
13+
// lldb-command:run
14+
// lldb-check:[...]#break[...]
15+
// lldb-command: up
16+
// lldb-check:[...]zzz[...]
17+
18+
struct Foo;
19+
20+
impl Foo {
21+
fn bar(self) -> Foo {
22+
println!("bar");
23+
self
24+
}
25+
fn baz(self) -> Foo {
26+
println!("baz"); // #break
27+
self
28+
}
29+
}
30+
31+
fn main() {
32+
let f = Foo;
33+
f.bar() // aaa
34+
.baz(); // zzz
35+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ run-fail
2+
//@ compile-flags: -Cstrip=none -Cdebuginfo=line-tables-only -Copt-level=0
3+
//@ exec-env:RUST_BACKTRACE=1
4+
//@ regex-error-pattern: location-detail-unwrap-multiline\.rs:10(:10)?\n
5+
//@ needs-unwind
6+
7+
fn main() {
8+
let opt: Option<u32> = None;
9+
opt
10+
.unwrap();
11+
}

0 commit comments

Comments
 (0)