Skip to content

Commit 756b694

Browse files
authored
Rollup merge of rust-lang#51153 - ogham:panic-and-compile_error-docs, r=GuillaumeGomez
Link panic and compile_error docs This adds documentation links between `panic!()` and `compile_error!()` as per rust-lang#47275, which points out that they’re similar. It also adds a sentence to the `compile_error()` docs I thought could be added.
2 parents d72a67f + f85ddfb commit 756b694

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/libstd/macros.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@
3838
/// The multi-argument form of this macro panics with a string and has the
3939
/// [`format!`] syntax for building a string.
4040
///
41+
/// See also the macro [`compile_error!`], for raising errors during compilation.
42+
///
4143
/// [runwrap]: ../std/result/enum.Result.html#method.unwrap
4244
/// [`Option`]: ../std/option/enum.Option.html#method.unwrap
4345
/// [`Result`]: ../std/result/enum.Result.html
4446
/// [`format!`]: ../std/macro.format.html
47+
/// [`compile_error!`]: ../std/macro.compile_error.html
4548
/// [book]: ../book/second-edition/ch09-01-unrecoverable-errors-with-panic.html
4649
///
4750
/// # Current implementation
@@ -305,13 +308,16 @@ pub mod builtin {
305308
/// Unconditionally causes compilation to fail with the given error message when encountered.
306309
///
307310
/// This macro should be used when a crate uses a conditional compilation strategy to provide
308-
/// better error messages for erroneous conditions.
311+
/// better error messages for erroneous conditions. It's the compiler-level form of [`panic!`],
312+
/// which emits an error at *runtime*, rather than during compilation.
309313
///
310314
/// # Examples
311315
///
312316
/// Two such examples are macros and `#[cfg]` environments.
313317
///
314-
/// Emit better compiler error if a macro is passed invalid values.
318+
/// Emit better compiler error if a macro is passed invalid values. Without the final branch,
319+
/// the compiler would still emit an error, but the error's message would not mention the two
320+
/// valid values.
315321
///
316322
/// ```compile_fail
317323
/// macro_rules! give_me_foo_or_bar {
@@ -332,6 +338,8 @@ pub mod builtin {
332338
/// #[cfg(not(any(feature = "foo", feature = "bar")))]
333339
/// compile_error!("Either feature \"foo\" or \"bar\" must be enabled for this crate.")
334340
/// ```
341+
///
342+
/// [`panic!`]: ../std/macro.panic.html
335343
#[stable(feature = "compile_error_macro", since = "1.20.0")]
336344
#[macro_export]
337345
macro_rules! compile_error {

0 commit comments

Comments
 (0)