Skip to content

new trace_macros doesn't work if there's an error during expansion #43493

Closed
@durka

Description

@durka

The new trace_macros has much better output, but it has regressed in functionality! The old trace_macros could be used to debug macro expansion. Example using rustc 1.6.0:

$ cargo +1.6.0 script -u trace_macros -e 'trace_macros!(true); macro_rules! m { (x $($t:tt)*) => { m!() } } m!(foo);'
   Compiling expr v0.1.0 (file:///Users/alex/.cargo/.cargo/script-cache/expr-634e13f197b6cae5)
m! { foo }
.cargo/.cargo/script-cache/expr-634e13f197b6cae5/expr.rs:11:81: 11:84 error: no rules expected the token `foo`
.cargo/.cargo/script-cache/expr-634e13f197b6cae5/expr.rs:11     match {trace_macros!(true); macro_rules! m { (x $($t:tt)*) => { m!() } } m!(foo);} {
                                                                                                                                            ^~~
Could not compile `expr`.

OK, you can see m!(foo) was invoked, and then it didn't match so there's an error.

Now with current rustc (all channels):

$ cargo script -u trace_macros -e 'trace_macros!(true); macro_rules! m { (x $($t:tt)*) => { m!() } } m!(foo);'
   Compiling expr v0.1.0 (file:///Users/alex/.cargo/.cargo/script-cache/expr-634e13f197b6cae5)
error: no rules expected the token `foo`
  --> .cargo/.cargo/script-cache/expr-634e13f197b6cae5/expr.rs:11:81
   |
11 |     match {trace_macros!(true); macro_rules! m { (x $($t:tt)*) => { m!() } } m!(foo);} {
   |                                                                                 ^^^

error: Could not compile `expr`.

You no longer get to see the chain of expansions leading up to the error. This typically occurs much deeper in a string of recursive macros, making debugging much harder.

cc #41520 @estebank @nikomatsakis

Metadata

Metadata

Assignees

Labels

A-syntaxextArea: Syntax extensionsC-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions