Skip to content

Debug derived when not allowed #246

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

Closed
dimbleby opened this issue Nov 13, 2016 · 6 comments
Closed

Debug derived when not allowed #246

dimbleby opened this issue Nov 13, 2016 · 6 comments

Comments

@dimbleby
Copy link
Contributor

Eg change tests/headers/union_with_big_member.h like this:

-  int b[33];
+  char b[33];

Then the output is like this:

#[repr(C)]
#[derive(Debug, Copy)]
pub struct WithBigArray {
    pub a: __BindgenUnionField<::std::os::raw::c_int>,
    pub b: __BindgenUnionField<[::std::os::raw::c_char; 33usize]>,
    pub bindgen_union_field: [u32; 9usize],
}

But the array b of __BindgenUnionFieldis too large for#[derive(Debug)]` to be allowed.

I hit this with a header file that pulls in pthreads: in particular

union pthread_attr_t
{
  char __size[__SIZEOF_PTHREAD_ATTR_T];
  long int __align;
};
@dimbleby
Copy link
Contributor Author

Actually on closer inspection I see that b isn't an array at all. But still, the compiler complains like this:

error[E0277]: the trait bound `[i8; 56]: std::fmt::Debug` is not satisfied
   --> src/ffi.rs:712:5
    |
712 |     pub __size: __BindgenUnionField<[::std::os::raw::c_char; 56usize]>,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::fmt::Debug` is not implemented for `[i8; 56]`
    |
    = note: `[i8; 56]` cannot be formatted using `:?`; if it is defined in your crate, add `#[derive(Debug)]` or manually implement it
    = note: required because of the requirements on the impl of `std::fmt::Debug` for `ffi::__BindgenUnionField<[i8; 56]>`
    = note: required because of the requirements on the impl of `std::fmt::Debug` for `&ffi::__BindgenUnionField<[i8; 56]>`
    = note: required for the cast to the object type `std::fmt::Debug`

(that output taken from compiling the pthreads example)

@dimbleby
Copy link
Contributor Author

By the way, I'd actually prefer not to generate Rust code to match pthreads headers at all - is there a way of excluding such things from the output?

@emilio
Copy link
Contributor

emilio commented Nov 13, 2016

@dimbleby yup! You can pass --whitelist flags with a regex, and we'll only generate stuff that matches that regex, or are used by it recursively.

Thanks for the report! This should be fixed in #248.

@emilio
Copy link
Contributor

emilio commented Nov 13, 2016

One of the pending stuff is writing better documentation in how to filter stuff, I use to point to Stylo's (Servo's style system in Gecko) script, but that's become really complex lately, so I'd rather write generic documentation :)

@dimbleby
Copy link
Contributor Author

gotcha thanks - and thanks for the impressively quick turnaround on the bug reports!

@emilio
Copy link
Contributor

emilio commented Nov 13, 2016

No problem! And thank you for reporting them! :)

bors-servo pushed a commit that referenced this issue Nov 14, 2016
Our debug-detection code assumes so.

Fixes #246

r? @fitzgen
bors-servo pushed a commit that referenced this issue Nov 14, 2016
codegen: Always implement debug for __BindgenUnionField.

Our debug-detection code assumes so.

Fixes #246

r? @fitzgen
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

No branches or pull requests

2 participants