I'm debugging a proc-macro and can't seem to follow the advice that rust is giving me. Here is the tail end of an error message:
= note: this error originates in the macro `polygraph_macro::schema` (in Nightly builds, run with -Z macro-backtrace for more info)
More info sounded great so I tried to follow the advice:
$ cargo +nightly test -Z macro-backtrace
error: unknown `-Z` flag specified: macro-backtrace
Am I doing something wrong, or is the error message itself in error?
I think you might need the following to avoid having
cargo-test process the argument:
cargo +nightly test -- -Z macro-backtrace
-Z macro-backtrace is not a flag for
cargo, nor for the integration tests binary, but for
RUSTFLAGS=-Zmacro-backtrace cargo …
is the best way to achieve this.
cargo command is something as simple as
check (or checking the unit tests), then you can run
cargo rustc -- -Zmacro-backtrace # --cfg test # (to check the unit tests)
This may be a bit faster to compiler since it won't change the
RUSTFLAGS used to compile the dependencies, thus not invalidating the cached compilation artifacts for them.
An unstable flag
Finally, note that
-Z macro-backtrace is an unstable feature.
If you are developing on a machine with no
nightly available, but want really hard to be able to debug these macros, then you can use the super unstable
RUSTC_BOOTSTRAP=1 to temporarily imbue your current
cargo toolchain with unstable capabilities. But do not do this on production nor CI, of course.
Bonus: other macro debugging tips
There are several kinds of errors one can have when writing macros:
Thanks so much! I did manage to debug my error.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.