Skip to content

Commit a794f94

Browse files
committed
Auto merge of #141372 - khuey:ir_call_dbg_loc, r=<try>
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. try-job: armhf-gnu try-job: test-various try-job: x86_64-msvc-1 r? `@jieyouxu`
2 parents 1d67944 + 4a65590 commit a794f94

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-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: 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)