Reputation: 6447
The Rust book mentions that macros can be expanded with the command rustc --pretty expanded
. I'd like to use this for testing some macros I wrote in a crate, by expanding an example file with a command like
rustc -Z unstable-options --pretty expanded examples/macro_test.rs
macro_test.rs
would have code that looks like this:
#[macro_use] extern crate macro_crate;
use macro_crate::macros::*;
macro_foo! { foo }
fn main() {}
However, that results in error 0463, which is that rustc
doesn't know anything about the crate environment it's in:
error[E0463]: can't find crate for `macro_crate`
--> examples/macro_test.rs:1:1
|
1 | extern crate macro_test;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
What's the recommended way to work with this? The cargo
help doesn't have anything directly related as far as I can tell.
Upvotes: 1
Views: 110
Reputation: 65782
Cargo has a rustc
subcommand for invoking rustc
with additional arguments.
$ cargo rustc --example macro_test -- -Z unstable-options --pretty expanded
You can also add --verbose
before the --
to get Cargo to print the full rustc
command line (among other things).
Upvotes: 3