#compilation #guard #fail #features #flags #attributes #condition

macro compilation-guard

Force compilation to fail when certain condition is met

2 releases

0.1.1 Jul 3, 2023
0.1.0 Jul 3, 2023

#682 in Procedural macros

21 downloads per month

Apache-2.0

6KB

Compilation Guard

Say, you have a feature that is behind several different feature guard, and you want to make sure that your user knows whne it has to compile.

This crate can help you with that.

e.g.

#![allow(unused_imports, dead_code)]

use compilation_guard::compilation_guard;
#[cfg_attr(all(unstable, feature = "enable-macro"), derive(VeryExpensiveMacro))]
#[cfg_attr(all(not(unstable), feature = "enable-macro"), compilation_guard("lol"))]
struct A;

fn main() {

}

If you don't enable the unstable flag, you get this.

error: custom attribute panicked
 --> src/main.rs:5:58
  |
5 | #[cfg_attr(all(not(unstable), feature = "enable-macro"), compilation_guard("lol"))]
  |                                                          ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: message: Compilation guard was triggered!
          lol

No runtime deps