std::compile_error - Rust
Description: API documentation for the Rust `compile_error` macro in crate `std`.
Keywords: rust, rustlang, rust-lang, compile_error

# Macro std::compile_error 1.20.0 [−] [src]

    macro_rules! compile_error {
        ($msg:expr) => { ... };
    }

Unconditionally causes compilation to fail with the given error message when encountered.

This macro should be used when a crate uses a conditional compilation strategy to provide better error messages for errornous conditions.

# Examples

Two such examples are macros and `#[cfg]` environments.

Emit better compiler error if a macro is passed invalid values.

ⓘThis example deliberately fails to compile

    macro_rules! give_me_foo_or_bar {
        (foo) => {};
        (bar) => {};
        ($x:ident) => {
            compile_error!("This macro only accepts `foo` or `bar`");
        }
    }

    give_me_foo_or_bar!(neither);
    // ^ will fail at compile time with message "This macro only accepts `foo` or `bar`"Run

Emit compiler error if one of a number of features isn't available.

ⓘThis example deliberately fails to compile

    #[cfg(not(any(feature = "foo", feature = "bar")))]
    compile_error!("Either feature \"foo\" or \"bar\" must be enabled for this crate.")Run

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
↑
  Move up in search results
↓
  Move down in search results
↹
  Switch tab
⏎
  Go to active search result
+ / -
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)