Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: allow unreachable pattern in macro getsockopt_impl #2470

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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