#macro #plugin

nightly compile_msg

A plugin for emitting errors, warnings and notes to the developer at compile time

6 releases

Uses old Rust 2015

0.1.5 Feb 9, 2015
0.1.4 Feb 7, 2015
0.1.3 Jan 9, 2015
0.1.1 Nov 14, 2014

#281 in Procedural macros

Download history 1/week @ 2021-10-04 1/week @ 2021-10-11 1/week @ 2021-10-18 24/week @ 2021-10-25 34/week @ 2021-11-01 48/week @ 2021-11-08 45/week @ 2021-11-15 51/week @ 2021-11-22 48/week @ 2021-11-29 51/week @ 2021-12-06 42/week @ 2021-12-13 42/week @ 2021-12-20 42/week @ 2021-12-27 43/week @ 2022-01-03 59/week @ 2022-01-10 38/week @ 2022-01-17

188 downloads per month


98 lines


Build Status

A syntax extension for emitting messages at compile time, via the compiler, similar to #warning and #error in the C preprocessor. Four macros are provided (in order of increasing severity):

  • compile_note: tell the user a tidbit of information without implying it is a problem,
  • compile_warning: tell the user that something could go wrong,
  • compile_error: tell the user about some error, compilation will not stop immediately, but will halt before any compiler passes after macro expansion.
  • compile_fatal: tell the user about a catastrophic error and immediately halt compilation. compile_error is strongly preferred as it allows further errors and warnings to be picked up in a single pass.

The macros can be placed as an item (expanding to nothing), and as an expression (expanding to a literal unit, i.e. ()). They are best used in conditionally compiled items, e.g. if a certain operating system is entirely unsupported, one can use compile_error! with an appropriate #[cfg] attribute.


Ensure your Cargo.toml contains:

compile_msg = "0"

and then load the syntax in the normal manner:


#[plugin] extern crate compile_msg;

#[cfg(target_os = "hal")]
compile_error!("I'm sorry, Dave, I'm afraid I can't do that.");

fn main() {
    compile_note!("please be careful"); // note: please be careful

    compile_warning!("take more care"); // warning: take more care

    compile_error!("things are breaking"); // error: things are breaking

    compile_fatal!("catastrophic failure!"); // error: catastrophic failure
    // (compilation stops here)

    compile_warning!("not emitted");

(If that compiled, it would be equivalent to fn main() {} at runtime.)

No runtime deps