How do I debug `derive` macro expansion

I've been searching for a while, but I can't seem to find anything that would tell me how to see why my derive statement is not working. What is the magic incantation to show me what code is being generated?

I'm working with rocket.rs and trying to #[derive(Serialize)] a custom struct. but it's telling me that I haven't satisfied the trait?

The following code:

Produces the following error: (sorry about the module name, it came out of my frustration with the derive macro!)

❯ cargo build
Compiling derive-hate v0.1.0 (file:///Users/scull7/code/Rust/derive-hate)
error[E0277]: the trait bound Foo: serde::ser::Serialize is not satisfied
--> src/main.rs:35:1
|
35 | #[post("/foo", data = "")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait serde::ser::Serialize is not implemented for Foo
|
= note: required because of the requirements on the impl of rocket::response::Responder<'_> for rocket_contrib::JSON<Foo>
= note: required by rocket::handler::<impl rocket::Outcome<rocket::Response<'r>, rocket::http::Status, rocket::Data>>::of

error: aborting due to previous error

error: Could not compile derive-hate.

To learn more, run the command again with --verbose.

So I have learned from the very helpful guys (Sergio and mk) on the #rocket IRC channel that this issue is caused by incompatible versions of serde and rocket. Currently rocket requires serde 0.8.* to work. I hope that this helps someone.

https://github.com/SergioBenitez/Rocket/issues/154

My question about debugging this issue is still unanswered though? How can one figure out this incompatibility from the Rust tool set? If it is not possible, then what needs to change to make it possible?

cargo-tree has --duplicates (-d) option that is useful for detecting a jumble of some different versions of the same crate.
For probing generated code for macro things, you can use cargo-expand.

4 Likes

Thank you the cargo-expand module is awesome!

1 Like