Skip to content
Open
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
16 changes: 16 additions & 0 deletions src/sockaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ impl SockAddrStorage {
/// # Safety
///
/// The type `T` must be one of the `sockaddr_*` types defined by this platform.
///
/// # Examples
/// ```
/// # #[allow(dead_code)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure dead-code warnings are disabled by default in documentation tests.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Darksonn, I'm running cargo test --all-features locally and seeing this (without the allow(dead_code))

---- src/sockaddr.rs - sockaddr::SockAddrStorage::view_as (line 54) stdout ----
error: function `from_sockaddr_storage` is never used
 --> src/sockaddr.rs:60:4
  |
9 | fn from_sockaddr_storage(recv_address: &sockaddr_storage) -> SockAddr {
  |    ^^^^^^^^^^^^^^^^^^^^^
  |
note: the lint level is defined here
 --> src/sockaddr.rs:52:9
  |
1 | #![deny(warnings)]
  |         ^^^^^^^^
  = note: `#[deny(dead_code)]` implied by `#[deny(warnings)]`

error: aborting due to 1 previous error

Couldn't compile the test.

Do I possibly have something misconfigured locally to cause this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, there is a #![doc(test(attr(deny(warnings))))] in socket2. I didn't know about that. It's because of that.

/// # #[cfg(unix)] mod unix_example {
/// use libc::sockaddr_storage;
/// use socket2::{SockAddr, SockAddrStorage, socklen_t};
///
/// fn from_sockaddr_storage(recv_address: &sockaddr_storage) -> SockAddr {
/// let mut storage = SockAddrStorage::zeroed();
/// let libc_address = unsafe { storage.view_as::<sockaddr_storage>() };
/// *libc_address = *recv_address;
/// unsafe { SockAddr::new(storage, size_of::<sockaddr_storage>() as socklen_t) }
/// }
/// # }
/// ```
#[inline]
pub unsafe fn view_as<T>(&mut self) -> &mut T {
assert!(size_of::<T>() <= size_of::<Self>());
Expand Down
Loading