debuginfo: Stabilize -Z debug-macros, -Z collapse-macro-debuginfo and #[collapse_debuginfo] by petrochenkov · Pull Request #120845 · rust-lang/rust (original) (raw)

Stabilization Report

Before this PR all spans coming from macro definitions were by default collapsed to a single span representing the macro's call site when generating debuginfo.
The option -Z debug-macros changed that behavior and preserved all spans in debuginfo without collapsing.

With this PR the -Z debug-macros option is removed and the defaults are partially swapped.
By default spans are preserved without collapsing, giving more detailed information during debugging, but only for macros coming from the current crate.
For macros from other crates the spans are still collapsed to a single call site span, this way we don't jump to code of println! and other macros from the standard library.

Attributes #[collapse_debuginfo(yes/no/external)] and command line options -C collapse-macro-debuginfo=yes/no/external (replace -Z debug-macros) provide more fine-grained control over collapsing debuginfo spans to call site, when the defaults are insufficient.

History

#41743 identified the problem with detailed debuginfo spans for macros not being available on stable channel.

rust-lang/rfcs#2117 and rust-lang/compiler-team#386 provided the solution for undesirable jumping to sources of println! and friends when detailed spans are enabled.
#99556 implemented that solution in July 2022.

#118903 added detailed tests for the feature and fixed some issues with nested macro calls in December 2023.
#119828 added some more fine grained options to the #[collapse_debuginfo] attribute, and added a command line flag -C collapse-macro-debuginfo for overriding both defaults and attributes as well in January 2024.

Design

rust-lang/compiler-team#386 gives motivation for not collapsing macros in debuginfo in general, but collapsing some macros in particular.

Comments in #100758 (comment) and below describe some possible debugging scenarios, and make a choice for the default collapsing behavior implemented in this PR.

Tests

Documentation

src/doc/rustc/src/codegen-options/index.md in this PR and rust-lang/reference#1468 in the reference.