Skip to content

generated function has an argument which shadows a generated static #840

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

Open
db48x opened this issue Jul 21, 2017 · 6 comments
Open

generated function has an argument which shadows a generated static #840

db48x opened this issue Jul 21, 2017 · 6 comments

Comments

@db48x
Copy link
Contributor

db48x commented Jul 21, 2017

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.

@fitzgen
Copy link
Member

fitzgen commented Jul 21, 2017

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

@emilio
Copy link
Contributor

emilio commented Jul 22, 2017

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
Copy link
Contributor

emilio commented Jul 22, 2017

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

@Vurv78
Copy link

Vurv78 commented Nov 4, 2021

Any way to deal with this? 😦

@Narquadah
Copy link

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

@SimonIT
Copy link

SimonIT commented Feb 29, 2024

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())
        });

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

6 participants