Skip to content

Commit cd87530

Browse files
committed
Make unreachable implementation type-safe
1 parent a570cc4 commit cd87530

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/std/src/never.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ pub enum Never {}
1212
// The Debug implementation is needed to allow the use of `Result::unwrap`.
1313
impl core::fmt::Debug for Never {
1414
fn fmt(&self, _f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
15-
// This is unreachable because no instance of Never can exist
16-
unreachable!()
15+
// Unreachable because no instance of Never can exist
16+
match *self {}
1717
}
1818
}
1919

2020
// The Display implementation is needed to fulfill the ToString requirement of
2121
// entry point errors: `Result<IbcReceiveResponse<C>, E>` with `E: ToString`.
2222
impl core::fmt::Display for Never {
2323
fn fmt(&self, _f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
24-
// This is unreachable because no instance of Never can exist
25-
unreachable!()
24+
// Unreachable because no instance of Never can exist
25+
match *self {}
2626
}
2727
}

0 commit comments

Comments
 (0)