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

generated function has an argument which shadows a generated static

Open db48x opened this issue 7 years ago • 6 comments

Input C/C++ Header

Perhaps soon.

Bindgen Invocation

    let bindings = bindgen::Builder::default()
        .generate_comments(true)
        .clang_arg("-I../../src")
        .clang_arg("-I../../lib")
        .header("wrapper.h")
        .hide_type("BOOL_VECTOR_BITS_PER_CHAR")
        .generate()
        .expect("Unable to generate bindings");

Actual Results

error[E0530]: function parameters cannot shadow statics
     --> /home/db48x/projects/remacs/rust_src/remacs-sys/target/debug/build/remacs-sys-992c0642432c4683/out/bindings.rs:29414:27
      |
29414 |                           face_change: bool_bf) -> u64 {
      |                           ^^^^^^^^^^^ cannot be named the same as a static
...
50626 |     pub static mut face_change: bool;
      |     --------------------------------- a static `face_change` is defined here

Expected Results

Hard to say how I would change this; probably by tweaking the argument name. That seems the simplest, because it only affects one function rather than everyone who wanted to use the static.

db48x avatar Jul 21 '17 21:07 db48x

Thanks for the bug report! The best way you can help us resolve this issue with with a reduced test case that demonstrates the bug: https://github.com/servo/rust-bindgen/blob/master/CONTRIBUTING.md#using-creduce-to-minimize-test-cases

fitzgen avatar Jul 21 '17 22:07 fitzgen

I can see from the error what it's trying to do... Here you got a test-case:

static int foo;

struct bar {
  int foo: 10;
};

emilio avatar Jul 22 '17 00:07 emilio

btw, I think this shouldn't be a hard error, it's just unfortunate, specially when it works in extern "C" functions.

emilio avatar Jul 22 '17 00:07 emilio

Any way to deal with this? 😦

Vurv78 avatar Nov 04 '21 08:11 Vurv78

I am running in the same issue. Is there anything we can do?

Narquadah avatar Feb 29 '24 11:02 Narquadah

I think the best solution would be if Bindgen automatically correctly named the static and argument. Statics should be SCREAMING_SNAKE_CASE, and arguments should be snake_case. I did it manually afterwards in the build.rs which resolved it for me:

    let new_output = [
        "ASM",
        "UART1",
        "UART2",
        "CRM",
        "AUTO_ADC",
        "ADC",
        "GPIO_08",
        "GPIO_09",
        "GPIO_10",
        "GPIO_11",
        "XTAL32_EXISTS",
        "TIMER_WU_EN",
        "RTC_WU_EN",
        "EXT_WU_EN",
        "EXT_WU_EDGE",
        "EXT_WU_POL",
        "TIMER_WU_IEN",
        "RTC_WU_IEN",
        "EXT_WU_IEN",
        "RTC_WU_EVT",
        "EXT_WU_EVT",
        "ROSC_EN",
        "ROSC_FTUNE",
        "ROSC_CTUNE",
        "XTAL32_EN",
        "XTAL32_GAIN"
    ].iter()
        .fold(bindgen_output, |a, s| {
            let lower = s.to_lowercase();
            a
                .replace(format!("{}: u32", s).as_str(), format!("{}: u32", lower).as_str())
                .replace(format!("::core::mem::transmute({})", s).as_str(), format!("::core::mem::transmute({})", lower).as_str())
                .replace(format!("{} as u64", s).as_str(), format!("{} as u64", lower).as_str())
        });

SimonIT avatar Feb 29 '24 12:02 SimonIT