rust-lang / rust-lang/nomicon

Can we use non_exhausive attr instead of zero length array in "Representing Opaque Structs"

Open Beginner friendly
#342 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
CSS
Stars
2.3k
Forks
325
PR merge metrics
No merged PRs in 30d

Description

Section: https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs

Currently, it uses a struct like this:

#[repr(C)]
pub struct Foo {
    _data: [u8; 0],
    _marker:
        core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,
}

But since that was written, we have access to the #[non_exhausive] attribute. I think it has the same functionality. Any reason we shouldn't be suggesting this instead?

#[repr(C)]
#[non_exhaustive]
pub struct Foo {
    _marker:
        core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the “Representing Opaque Structs” section in doc.rust-lang.org/nomicon/ffi.html and compare the documented zero-length-array pattern with the proposed #[non_exhaustive] form. Verify whether the attribute provides the same FFI and opacity guarantees, then update the section if appropriate and document any reason to retain the existing pattern.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.