]> git.lizzy.rs Git - rust.git/commitdiff
Document `unreachable!()` custom panic message
authorEd Morley <501702+edmorley@users.noreply.github.com>
Thu, 11 Nov 2021 13:41:21 +0000 (13:41 +0000)
committerEd Morley <501702+edmorley@users.noreply.github.com>
Thu, 11 Nov 2021 13:41:21 +0000 (13:41 +0000)
The `unreachable!` docs previously did not mention that there was a second
form, `unreachable!("message")` that could be used to specify a custom panic
message,

The docs now mention this in the same style as currently used for `unimplemented!`:
https://doc.rust-lang.org/core/macro.unimplemented.html#panics

library/core/src/macros/mod.rs

index 5b3e988caa506cc61e8c74f069e30e9ca3711649..993ae72322966388b96342c7038256d3d509576a 100644 (file)
@@ -554,7 +554,10 @@ macro_rules! writeln {
 ///
 /// # Panics
 ///
-/// This will always [`panic!`].
+/// This will always [`panic!`] because `unreachable!` is just a shorthand for `panic!` with a
+/// fixed, specific message.
+///
+/// Like `panic!`, this macro has a second form for displaying custom values.
 ///
 /// # Examples
 ///
@@ -581,7 +584,7 @@ macro_rules! writeln {
 ///         if 3*i < i { panic!("u32 overflow"); }
 ///         if x < 3*i { return i-1; }
 ///     }
-///     unreachable!();
+///     unreachable!("The loop should always return");
 /// }
 /// ```
 #[macro_export]