about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorHavvy <ryan.havvy@gmail.com>2017-12-04 21:55:24 -0800
committerHavvy <ryan.havvy@gmail.com>2017-12-04 21:55:24 -0800
commit44c343be45ef0ef68f456eeb8f5a07fa46eb599b (patch)
tree1cd61586ea50e6263fab727d4b86f2cfb3f8a251 /src/libstd
parenta4fa23a5bbbffc15c7ef6df5781478ddc7a45640 (diff)
downloadrust-44c343be45ef0ef68f456eeb8f5a07fa46eb599b.tar.gz
rust-44c343be45ef0ef68f456eeb8f5a07fa46eb599b.zip
Give compile_error macro examples
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/macros.rs21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs
index 7d62f94056f..85785270811 100644
--- a/src/libstd/macros.rs
+++ b/src/libstd/macros.rs
@@ -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 */ }) }