summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ir/context.rs4
-rw-r--r--tests/expectations/tests/issue-1382-rust-primitive-types.rs138
-rw-r--r--tests/expectations/tests/jsval_layout_opaque.rs12
-rw-r--r--tests/expectations/tests/jsval_layout_opaque_1_0.rs12
-rw-r--r--tests/expectations/tests/keywords.rs44
-rw-r--r--tests/headers/issue-1382-rust-primitive-types.h34
-rw-r--r--tests/headers/keywords.h3
7 files changed, 222 insertions, 25 deletions
diff --git a/src/ir/context.rs b/src/ir/context.rs
index 8ff102c0..901daa3a 100644
--- a/src/ir/context.rs
+++ b/src/ir/context.rs
@@ -864,7 +864,9 @@ If you encounter an error missing from this list, please file an issue or a PR!"
"return" | "Self" | "self" | "sizeof" | "static" |
"struct" | "super" | "trait" | "true" | "type" | "typeof" |
"unsafe" | "unsized" | "use" | "virtual" | "where" |
- "while" | "yield" | "bool" | "_" => true,
+ "while" | "yield" | "str" | "bool" | "f32" | "f64" |
+ "usize" | "isize" | "u128" | "i128" | "u64" | "i64" |
+ "u32" | "i32" | "u16" | "i16" | "u8" | "i8" | "_" => true,
_ => false,
}
{
diff --git a/tests/expectations/tests/issue-1382-rust-primitive-types.rs b/tests/expectations/tests/issue-1382-rust-primitive-types.rs
new file mode 100644
index 00000000..053fee91
--- /dev/null
+++ b/tests/expectations/tests/issue-1382-rust-primitive-types.rs
@@ -0,0 +1,138 @@
+/* automatically generated by rust-bindgen */
+
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
+
+pub type i8_ = i8;
+pub type u8_ = u8;
+pub type i16_ = i16;
+pub type u16_ = u16;
+pub type i32_ = i32;
+pub type u32_ = u32;
+pub type i64_ = i64;
+pub type u64_ = u64;
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct Foo {
+ pub i8_: ::std::os::raw::c_int,
+ pub u8_: ::std::os::raw::c_int,
+ pub i16_: ::std::os::raw::c_int,
+ pub u16_: ::std::os::raw::c_int,
+ pub i32_: ::std::os::raw::c_int,
+ pub u32_: ::std::os::raw::c_int,
+ pub i64_: ::std::os::raw::c_int,
+ pub u64_: ::std::os::raw::c_int,
+ pub i128_: ::std::os::raw::c_int,
+ pub u128_: ::std::os::raw::c_int,
+ pub isize_: ::std::os::raw::c_int,
+ pub usize_: ::std::os::raw::c_int,
+ pub f32_: ::std::os::raw::c_int,
+ pub f64_: ::std::os::raw::c_int,
+}
+#[test]
+fn bindgen_test_layout_Foo() {
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 56usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<Foo>())).i8_ as *const _ as usize },
+ 0usize,
+ concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i8_))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<Foo>())).u8_ as *const _ as usize },
+ 4usize,
+ concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u8_))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<Foo>())).i16_ as *const _ as usize },
+ 8usize,
+ concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i16_))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<Foo>())).u16_ as *const _ as usize },
+ 12usize,
+ concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u16_))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<Foo>())).i32_ as *const _ as usize },
+ 16usize,
+ concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i32_))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<Foo>())).u32_ as *const _ as usize },
+ 20usize,
+ concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u32_))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<Foo>())).i64_ as *const _ as usize },
+ 24usize,
+ concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i64_))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<Foo>())).u64_ as *const _ as usize },
+ 28usize,
+ concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u64_))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<Foo>())).i128_ as *const _ as usize },
+ 32usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(Foo),
+ "::",
+ stringify!(i128_)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<Foo>())).u128_ as *const _ as usize },
+ 36usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(Foo),
+ "::",
+ stringify!(u128_)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<Foo>())).isize_ as *const _ as usize },
+ 40usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(Foo),
+ "::",
+ stringify!(isize_)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<Foo>())).usize_ as *const _ as usize },
+ 44usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(Foo),
+ "::",
+ stringify!(usize_)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<Foo>())).f32_ as *const _ as usize },
+ 48usize,
+ concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f32_))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<Foo>())).f64_ as *const _ as usize },
+ 52usize,
+ concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f64_))
+ );
+}
diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs
index 0edcdc20..bab7c1bd 100644
--- a/tests/expectations/tests/jsval_layout_opaque.rs
+++ b/tests/expectations/tests/jsval_layout_opaque.rs
@@ -272,8 +272,8 @@ pub struct jsval_layout__bindgen_ty_2 {
#[repr(C)]
#[derive(Copy, Clone)]
pub union jsval_layout__bindgen_ty_2__bindgen_ty_1 {
- pub i32: i32,
- pub u32: u32,
+ pub i32_: i32,
+ pub u32_: u32,
pub why: JSWhyMagic,
_bindgen_union_align: u32,
}
@@ -298,27 +298,27 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() {
assert_eq!(
unsafe {
&(*(::std::ptr::null::<jsval_layout__bindgen_ty_2__bindgen_ty_1>()))
- .i32 as *const _ as usize
+ .i32_ as *const _ as usize
},
0usize,
concat!(
"Offset of field: ",
stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1),
"::",
- stringify!(i32)
+ stringify!(i32_)
)
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<jsval_layout__bindgen_ty_2__bindgen_ty_1>()))
- .u32 as *const _ as usize
+ .u32_ as *const _ as usize
},
0usize,
concat!(
"Offset of field: ",
stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1),
"::",
- stringify!(u32)
+ stringify!(u32_)
)
);
assert_eq!(
diff --git a/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/tests/expectations/tests/jsval_layout_opaque_1_0.rs
index 46f5b1c9..44acfbc4 100644
--- a/tests/expectations/tests/jsval_layout_opaque_1_0.rs
+++ b/tests/expectations/tests/jsval_layout_opaque_1_0.rs
@@ -320,8 +320,8 @@ pub struct jsval_layout__bindgen_ty_2 {
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
pub struct jsval_layout__bindgen_ty_2__bindgen_ty_1 {
- pub i32: __BindgenUnionField<i32>,
- pub u32: __BindgenUnionField<u32>,
+ pub i32_: __BindgenUnionField<i32>,
+ pub u32_: __BindgenUnionField<u32>,
pub why: __BindgenUnionField<JSWhyMagic>,
pub bindgen_union_field: u32,
}
@@ -346,27 +346,27 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() {
assert_eq!(
unsafe {
&(*(::std::ptr::null::<jsval_layout__bindgen_ty_2__bindgen_ty_1>()))
- .i32 as *const _ as usize
+ .i32_ as *const _ as usize
},
0usize,
concat!(
"Offset of field: ",
stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1),
"::",
- stringify!(i32)
+ stringify!(i32_)
)
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<jsval_layout__bindgen_ty_2__bindgen_ty_1>()))
- .u32 as *const _ as usize
+ .u32_ as *const _ as usize
},
0usize,
concat!(
"Offset of field: ",
stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1),
"::",
- stringify!(u32)
+ stringify!(u32_)
)
);
assert_eq!(
diff --git a/tests/expectations/tests/keywords.rs b/tests/expectations/tests/keywords.rs
index db57bb08..105b6cdc 100644
--- a/tests/expectations/tests/keywords.rs
+++ b/tests/expectations/tests/keywords.rs
@@ -8,40 +8,60 @@
)]
extern "C" {
- pub static mut u8: ::std::os::raw::c_int;
+ #[link_name = "\u{1}u8"]
+ pub static mut u8_: ::std::os::raw::c_int;
}
extern "C" {
- pub static mut u16: ::std::os::raw::c_int;
+ #[link_name = "\u{1}u16"]
+ pub static mut u16_: ::std::os::raw::c_int;
}
extern "C" {
- pub static mut u32: ::std::os::raw::c_int;
+ #[link_name = "\u{1}u32"]
+ pub static mut u32_: ::std::os::raw::c_int;
}
extern "C" {
- pub static mut u64: ::std::os::raw::c_int;
+ #[link_name = "\u{1}u64"]
+ pub static mut u64_: ::std::os::raw::c_int;
}
extern "C" {
- pub static mut i8: ::std::os::raw::c_int;
+ #[link_name = "\u{1}i8"]
+ pub static mut i8_: ::std::os::raw::c_int;
}
extern "C" {
- pub static mut i16: ::std::os::raw::c_int;
+ #[link_name = "\u{1}i16"]
+ pub static mut i16_: ::std::os::raw::c_int;
}
extern "C" {
- pub static mut i32: ::std::os::raw::c_int;
+ #[link_name = "\u{1}i32"]
+ pub static mut i32_: ::std::os::raw::c_int;
}
extern "C" {
- pub static mut i64: ::std::os::raw::c_int;
+ #[link_name = "\u{1}i64"]
+ pub static mut i64_: ::std::os::raw::c_int;
}
extern "C" {
- pub static mut f32: ::std::os::raw::c_int;
+ #[link_name = "\u{1}f32"]
+ pub static mut f32_: ::std::os::raw::c_int;
}
extern "C" {
- pub static mut f64: ::std::os::raw::c_int;
+ #[link_name = "\u{1}f64"]
+ pub static mut f64_: ::std::os::raw::c_int;
}
extern "C" {
- pub static mut usize: ::std::os::raw::c_int;
+ #[link_name = "\u{1}usize"]
+ pub static mut usize_: ::std::os::raw::c_int;
}
extern "C" {
- pub static mut isize: ::std::os::raw::c_int;
+ #[link_name = "\u{1}isize"]
+ pub static mut isize_: ::std::os::raw::c_int;
+}
+extern "C" {
+ #[link_name = "\u{1}bool"]
+ pub static mut bool_: ::std::os::raw::c_int;
+}
+extern "C" {
+ #[link_name = "\u{1}str"]
+ pub static mut str_: ::std::os::raw::c_int;
}
extern "C" {
#[link_name = "\u{1}as"]
diff --git a/tests/headers/issue-1382-rust-primitive-types.h b/tests/headers/issue-1382-rust-primitive-types.h
new file mode 100644
index 00000000..4cf346e6
--- /dev/null
+++ b/tests/headers/issue-1382-rust-primitive-types.h
@@ -0,0 +1,34 @@
+typedef int int8_t;
+typedef int uint8_t;
+typedef int int16_t;
+typedef int uint16_t;
+typedef int int32_t;
+typedef int uint32_t;
+typedef int int64_t;
+typedef int uint64_t;
+
+typedef int8_t i8;
+typedef uint8_t u8;
+typedef int16_t i16;
+typedef uint16_t u16;
+typedef int32_t i32;
+typedef uint32_t u32;
+typedef int64_t i64;
+typedef uint64_t u64;
+
+struct Foo {
+ int i8;
+ int u8;
+ int i16;
+ int u16;
+ int i32;
+ int u32;
+ int i64;
+ int u64;
+ int i128;
+ int u128;
+ int isize;
+ int usize;
+ int f32;
+ int f64;
+};
diff --git a/tests/headers/keywords.h b/tests/headers/keywords.h
index 8699ce5f..0e492316 100644
--- a/tests/headers/keywords.h
+++ b/tests/headers/keywords.h
@@ -10,6 +10,9 @@ int f32;
int f64;
int usize;
int isize;
+int bool;
+int str;
+
int as;
int box;
int crate;