rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

Comments are not generated for typedef struct forward declaration.

Open jschwe opened this issue 10 months ago • 0 comments

If we have a struct declaration with a typedef and the same name, the comment is not generated on the Rust binding.

/**
 * This is a forward declared struct with typedef
 */
typedef struct Struct2 Struct2;

binding:

#[repr(C)]
pub struct Struct2 {
    _unused: [u8; 0],
}

If we change the C typedef to have a non conflicting name:

/**
 * This is forward declared struct alias
 */
typedef struct Struct2 Struct2_alias;

The comment is generated on top of the type alia:

#[repr(C)]
pub struct Struct2 {
    _unused: [u8; 0],
}
/// This is forward declared struct alias
pub type Struct2_alias = Struct2;

If we add a field to the struct, then the comment is also correctly generated:

/**
 * This is forward declared struct alias
 */
typedef struct Struct2 {
    /**
     * This is field
     */
    int field;
} Struct2;
/// This is forward declared struct alias
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct Struct2 {
    /// This is field
    pub field: ::std::os::raw::c_int,
}

jschwe avatar Feb 08 '25 09:02 jschwe