File tree 2 files changed +29
-4
lines changed
2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -596,9 +596,9 @@ mod builtin {
596
596
597
597
/// Unconditionally causes compilation to fail with the given error message when encountered.
598
598
///
599
- /// For more information, see the [RFC ].
599
+ /// For more information, see the documentation for [`std::compile_error!` ].
600
600
///
601
- /// [RFC ]: https://github.com/rust-lang/rfcs/blob/master/text/1695-add-error- macro.md
601
+ /// [`std::compile_error!` ]: ../std/ macro.compile_error.html
602
602
#[ stable( feature = "compile_error_macro" , since = "1.20.0" ) ]
603
603
#[ macro_export]
604
604
#[ cfg( dox) ]
Original file line number Diff line number Diff line change @@ -282,9 +282,34 @@ pub mod builtin {
282
282
283
283
/// Unconditionally causes compilation to fail with the given error message when encountered.
284
284
///
285
- /// For more information, see the [RFC].
285
+ /// This macro should be used when a crate uses a conditional compilation strategy to provide
286
+ /// better error messages for errornous conditions.
286
287
///
287
- /// [RFC]: https://github.com/rust-lang/rfcs/blob/master/text/1695-add-error-macro.md
288
+ /// # Examples
289
+ ///
290
+ /// Two such examples are macros and `#[cfg]` environments.
291
+ ///
292
+ /// Emit better compiler error if a macro is passed invalid values.
293
+ ///
294
+ /// ```compile_fail
295
+ /// macro_rules! give_me_foo_or_bar {
296
+ /// (foo) => {};
297
+ /// (bar) => {};
298
+ /// ($x:ident) => {
299
+ /// compile_error!("This macro only accepts `foo` or `bar`");
300
+ /// }
301
+ /// }
302
+ ///
303
+ /// give_me_foo_or_bar!(neither);
304
+ /// // ^ will fail at compile time with message "This macro only accepts `foo` or `bar`"
305
+ /// ```
306
+ ///
307
+ /// Emit compiler error if one of a number of features isn't available.
308
+ ///
309
+ /// ```compile_fail
310
+ /// #[cfg(not(any(feature = "foo", feature = "bar")))]
311
+ /// compile_error!("Either feature \"foo\" or \"bar\" must be enabled for this crate.")
312
+ /// ```
288
313
#[ stable( feature = "compile_error_macro" , since = "1.20.0" ) ]
289
314
#[ macro_export]
290
315
macro_rules! compile_error { ( $msg: expr) => ( { /* compiler built-in */ } ) }
You can’t perform that action at this time.
0 commit comments