Skip to content

Bindgen is not respecting .derive_debug(true) for a generated struct that works with #[derive(Debug)] #2041

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
jbaublitz opened this issue Apr 26, 2021 · 2 comments

Comments

@jbaublitz
Copy link
Contributor

Input C/C++ Header

#include <linux/dm-ioctl.h>

Bindgen Invocation

    let bindings = Builder::default()         
        .header("dm-ioctl.h")   
        .derive_debug(true)                                               
        .derive_default(true)                                                                                                                                                                                                                 
        .generate()                                                                                                                                                                                                                           
        .expect("Could not generate bindings");                                                                                                                                                                                               

Actual Results

#[repr(C)]                                                                                                                                                                                                                          [421/1915]
#[derive(Copy, Clone)]                                                                                                                                                                                                                        
pub struct dm_ioctl {                                                                                                  
    pub version: [__u32; 3usize],                                                                                      
    pub data_size: __u32,                                  
    pub data_start: __u32,                                                                                             
    pub target_count: __u32,                                                                                           
    pub open_count: __s32,                                                                                             
    pub flags: __u32,                                                                                                  
    pub event_nr: __u32,                                                                                                                                                                                                                      
    pub padding: __u32,                                                                                                
    pub dev: __u64,                                                                                                    
    pub name: [::std::os::raw::c_char; 128usize],                                                                      
    pub uuid: [::std::os::raw::c_char; 129usize],                                                                      
    pub data: [::std::os::raw::c_char; 7usize],
}                                                          

Expected Results

I would expect dm_ioctl to have a #[derive(Debug)]. I tested this generated struct in the Rust playground and it successfully derives Debug when the directive is added. Was this an intentional design decision or does this appear to be a bug? Default appears not to be implemented for some of the members of the struct so that part makes sense.

@emilio
Copy link
Contributor

emilio commented Apr 26, 2021

The issue is:

    pub uuid: [::std::os::raw::c_char; 129usize],

(and the other 128-element array). In the past, Rust wouldn't allow to derive traits other than Copy on arrays of more than 32 elements, so bindgen had to deal with it. It seems with const generics that's fixed.

So we have can_derive_large_array in src/ir/analysis/derive.rs. We should add a rust feature to src/features.rs to the appropriate rust version, and then check that from can_derive_large_array. Other usages of RUST_DERIVE_IN_ARRAY_LIMIT should also be audited, but I'm pretty sure the can_derive_large_array change should be enough to fix your test-case.

@jbaublitz
Copy link
Contributor Author

Okay, thanks so much for the quick response! This isn't urgent because I can implement Debug by hand for now as it's only not being generated for that one struct, but I just wanted to make sure that I wasn't missing some configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants