rust-lang / rust-lang/rust-bindgen

Error generation

Open
#3,235 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

error[E0740]: field must implement Copy or be wrapped in ManuallyDrop<...> to be used in a union
--> ./open/162/generated_bindings.rs:12:5
|
12 | pub _M_val: _Tp,
| ^^^^^^^^^^^^^^^
|
= note: union fields must not have drop side-effects, which is currently enforced via either Copy or ManuallyDrop<...>
help: wrap the field type in ManuallyDrop<...>
|
12 | pub _M_val: std::mem::ManuallyDrop<_Tp>,
| +++++++++++++++++++++++ +

error: aborting due to 1 previous error

For more information about this error, try rustc --explain E0740.

#[repr(C)]
pub union std_vector__Temporary_value__Storage<_Tp> {
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<_Tp>>,
pub _M_byte: ::std::os::raw::c_uchar,
pub _M_val: _Tp, //Error generation
}

#[repr(C)]
pub union std_vector__Temporary_value__Storage<_Tp> {
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<_Tp>>,
pub _M_byte: ::std::os::raw::c_uchar,
pub _M_val: ManuallyDrop<_Tp>, //Changing it to this compilation can be passed
}

Contributor guide

Open the contributing guide

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 by examining the generated_bindings.rs example and run rustc --explain E0740 to confirm why the union field is rejected. Trace how rust-bindgen produces std_vector__Temporary_value__Storage and compare the _M_val output with the ManuallyDrop form shown; done means the generated binding compiles without E0740.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.