rust-lang / rust-lang/rust-bindgen

Duplicate definitions with forward declared pointer types

Open
#1,864 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

Input C/C++ Header
CAPI void alt_RotationLayout_CAPI_Free_Forward(struct alt_RotationLayout* ptr);
typedef struct alt_RotationLayout {
    float roll;
    float pitch;
    float yaw;
} alt_RotationLayout;
CAPI void alt_RotationLayout_CAPI_Free(struct alt_RotationLayout* ptr);
Bindgen Invocation
let bindings = bindgen::Builder::default()
        .rustfmt_bindings(true)
        .layout_tests(false)
        .header(format!("./altv-capi-{}-static-{}/include/altv-capi-{}.h", kind, platform, kind))
        .parse_callbacks(Box::new(bindgen::CargoCallbacks))
        .generate()
        .expect("Unable to generate bindings");

    bindings
        .write_to_file(format!("src/altv_{}.rs", kind))
        .expect("Couldn't write bindings!");
Actual Results
/* automatically generated by rust-bindgen 0.54.1 */

pub const true_: u32 = 1;
pub const false_: u32 = 0;
pub const __bool_true_false_are_defined: u32 = 1;
pub type nullptr_t = *mut ::std::os::raw::c_void;
extern "C" {
  pub fn alt_RotationLayout_CAPI_Free_Forward(ptr: *mut alt_RotationLayout);
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct alt_RotationLayout {
  pub roll: f32,
  pub pitch: f32,
  pub yaw: f32,
}
extern "C" {
  pub fn alt_RotationLayout_CAPI_Free(ptr: *mut alt_RotationLayout);
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct alt_RotationLayout {
  pub _address: u8,
}
Expected Results

No duplicate definitions (when using forward declared pointers).

/* automatically generated by rust-bindgen 0.54.1 */

pub const true_: u32 = 1;
pub const false_: u32 = 0;
pub const __bool_true_false_are_defined: u32 = 1;
pub type nullptr_t = *mut ::std::os::raw::c_void;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
extern "C" {
  pub fn alt_RotationLayout_CAPI_Free_Forward(ptr: *mut alt_RotationLayout);
}
pub struct alt_RotationLayout {
  pub roll: f32,
  pub pitch: f32,
  pub yaw: f32,
}
extern "C" {
  pub fn alt_RotationLayout_CAPI_Free(ptr: *mut alt_RotationLayout);
}

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

Reproduce the report using the shown C/C++ header and bindgen::Builder invocation, writing the generated bindings to src/altv_*.rs. Compare the output around the forward-declared pointer and completed struct definitions; done means the generated Rust bindings contain no duplicate alt_RotationLayout definitions while preserving both functions.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cpp, rust
Domain
compilers, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.