Skip to main content

collapse_debuginfo

Attribute collapse_debuginfo 

Source
Expand description

Controls whether the code location from a macro definition collapses on the call site in debug info.

#[collapse_debuginfo(yes)]
macro_rules! say_hello {
    () => {
        println!("hello!");
    }
}

fn main() {
    say_hello!();
}

When using a debugger, when you step on say_hello!() macro, only the macro invocation is visible in debug info rather than the expanded code.

#[collapse_debuginfo] accepts three options:

  • #[collapse_debuginfo(yes)] — Collapses code location in debug info.
  • #[collapse_debuginfo(no)] — Does not collapse code location in debug info.
  • #[collapse_debuginfo(external)] — Collapses code location if the macro comes from a different crate in debug info.

#[collapse_debuginfo] is only applicable to macro_rules! and only once.

Default behavior:

  • external is the default for user-defined macros.
  • yes is the default for built-in macros.

Note: you can use -C collapse-macro-debuginfo command line option to override both the default behavior and values of any #[collapse_debuginfo] attributes.

For more information, see the Reference on the collapse_debuginfo attribute.