Skip to content

Conversation

@nik-rev
Copy link

@nik-rev nik-rev commented Jan 16, 2026

When syn is used inside of a proc-macro, we now embed the [file:line:column] information to panic messages. This makes it a lot easier to debug proc macros.

Turning this error message:

error: proc-macro derive panicked
 --> src/lib.rs:1:10
  |
1 | #[derive(Trait)]
  |          ^^^^^^
  |
  = help: message: expected string literal

Into an error like this:

error: proc-macro derive panicked
 --> src/lib.rs:1:10
  |
1 | #[derive(Trait)]
  |          ^^^^^^
  |
  = help: message: [/tmp/macr/src/lib.rs:9:10] expected string literal

Closes #1957

@nik-rev nik-rev force-pushed the panic-location branch 5 times, most recently from 93528b1 to a09f783 Compare January 16, 2026 12:46
/// `panic!` macro that includes location information [file:line:column]
/// when inside of a proc-macro, because otherwise you don't get this information without
/// -Zmacro-backtrace, and enabling it is an extra step which makes debugging proc macros harder
macro_rules! panic_with_location {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you called this panic! instead (shorter), it would not compile on the msrv (1.68) because it would be ambiguous with a macro of the same name in the prelude. Later stable versions of Rust do not have this problem (e.g. 1.88)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve panic messages when in proc_macro

1 participant