Procedural macro / derive trait behave differently based on whether type implements trait

I suspect the answer is probably no, but want to check anyway in case there is some blackmagic I am unaware of.

I have my own procedural macro which does #[derive(FooBar)].

As part of macro, we march across all the named fields / unnamed fields of a struct / enum, and do different things with the (name_i, Type_i) pair.

Now, I want to have the procedural macro do different things based on whether Type_i implements some trait Animal_T.

I.e. if Type_i implements Animal_T, output one code block; otherwise output another code block.

I suspect this is impossible since procedural macros operate on the syntactical level, before type checking. However, I wanted to ask anyway in case there is some blackmagic trick.

There's one trick: case-studies/README.md at master · dtolnay/case-studies · GitHub

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.