Skip to content

fix: unused struct tuple fields on DragonFlyBSD #2281

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

Merged
merged 1 commit into from
Jan 6, 2024

Conversation

SteveLauC
Copy link
Member

@SteveLauC SteveLauC commented Jan 6, 2024

What does this PR do

Test the DragonFlyBSD CI failure in #2277, theoretically, I should be able to reproduce it in this PR.

Fix that CI failure by converting the type SendfileHeaderTrailer into a real struct and explicitly mark the fields that are not in use as unused with a _ prefix.

Checklist:

  • I have read CONTRIBUTING.md
  • I have written necessary tests and rustdoc comments
  • A change log has been added if this PR modifies nix's API

@SteveLauC
Copy link
Member Author

Maybe this is not a bug but a feature, such a check was introduced in rust#118297: Merge unused_tuple_struct_fields into dead_code

@SteveLauC SteveLauC changed the title test DragonFlyBSD ci fix: unused struct tuple fields on DragonFlyBSD Jan 6, 2024
@SteveLauC SteveLauC requested a review from asomers January 6, 2024 08:50
Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

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

It looks like those fields only exist in order to keep a slice from dropping while we have a pointer to it. What about changing the function signature so we keep the user's original slice around? Something like:

fn send_file_header_trailer(headers: &Option<Vec<IoSlice<'a>>>, trailers: ...) -> Option<libc::sf_hdtr> {
    ...
}

@asomers
Copy link
Member

asomers commented Jan 6, 2024

It looks like those fields only exist in order to keep a slice from dropping while we have a pointer to it. What about changing the function signature so we keep the user's original slice around? Something like:

fn send_file_header_trailer(headers: &Option<Vec<IoSlice<'a>>>, trailers: ...) -> Option<libc::sf_hdtr> {
    ...
}

Ahh, I see now why it was done this way. Because sf_hdtr needs its headers and trailers to be in the form of a slice of iovec, which has a different layout than &[&[u8]].

Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

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

LGTM, except that the commit message is inaccurate. It applies to FreeBSD and Apple as well. But we don't test those on CI with a nightly compiler, which is why we only noticed for DragonflyBSD.

@asomers asomers added this pull request to the merge queue Jan 6, 2024
Merged via the queue into nix-rust:master with commit 3195d9e Jan 6, 2024
@SteveLauC SteveLauC deleted the test_ci branch January 7, 2024 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants