Skip to content

Collapse cross-crate macros in error backtraces #24188

@huonw

Description

@huonw

Errors inside macros currently get some serious and intimidating compiler-spew, e.g.

fn main() {
    println!("{}", () + 1);
}

gives

<anon>:2:20: 2:24 error: binary operation `+` cannot be applied to type `()` [E0369]
<anon>:2     println!("{}", () + 1);
                            ^~~~
note: in expansion of format_args!
<std macros>:2:25: 2:58 note: expansion site
<std macros>:1:1: 2:62 note: in expansion of print!
<std macros>:3:1: 3:54 note: expansion site
<std macros>:1:1: 3:58 note: in expansion of println!
<anon>:2:5: 2:28 note: expansion site

Most of the <std macros> lines are useless, as they're talking about implementation details of println! that the user has no control over (the macro is defined in another crate) and almost certainly doesn't care about. It would be much nicer if they were just collapsed to only print the outer call:

<anon>:2:20: 2:24 error: binary operation `+` cannot be applied to type `()` [E0369]
<anon>:2     println!("{}", () + 1);
                            ^~~~
note: in expansion of println!
<anon>:2:5: 2:28 note: expansion site

There's a few edge-cases I can think of:

  • someone working on their own macros and testing/using them in another crate may still be interested in the full backtrace. We could print the full trace if --verbose is passed.
  • macros that call other macros may result in interleaved cross-crate and intra-crate macros, presumably this is addressed by only collapsing contiguous sequences of cross-crate macros

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions