Skip to content

Commit c5a4299

Browse files
authored
refactor: allow unreachable pattern in macro getsockopt_impl (#2470)
1 parent 1e259be commit c5a4299

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/sys/socket/sockopt.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ macro_rules! getsockopt_impl {
108108
Errno::result(res)?;
109109

110110
match <$ty>::try_from(getter.assume_init()) {
111+
// In most `getsockopt_impl!` implementations, `assume_init()`
112+
// returns `$ty`, so calling `$ty`::try_from($ty) will always
113+
// succeed. which makes the following `Err(_)` branch
114+
// unreachable.
115+
//
116+
// However, there is indeed one exception, `sockopt::SockType`,
117+
// `assume_init()` returns an `i32`, but `$ty` is `super::SockType`,
118+
// this exception necessitates the use of that `try_from()`,
119+
// and we have to allow the unreachable pattern wraning.
120+
//
121+
// For the reason why we are using `i32` as the underlying
122+
// buffer type for this socket option, see issue:
123+
// https://github.com/nix-rust/nix/issues/1819
124+
#[allow(unreachable_patterns)]
111125
Err(_) => Err(Errno::EINVAL),
112126
Ok(r) => Ok(r),
113127
}

0 commit comments

Comments
 (0)