Skip to content

Commit d232f4f

Browse files
committed
Auto merge of rust-lang#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 d423c81 + b897ad6 commit d232f4f

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
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,

src/tools/compiletest/src/runtest/ui.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl TestCx<'_> {
2424
let pm = self.pass_mode();
2525
let should_run = self.should_run(pm);
2626
let emit_metadata = self.should_emit_metadata(pm);
27-
let proc_res = self.compile_test(should_run, emit_metadata);
27+
let mut proc_res = self.compile_test(should_run, emit_metadata);
2828
self.check_if_test_should_compile(self.props.fail_mode, pm, &proc_res);
2929
if matches!(proc_res.truncated, Truncated::Yes)
3030
&& !self.props.dont_check_compiler_stdout
@@ -128,7 +128,7 @@ impl TestCx<'_> {
128128
}
129129

130130
let output_to_check = if let WillExecute::Yes = should_run {
131-
let proc_res = self.exec_compiled_test();
131+
proc_res = self.exec_compiled_test();
132132
let run_output_errors = if self.props.check_run_results {
133133
self.load_compare_outputs(&proc_res, TestOutput::Run, explicit)
134134
} else {

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)