How to run cargo expand on a single macro?


I'm new to Rust and I'm fascinated by the macro system. I'm following the proc-macro-workshop from dtolnay (

My problem is I'm trying to use cargo expand to expand the macro in one of the specific tests but I'm struggling with the exact syntax. I understand the general format to do a single expansion is;

$ cargo expand --test test_something

but I'm not sure what to replace "test_something" with.

any help gratefully received.



The way I worked on the workshop was to copy paste the test file (eg debug/tests/01-parse) you are working on into the that's in the root, then you just run cargo expand no args needed. The other option is to rename the folder tests to examples then you can run cargo expand --example 01-parse this would run the first file in the debug workshop. The downside of this is you need to rename it back every time you want to run an actual test.

HI Devin.

thanks for the reply and tip. I couldn't get the copy/paste to to work (I got an error

error: extra arguments to rustc can only be passed to one target, consider filtering
the package by passing, e.g., --lib or --bin NAME to specify a single target)

but renaming tests to examples did work so I'll stick with that for now.

Once again, thanks for your help.



1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.