Skip to content

Commit 850ea99

Browse files
committed
fix: match on uninhabited types at compile time
uninhabited types should be dealt with at compile time, not through the runtime panic that `unreachable!` throws since rust 1.82, Rust has better ergonomics for matching on uninhabited enum variants, which makes this easier for owned types (rust-lang/rust#122792)
1 parent 1a703d6 commit 850ea99

File tree

4 files changed

+7
-11
lines changed

4 files changed

+7
-11
lines changed

openraft/src/error.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ where C: RaftTypeConfig
321321
RPCError::Unreachable(e) => RPCError::Unreachable(e),
322322
RPCError::PayloadTooLarge(e) => RPCError::PayloadTooLarge(e),
323323
RPCError::Network(e) => RPCError::Network(e),
324-
RPCError::RemoteError(_infallible) => unreachable!(),
325324
}
326325
}
327326
}

openraft/src/error/into_ok.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ where E: Into<Infallible>
1111
fn into_ok(self) -> T {
1212
match self {
1313
Ok(t) => t,
14-
Err(_) => unreachable!(),
14+
Err(e) => {
15+
// NOTE: `allow` required because of buggy reachability detection by rust compiler
16+
#[allow(unreachable_code)]
17+
match e.into() {}
18+
}
1519
}
1620
}
1721
}

openraft/src/error/streaming_error.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,13 @@ impl<C: RaftTypeConfig> From<StreamingError<C>> for ReplicationError<C> {
4848

4949
impl<C: RaftTypeConfig> From<RPCError<C>> for StreamingError<C> {
5050
fn from(value: RPCError<C>) -> Self {
51-
#[allow(unreachable_patterns)]
5251
match value {
5352
RPCError::Timeout(e) => StreamingError::Timeout(e),
5453
RPCError::Unreachable(e) => StreamingError::Unreachable(e),
5554
RPCError::PayloadTooLarge(_e) => {
5655
unreachable!("PayloadTooLarge should not be converted to StreamingError")
5756
}
5857
RPCError::Network(e) => StreamingError::Network(e),
59-
RPCError::RemoteError(_e) => {
60-
unreachable!("Infallible error should not be produced at all")
61-
}
6258
}
6359
}
6460
}

rt-monoio/src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,8 @@ impl AsyncRuntime for MonoioRuntime {
7474
}
7575

7676
#[inline]
77-
fn is_panic(_join_error: &Self::JoinError) -> bool {
78-
// Given that joining a task will never fail, i.e., `Self::JoinError`
79-
// will never be constructed, and it is impossible to construct an
80-
// enum like `Infallible`, this function could never be invoked.
81-
unreachable!("unreachable since argument `join_error` could never be constructed")
77+
fn is_panic(join_error: &Self::JoinError) -> bool {
78+
match *join_error {}
8279
}
8380

8481
#[inline]

0 commit comments

Comments
 (0)