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

Correct a comment #2282

Merged
merged 1 commit into from
Jan 7, 2024
Merged

Correct a comment #2282

merged 1 commit into from
Jan 7, 2024

Conversation

asomers
Copy link
Member

@asomers asomers commented Jan 6, 2024

And while here, make cmsg_space a const fn, though I doubt it will make a difference since it's already inline.

The original comment was almost correct. Changing the cmsg_space macro to return an array works in most locations. However, it fails in the test_recverr_impl function in the tests due to a E0401 Error "Inner items do not inherit the generic parameters from the items they are embedded in." That error is very difficult to fix in our test, and it might occur in user code, too. The root of the problem is that each length of array is its own distinct type, and in a generic function cmsg_space returns an array type that may depend on the generic parameters.

Alternatively we could provide a second macro that always heap allocates. But that may be too complicated just to save a single allocation.

What does this PR do

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

@asomers asomers requested a review from SteveLauC January 6, 2024 15:25
And while here, make cmsg_space a const fn, though I doubt it will make
a difference since it's already inline.

The original comment was _almost_ correct.  Changing the cmsg_space
macro to return an array works in most locations.  However, it fails in
the test_recverr_impl function in the tests due to a E0401 Error "Inner
items do not inherit the generic parameters from the items they are
embedded in."  That error is very difficult to fix in our test, and it
might occur in user code, too.  The root of the problem is that each
length of array is its own distinct type, and in a generic function
cmsg_space returns an array type that may depend on the generic
parameters.

Alternatively we could provide a second macro that always heap
allocates.  But that may be too complicated just to save a single
allocation.
@SteveLauC SteveLauC added this pull request to the merge queue Jan 7, 2024
Merged via the queue into nix-rust:master with commit 20db3f3 Jan 7, 2024
35 checks passed
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