rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.28k stars 12.72k forks source link

Redundancy in `trace_macro` output #42223

Open jorendorff opened 7 years ago

jorendorff commented 7 years ago

(filed per https://github.com/rust-lang/rust/pull/42103#issuecomment-303183649 )

trace_macro output now contains both "before" and "after" text.

But often a macro-call expands to another macro-call. In that case, we get redundant lines from trace_macro:

 note: trace_macro
   --> trace-macro.rs:14:5
   |
14 |     println!("Hello, World!");
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   |
   = note: expanding `println! { "Hello, World!" }`
   = note: to `print ! ( concat ! ( "Hello, World!" , "\n" ) )`
   = note: expanding `print! { concat ! ( "Hello, World!" , "\n" ) }`
   = note: to `$crate :: io :: _print ( format_args ! ( concat ! ( "Hello, World!" , "\n" ) )
           )`

The second "expanding" note is basically the same as the previous line. We could eliminate that.

Note that it's also common for a macro-call to expand to code that merely contains another macro-call somewhere, and in that case we probably shouldn't elide anything.

fmease commented 2 months ago

Since println and panic now lead to only one expansion, here's a new MCVE:

macro_rules! start { () => { end!() }; }
macro_rules! end { () => { () }; }

fn main() { start!(); }

With -Ztrace-macros:

note: trace_macro
 --> hw.rs:4:13
  |
4 | fn main() { start!(); }
  |             ^^^^^^^^
  |
  = note: expanding `start! {  }`
  = note: to `end! ()`
  = note: expanding `end! {  }`
  = note: to `()`