rust-lang / rust-lang/rust-bindgen
Opaque types don't include `!Send`, `!Sync`, `!Pin`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
We have a pointer type to an opaque type in our FFI project.
Bindgen generates this definition for the opaque type:
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct SEXPREC {
_unused: [u8; 0],
}
But then I was reading https://stackoverflow.com/questions/38315383/whats-the-rust-idiom-to-define-a-field-pointing-to-a-c-opaque-pointer, and https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs,
which says that the definition of the above should really be:
#[repr(C)]
pub struct SEXPREC {
_data: [u8; 0],
_marker:
core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,
}
Is this something I should replace the bindgen-version with this?
Lastly, I merely have these in the C-headers:
typedef struct SEXPREC s_object;
with no definition of s_object, and I'm quite certain this is intended behavior.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by examining bindgen's generation of opaque Rust structs from the incomplete C declaration typedef struct SEXPREC s_object;, then compare the generated type's auto-trait behavior with the Rust Nomicon guidance linked in the issue. Done means determining and documenting whether the generated opaque type should include !Send, !Sync, and !Pin, with regression coverage for the intended behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100