Skip to content

Commit 5b3cb68

Browse files
authored
Rollup merge of rust-lang#90798 - edmorley:doc-unreachable-custom-message, r=dtolnay
Document `unreachable!` custom panic message 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 feature in the same wording as currently used for `unimplemented!`: https://doc.rust-lang.org/core/macro.unimplemented.html#panics
2 parents f522f26 + b41b2e5 commit 5b3cb68

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

library/core/src/macros/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,10 @@ macro_rules! writeln {
554554
///
555555
/// # Panics
556556
///
557-
/// This will always [`panic!`].
557+
/// This will always [`panic!`] because `unreachable!` is just a shorthand for `panic!` with a
558+
/// fixed, specific message.
559+
///
560+
/// Like `panic!`, this macro has a second form for displaying custom values.
558561
///
559562
/// # Examples
560563
///
@@ -581,7 +584,7 @@ macro_rules! writeln {
581584
/// if 3*i < i { panic!("u32 overflow"); }
582585
/// if x < 3*i { return i-1; }
583586
/// }
584-
/// unreachable!();
587+
/// unreachable!("The loop should always return");
585588
/// }
586589
/// ```
587590
#[macro_export]

0 commit comments

Comments
 (0)