From caf665e692d74085e28a62ce4497eb7f02c5f37f Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Wed, 21 May 2025 16:21:00 -0700 Subject: [PATCH 1/2] 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. --- compiler/rustc_codegen_ssa/src/mir/block.rs | 1 + tests/debuginfo/multiline-calls.rs | 35 +++++++++++++++++++ .../location-detail-unwrap-multiline.rs | 11 ++++++ 3 files changed, 47 insertions(+) create mode 100644 tests/debuginfo/multiline-calls.rs create mode 100644 tests/ui/panics/location-detail-unwrap-multiline.rs diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 950f19a6f0f4e..600d6ff68015f 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -1181,6 +1181,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { (_, Some(llfn)) => llfn, _ => span_bug!(span, "no instance or llfn for call"), }; + self.set_debug_loc(bx, mir::SourceInfo { span: fn_span, ..source_info }); helper.do_call( self, bx, diff --git a/tests/debuginfo/multiline-calls.rs b/tests/debuginfo/multiline-calls.rs new file mode 100644 index 0000000000000..724ad29729fd2 --- /dev/null +++ b/tests/debuginfo/multiline-calls.rs @@ -0,0 +1,35 @@ +//@ compile-flags:-g +//@ min-gdb-version: 16.0 + +// === GDB TESTS =================================================================================== + +// gdb-command: run +// gdb-check:[...]#break[...] +// gdb-command: up +// gdb-check:[...]zzz[...] + +// === LLDB TESTS ================================================================================== + +// lldb-command:run +// lldb-check:[...]#break[...] +// lldb-command: up +// lldb-check:[...]zzz[...] + +struct Foo; + +impl Foo { + fn bar(self) -> Foo { + println!("bar"); + self + } + fn baz(self) -> Foo { + println!("baz"); // #break + self + } +} + +fn main() { + let f = Foo; + f.bar() // aaa + .baz(); // zzz +} diff --git a/tests/ui/panics/location-detail-unwrap-multiline.rs b/tests/ui/panics/location-detail-unwrap-multiline.rs new file mode 100644 index 0000000000000..afe15a579c41c --- /dev/null +++ b/tests/ui/panics/location-detail-unwrap-multiline.rs @@ -0,0 +1,11 @@ +//@ run-fail +//@ compile-flags: -Cstrip=none -Cdebuginfo=line-tables-only -Copt-level=0 +//@ exec-env:RUST_BACKTRACE=1 +//@ regex-error-pattern: location-detail-unwrap-multiline\.rs:10(:10)?\n +//@ needs-unwind + +fn main() { + let opt: Option = None; + opt + .unwrap(); +} From 9c234c03fd2d4121147a860ee3430f875fd6d2d2 Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Sat, 24 May 2025 06:22:49 -0700 Subject: [PATCH 2/2] Disable test on android because it doesn't have backtraces. --- tests/ui/panics/location-detail-unwrap-multiline.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/ui/panics/location-detail-unwrap-multiline.rs b/tests/ui/panics/location-detail-unwrap-multiline.rs index afe15a579c41c..56e1760d851bb 100644 --- a/tests/ui/panics/location-detail-unwrap-multiline.rs +++ b/tests/ui/panics/location-detail-unwrap-multiline.rs @@ -1,8 +1,9 @@ //@ run-fail //@ compile-flags: -Cstrip=none -Cdebuginfo=line-tables-only -Copt-level=0 //@ exec-env:RUST_BACKTRACE=1 -//@ regex-error-pattern: location-detail-unwrap-multiline\.rs:10(:10)?\n +//@ regex-error-pattern: location-detail-unwrap-multiline\.rs:11(:10)?\n //@ needs-unwind +//@ ignore-android FIXME #17520 fn main() { let opt: Option = None;