Skip to content

Commit bfb9ee1

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 bfb9ee1

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//@ compile-flags:-g
2+
3+
// === GDB TESTS ===================================================================================
4+
5+
// gdb-command: run
6+
// gdb-check:[...]#break[...]
7+
// gdb-command: up
8+
// gdb-check:[...]zzz[...]
9+
10+
// === LLDB TESTS ==================================================================================
11+
12+
// lldb-command:run
13+
// lldb-check:[...]#break[...]
14+
// lldb-command: up
15+
// lldb-check:[...]zzz[...]
16+
17+
struct Foo;
18+
19+
impl Foo {
20+
fn bar(self) -> Foo {
21+
println!("bar");
22+
self
23+
}
24+
fn baz(self) -> Foo {
25+
println!("baz"); // #break
26+
self
27+
}
28+
}
29+
30+
fn main() {
31+
let f = Foo;
32+
f.bar() // aaa
33+
.baz(); // zzz
34+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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:9:10\n
5+
6+
fn main() {
7+
let opt: Option<u32> = None;
8+
opt
9+
.unwrap();
10+
}

0 commit comments

Comments
 (0)