Skip to content

Commit

Permalink
refactor: allow unreachable pattern in macro getsockopt_impl (#2470)
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveLauC authored Aug 11, 2024
1 parent 1e259be commit c5a4299
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/sys/socket/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ macro_rules! getsockopt_impl {
Errno::result(res)?;

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

0 comments on commit c5a4299

Please sign in to comment.