diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-09-21 12:06:11 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-21 12:06:11 -0500 |
commit | 5b49548ddd37a11180439eec878e9c537cef1a97 (patch) | |
tree | adf31a002cb66ee997151470f66f0f16e820016d | |
parent | a8f4bc93b8125c24a1a129874a77f49a4a85ac57 (diff) | |
parent | aa11524259b1638108346176f8a00ab07a4f9500 (diff) |
Auto merge of #1008 - AndrewGaspar:underscore-identifier, r=fitzgen
Translate _ as __
This change treats _ as a reserved identifier to resolve the bug reported in #631.
I have one concern - if the header has both an `_` and `__` identifier in the global namespace, this will cause a conflict. However, it seems like we already don't handle that case for `keyword_` (e.g. `abstract_`, `alignof_`, etc.) so it doesn't seem like we need a solution specifically for `__` in this change.
Fixes #631.
-rw-r--r-- | src/ir/context.rs | 3 | ||||
-rw-r--r-- | tests/expectations/tests/underscore.rs | 40 | ||||
-rw-r--r-- | tests/headers/underscore.hpp | 3 |
3 files changed, 45 insertions, 1 deletions
diff --git a/src/ir/context.rs b/src/ir/context.rs index cc1baf90..b2c53aac 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -680,7 +680,8 @@ impl BindgenContext { "where" | "while" | "yield" | - "bool" => true, + "bool" | + "_" => true, _ => false, } { diff --git a/tests/expectations/tests/underscore.rs b/tests/expectations/tests/underscore.rs new file mode 100644 index 00000000..d1b0ccc2 --- /dev/null +++ b/tests/expectations/tests/underscore.rs @@ -0,0 +1,40 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + +pub const __: ::std::os::raw::c_int = 10; +#[repr(C)] +#[derive(Debug, Default, Copy)] +pub struct ptr_t { + pub __: [::std::os::raw::c_uchar; 8usize], +} +#[test] +fn bindgen_test_layout_ptr_t() { + assert_eq!( + ::std::mem::size_of::<ptr_t>(), + 8usize, + concat!("Size of: ", stringify!(ptr_t)) + ); + assert_eq!( + ::std::mem::align_of::<ptr_t>(), + 1usize, + concat!("Alignment of ", stringify!(ptr_t)) + ); + assert_eq!( + unsafe { &(*(0 as *const ptr_t)).__ as *const _ as usize }, + 0usize, + concat!( + "Alignment of field: ", + stringify!(ptr_t), + "::", + stringify!(__) + ) + ); +} +impl Clone for ptr_t { + fn clone(&self) -> Self { + *self + } +} diff --git a/tests/headers/underscore.hpp b/tests/headers/underscore.hpp new file mode 100644 index 00000000..1c9371f1 --- /dev/null +++ b/tests/headers/underscore.hpp @@ -0,0 +1,3 @@ +const int _ = 10; + +typedef struct { unsigned char _[8]; } ptr_t;
\ No newline at end of file |