Skip to content
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

Fail to rename the field in impl debug when variable name conflicts with Rust #1122

Closed
photoszzt opened this issue Oct 30, 2017 · 2 comments
Closed

Comments

@photoszzt
Copy link
Contributor

Input C/C++ Header

struct test {
    unsigned int type;

    float a;
    union {
        int b;
        int c;
    };
};

Bindgen Invocation

$ bindgen --no-rustfmt-bindings --with-derive-default --impl-debug -o tests.rs headers/test.h

Actual Results

The translation of struct is correct:

 #[repr(C)]
 #[derive(Copy, Clone)]
 pub struct perf_event_attr {
     pub type_: ::std::os::raw::c_uint,
     pub a: f32,
     pub __bindgen_anon_1: perf_event_attr__bindgen_ty_1,
 }

But the impl Debug is wrong

impl ::std::fmt::Debug for perf_event_attr {
     fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
         write ! ( f , "perf_event_attr {{ type: {:?}, a: {:?}, __bindgen_anon_1: {:?} }}" , self . type , self . a , self . __bindgen_anon_1 )
     }
 }
error: expected identifier, found keyword `type`
   --> tests.rs:100:100
    |
100 |         write ! ( f , "perf_event_attr {{ type: {:?}, a: {:?}, __bindgen_anon_1: {:?} }}" , self . type , self . a , self . __bindgen_anon_1 )
    |                                                                                                    ^^^^

error: aborting due to previous error

Expected Results

Should be type_ not type.

@photoszzt
Copy link
Contributor Author

@highfive assign me

@highfive
Copy link

Hey @photoszzt! Thanks for your interest in working on this issue. It's now assigned to you!

bors-servo pushed a commit that referenced this issue Oct 30, 2017
Need mangle name of fields in struct for impl debug

Fix #1122  r? @fitzgen  or @emilio  or @pepyakin
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