Rust 2030 Christmas list: Macro sources in compiler diagnostics

Discussion on r/rust

AFAIK, the point of -Zmacro-backtrace is precisely this, at least for macro_rules! macros. Indeed, it can, for instance, yield:

error[E0412]: cannot find type `i33` in this scope
 --> /tmp/tmp.FfD3KppAr7/dep/src/lib.rs:6:21
  |
2 | /     macro_rules! create_function {(
3 | |         $name:ident $(,)?
4 | |     ) => (
5 | |         fn foobar() {
6 | |             let x: i33 = 0;
  | |                    ^^^ help: a builtin type with a similar name exists: `i32`
7 | |         }
8 | |     )}
  | |______- in this expansion of `::dep::create_function!`
  |
 ::: src/lib.rs:1:5
  |
1 |       ::dep::create_function!(foobar);
  |       ------------------------------- in this macro invocation

For more information about this error, try `rustc --explain E0412`.
error: could not compile `example` due to previous error

Sadly it doesn't work for procmacro-generated code, so I'd technically amend that wishlist for that exactly :slightly_smiling_face:

  • something like highlighting "virtual source code", the one emitted by the proc macro, formatted by rustc (or rustfmt or whatnot), with an intro saying "from the code emitted by that proc-macro invocation : let x : i33 …
4 Likes

I was hoping someone was going to tell me something like that that I didn't know about ^^

I thought macro backtraces only covered which macros were used (at least that's what they seem to do with proc macros), not the expanded code.

1 Like