cargo check compiles a Rust project for error checking without producing a final executable. With procedural macros, it checks the macro library and the generated code only when a consuming application uses the macro. section 3.2
Checking generated code
A typo such as TokenStrea in the macro library is caught by cargo check. However, invalid tokens generated by quote!, such as `fn this should not work () {}`, can pass there; running cargo check in the outer application reports the syntax error at the derive macro invocation. section 3.2
Use cargo check diagnostically by separating these cases:
- Check the procedural macro library for errors in its own Rust code. section 3.2
- Check a consuming application to validate the Rust code emitted by the macro. section 3.2
- Combine cargo check with cargo expand when an attribute macro produces a confusing type error, such as a missing return in Err(...). section 7.8.2
#[proc_macro_derive(Hello)]
pub fn hello(item: TokenStream) -> TokenStream {
let add_hello_world = quote! {
fn this should not work () {}
};
add_hello_world.into()
}
Inspect the intentionally invalid generated function to see why checking the consuming application matters. section 3.2

