Give compile_error macro examples
This commit is contained in:
parent
a4fa23a5bb
commit
44c343be45
2 changed files with 21 additions and 4 deletions
|
@ -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)]
|
||||
|
|
|
@ -282,9 +282,26 @@ 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.
|
||||
///
|
||||
/// ```
|
||||
/// macro_rules! give_me_foo_or_bar {
|
||||
/// (foo) => {};
|
||||
/// (bar) => {};
|
||||
/// ($x:ident) => {
|
||||
/// compile_error!("This macro only accepts `foo` or `bar`");
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// ```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 */ }) }
|
||||
|
|
Loading…
Reference in a new issue