macro

Emit helpful compile-time diagnostics

When input violates the grammar, return tokens that report an error during compilation. The fixture uses Literal::string to encode the diagnostic text safely. The valid call succeeds; the negative fixture intentionally supplies unexpected tokens. Example: two-crate workspace; see fixtures/proc-macro-workspace/consumer/src/bin/diagnostics.rs. This caller is not a standalone rustc program. Expected stdout (not executed): 'true\n' Common mistake: Panicking with unwrap on user input instead of explaining the required grammar.

Formal Syntax & Structure

rust syntaxrust
compile_error!("message");

Working Example

Example Snippetrust
use teaching_macros::validated;fn main() { println!("{}", validated!()); }
Rust Reference