GithubHelp home page GithubHelp logo

steveklabnik / compile_msg Goto Github PK

View Code? Open in Web Editor NEW

This project forked from huonw/compile_msg

0.0 2.0 0.0 133 KB

Compile-time user-defined diagnostics

License: Apache License 2.0

Rust 100.00%

compile_msg's Introduction

compile_msg

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.

Usage

Ensure your Cargo.toml contains

[dependencies.compile_msg]
git = "https://github.com/huonw/compile_msg"

and then load the syntax in the normal manner:

#![feature(phase)]

#[phase(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.)

compile_msg's People

Contributors

huonw avatar steveklabnik avatar tomaka avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.