diff options
| author | Kyle Huey <khuey@kylehuey.com> | 2025-05-21 16:21:00 -0700 |
|---|---|---|
| committer | Kyle Huey <khuey@kylehuey.com> | 2025-05-22 14:06:24 -0700 |
| commit | caf665e692d74085e28a62ce4497eb7f02c5f37f (patch) | |
| tree | a22122986bd9197032731cad06c2f575e7f77420 | |
| parent | e42bbfe1f7c26f8760a99c4b1f27d33aba1040bb (diff) | |
| download | rust-caf665e692d74085e28a62ce4497eb7f02c5f37f.tar.gz rust-caf665e692d74085e28a62ce4497eb7f02c5f37f.zip | |
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.
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/mir/block.rs | 1 | ||||
| -rw-r--r-- | tests/debuginfo/multiline-calls.rs | 35 | ||||
| -rw-r--r-- | tests/ui/panics/location-detail-unwrap-multiline.rs | 11 |
3 files changed, 47 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 950f19a6f0f..600d6ff6801 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 00000000000..724ad29729f --- /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 00000000000..afe15a579c4 --- /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<u32> = None; + opt + .unwrap(); +} |
