Skip to content

Commit

Permalink
Rollup merge of #46512 - Havvy:doc-compile_fail, r=kennytm
Browse files Browse the repository at this point in the history
Give compile_error macro examples

I cannot get Rust to build at all with it complaining about GCC not being a valid C compiler or something, so letting TravisCI be my tester...

Fixes #46171
  • Loading branch information
frewsxcv authored Dec 6, 2017
2 parents 872c025 + aaaea2c commit bb239e2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/libcore/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,9 @@ mod builtin {

/// Unconditionally causes compilation to fail with the given error message when encountered.
///
/// For more information, see the [RFC].
/// For more information, see the documentation for [`std::compile_error!`].
///
/// [RFC]: https://github.com/rust-lang/rfcs/blob/master/text/1695-add-error-macro.md
/// [`std::compile_error!`]: ../std/macro.compile_error.html
#[stable(feature = "compile_error_macro", since = "1.20.0")]
#[macro_export]
#[cfg(dox)]
Expand Down
29 changes: 27 additions & 2 deletions src/libstd/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,34 @@ pub mod builtin {

/// Unconditionally causes compilation to fail with the given error message when encountered.
///
/// For more information, see the [RFC].
/// This macro should be used when a crate uses a conditional compilation strategy to provide
/// better error messages for errornous conditions.
///
/// [RFC]: https://github.com/rust-lang/rfcs/blob/master/text/1695-add-error-macro.md
/// # Examples
///
/// Two such examples are macros and `#[cfg]` environments.
///
/// Emit better compiler error if a macro is passed invalid values.
///
/// ```compile_fail
/// 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`"
/// ```
///
/// Emit compiler error if one of a number of features isn't available.
///
/// ```compile_fail
/// #[cfg(not(any(feature = "foo", feature = "bar")))]
/// compile_error!("Either feature \"foo\" or \"bar\" must be enabled for this crate.")
/// ```
#[stable(feature = "compile_error_macro", since = "1.20.0")]
#[macro_export]
macro_rules! compile_error { ($msg:expr) => ({ /* compiler built-in */ }) }
Expand Down

0 comments on commit bb239e2

Please sign in to comment.