From 1b0bae62d3eb00dd0381b5ad5382b72398aa4114 Mon Sep 17 00:00:00 2001 From: Diva M Date: Tue, 27 Sep 2022 15:55:38 -0500 Subject: [PATCH 1/4] add false passing test --- tests/expectations/tests/field_mangling.rs | 60 ++++++++++++++++++++++ tests/headers/field_mangling.h | 5 ++ 2 files changed, 65 insertions(+) create mode 100644 tests/expectations/tests/field_mangling.rs create mode 100644 tests/headers/field_mangling.h diff --git a/tests/expectations/tests/field_mangling.rs b/tests/expectations/tests/field_mangling.rs new file mode 100644 index 0000000000..b754ce24e8 --- /dev/null +++ b/tests/expectations/tests/field_mangling.rs @@ -0,0 +1,60 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct foo { + pub type_: ::std::os::raw::c_int, + pub type_: ::std::os::raw::c_int, + pub type__: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(type_) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(type_) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).type__) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(type__) + ) + ); +} diff --git a/tests/headers/field_mangling.h b/tests/headers/field_mangling.h new file mode 100644 index 0000000000..6033a9074e --- /dev/null +++ b/tests/headers/field_mangling.h @@ -0,0 +1,5 @@ +typedef struct foo { + int type; + int type_; + int type__; +}; From 1f7ce9336ef058544abe4986d15b7707b5fa0f1a Mon Sep 17 00:00:00 2001 From: Diva M Date: Tue, 27 Sep 2022 15:58:08 -0500 Subject: [PATCH 2/4] use different types to aid testing --- tests/expectations/tests/field_mangling.rs | 12 ++++++------ tests/headers/field_mangling.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/expectations/tests/field_mangling.rs b/tests/expectations/tests/field_mangling.rs index b754ce24e8..b0ae08fed2 100644 --- a/tests/expectations/tests/field_mangling.rs +++ b/tests/expectations/tests/field_mangling.rs @@ -9,8 +9,8 @@ #[derive(Debug, Default, Copy, Clone)] pub struct foo { pub type_: ::std::os::raw::c_int, - pub type_: ::std::os::raw::c_int, - pub type__: ::std::os::raw::c_int, + pub type_: ::std::os::raw::c_long, + pub type__: ::std::os::raw::c_longlong, } #[test] fn bindgen_test_layout_foo() { @@ -19,12 +19,12 @@ fn bindgen_test_layout_foo() { let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), - 12usize, + 24usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( ::std::mem::align_of::(), - 4usize, + 8usize, concat!("Alignment of ", stringify!(foo)) ); assert_eq!( @@ -39,7 +39,7 @@ fn bindgen_test_layout_foo() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, - 4usize, + 8usize, concat!( "Offset of field: ", stringify!(foo), @@ -49,7 +49,7 @@ fn bindgen_test_layout_foo() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).type__) as usize - ptr as usize }, - 8usize, + 16usize, concat!( "Offset of field: ", stringify!(foo), diff --git a/tests/headers/field_mangling.h b/tests/headers/field_mangling.h index 6033a9074e..ca1b7eeacd 100644 --- a/tests/headers/field_mangling.h +++ b/tests/headers/field_mangling.h @@ -1,5 +1,5 @@ typedef struct foo { int type; - int type_; - int type__; + long type_; + long long type__; }; From f998904ce4963cd894fb2a4fb6dc0a6ef5cdf3f6 Mon Sep 17 00:00:00 2001 From: Diva M Date: Tue, 27 Sep 2022 16:00:27 -0500 Subject: [PATCH 3/4] add correct expected test result --- tests/expectations/tests/field_mangling.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/expectations/tests/field_mangling.rs b/tests/expectations/tests/field_mangling.rs index b0ae08fed2..475f3d665f 100644 --- a/tests/expectations/tests/field_mangling.rs +++ b/tests/expectations/tests/field_mangling.rs @@ -9,8 +9,8 @@ #[derive(Debug, Default, Copy, Clone)] pub struct foo { pub type_: ::std::os::raw::c_int, - pub type_: ::std::os::raw::c_long, - pub type__: ::std::os::raw::c_longlong, + pub type__: ::std::os::raw::c_long, + pub type___: ::std::os::raw::c_longlong, } #[test] fn bindgen_test_layout_foo() { @@ -38,7 +38,7 @@ fn bindgen_test_layout_foo() { ) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, + unsafe { ::std::ptr::addr_of!((*ptr).type__) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", @@ -48,7 +48,7 @@ fn bindgen_test_layout_foo() { ) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).type__) as usize - ptr as usize }, + unsafe { ::std::ptr::addr_of!((*ptr).type___) as usize - ptr as usize }, 16usize, concat!( "Offset of field: ", From 603345e9ad1592ac4c7f52c89bb6c761b1635501 Mon Sep 17 00:00:00 2001 From: Diva M Date: Wed, 28 Sep 2022 11:02:52 -0500 Subject: [PATCH 4/4] update tests --- src/ir/context.rs | 39 ++++--- tests/expectations/tests/arg_keyword.rs | 2 +- .../tests/bitfield-method-same-name.rs | 9 +- tests/expectations/tests/call-conv-typedef.rs | 2 +- .../tests/derive-bitfield-method-same-name.rs | 14 +-- .../tests/enum_and_vtable_mangling.rs | 4 +- .../tests/issue-1382-rust-primitive-types.rs | 16 +-- ...{field_mangling.rs => keyword_mangling.rs} | 12 +- tests/expectations/tests/keywords.rs | 110 +++++++++--------- tests/expectations/tests/underscore.rs | 2 +- tests/headers/field_mangling.h | 5 - tests/headers/keyword_mangling.h | 13 +++ 12 files changed, 124 insertions(+), 104 deletions(-) rename tests/expectations/tests/{field_mangling.rs => keyword_mangling.rs} (83%) delete mode 100644 tests/headers/field_mangling.h create mode 100644 tests/headers/keyword_mangling.h diff --git a/src/ir/context.rs b/src/ir/context.rs index 7837e59491..053960a444 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -813,26 +813,33 @@ If you encounter an error missing from this list, please file an issue or a PR!" // TODO: Move all this syntax crap to other part of the code. /// Mangles a name so it doesn't conflict with any keyword. - #[rustfmt::skip] pub fn rust_mangle<'a>(&self, name: &'a str) -> Cow<'a, str> { + #[rustfmt::skip] + const KEYWORDS: &[&'static str] = &[ + "abstract", "alignof", "as", "async", "await", "become", "box", + "break", "const", "continue", "crate", "do", "dyn", "else", "enum", + "extern", "false", "final", "fn", "for", "if", "impl", "in", "let", + "loop", "macro", "match", "mod", "move", "mut", "offsetof", + "override", "priv", "proc", "pub", "pure", "ref", "return", "Self", + "self", "sizeof", "static", "struct", "super", "trait", "true", + "try", "type", "typeof", "unsafe", "unsized", "use", "virtual", + "where", "while", "yield", "str", "bool", "f32", "f64", "usize", + "isize", "u128", "i128", "u64", "i64", "u32", "i32", "u16", "i16", + "u8", "i8", "_", + ]; + let mut is_keyword_or_mangled_keyword = false; + for keyword in KEYWORDS { + if let Some(remaining) = name.strip_prefix(keyword) { + if remaining.is_empty() || remaining.chars().all(|c| c == '_') { + is_keyword_or_mangled_keyword = true; + break; + } + } + } if name.contains('@') || name.contains('?') || name.contains('$') || - matches!( - name, - "abstract" | "alignof" | "as" | "async" | "await" | "become" | - "box" | "break" | "const" | "continue" | "crate" | "do" | - "dyn" | "else" | "enum" | "extern" | "false" | "final" | - "fn" | "for" | "if" | "impl" | "in" | "let" | "loop" | - "macro" | "match" | "mod" | "move" | "mut" | "offsetof" | - "override" | "priv" | "proc" | "pub" | "pure" | "ref" | - "return" | "Self" | "self" | "sizeof" | "static" | - "struct" | "super" | "trait" | "true" | "try" | "type" | "typeof" | - "unsafe" | "unsized" | "use" | "virtual" | "where" | - "while" | "yield" | "str" | "bool" | "f32" | "f64" | - "usize" | "isize" | "u128" | "i128" | "u64" | "i64" | - "u32" | "i32" | "u16" | "i16" | "u8" | "i8" | "_" - ) + is_keyword_or_mangled_keyword { let mut s = name.to_owned(); s = s.replace('@', "_"); diff --git a/tests/expectations/tests/arg_keyword.rs b/tests/expectations/tests/arg_keyword.rs index 43ff58313d..98cd09a956 100644 --- a/tests/expectations/tests/arg_keyword.rs +++ b/tests/expectations/tests/arg_keyword.rs @@ -7,5 +7,5 @@ extern "C" { #[link_name = "\u{1}_Z3fooPKc"] - pub fn foo(type_: *const ::std::os::raw::c_char); + pub fn foo(type__: *const ::std::os::raw::c_char); } diff --git a/tests/expectations/tests/bitfield-method-same-name.rs b/tests/expectations/tests/bitfield-method-same-name.rs index e9c1a76d1c..b3152fb861 100644 --- a/tests/expectations/tests/bitfield-method-same-name.rs +++ b/tests/expectations/tests/bitfield-method-same-name.rs @@ -124,7 +124,7 @@ extern "C" { } impl Foo { #[inline] - pub fn type__bindgen_bitfield(&self) -> ::std::os::raw::c_char { + pub fn type__(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u8) } @@ -138,14 +138,13 @@ impl Foo { } #[inline] pub fn new_bitfield_1( - type__bindgen_bitfield: ::std::os::raw::c_char, + type__: ::std::os::raw::c_char, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); __bindgen_bitfield_unit.set(0usize, 3u8, { - let type__bindgen_bitfield: u8 = - unsafe { ::std::mem::transmute(type__bindgen_bitfield) }; - type__bindgen_bitfield as u64 + let type__: u8 = unsafe { ::std::mem::transmute(type__) }; + type__ as u64 }); __bindgen_bitfield_unit } diff --git a/tests/expectations/tests/call-conv-typedef.rs b/tests/expectations/tests/call-conv-typedef.rs index 6eabb1f6ad..a5081bcc43 100644 --- a/tests/expectations/tests/call-conv-typedef.rs +++ b/tests/expectations/tests/call-conv-typedef.rs @@ -7,6 +7,6 @@ #![cfg(not(test))] pub type void_fn = ::std::option::Option; -pub type fn_ = ::std::option::Option< +pub type fn__ = ::std::option::Option< unsafe extern "stdcall" fn(id: ::std::os::raw::c_int) -> void_fn, >; diff --git a/tests/expectations/tests/derive-bitfield-method-same-name.rs b/tests/expectations/tests/derive-bitfield-method-same-name.rs index ea6621dd1c..ffc2b1c112 100644 --- a/tests/expectations/tests/derive-bitfield-method-same-name.rs +++ b/tests/expectations/tests/derive-bitfield-method-same-name.rs @@ -163,19 +163,18 @@ impl ::std::fmt::Debug for Foo { v )) .collect::(), - self.type__bindgen_bitfield() + self.type__() ) } } impl ::std::cmp::PartialEq for Foo { fn eq(&self, other: &Foo) -> bool { - &self.large[..] == &other.large[..] && - self.type__bindgen_bitfield() == other.type__bindgen_bitfield() + &self.large[..] == &other.large[..] && self.type__() == other.type__() } } impl Foo { #[inline] - pub fn type__bindgen_bitfield(&self) -> ::std::os::raw::c_char { + pub fn type__(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u8) } @@ -189,14 +188,13 @@ impl Foo { } #[inline] pub fn new_bitfield_1( - type__bindgen_bitfield: ::std::os::raw::c_char, + type__: ::std::os::raw::c_char, ) -> __BindgenBitfieldUnit<[u8; 2usize]> { let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = Default::default(); __bindgen_bitfield_unit.set(0usize, 3u8, { - let type__bindgen_bitfield: u8 = - unsafe { ::std::mem::transmute(type__bindgen_bitfield) }; - type__bindgen_bitfield as u64 + let type__: u8 = unsafe { ::std::mem::transmute(type__) }; + type__ as u64 }); __bindgen_bitfield_unit } diff --git a/tests/expectations/tests/enum_and_vtable_mangling.rs b/tests/expectations/tests/enum_and_vtable_mangling.rs index f414812b82..fef7fdc4c8 100644 --- a/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -5,12 +5,12 @@ non_upper_case_globals )] -pub const match_: _bindgen_ty_1 = _bindgen_ty_1::match_; +pub const match__: _bindgen_ty_1 = _bindgen_ty_1::match_; pub const whatever_else: _bindgen_ty_1 = _bindgen_ty_1::whatever_else; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_1 { - match_ = 0, + match__ = 0, whatever_else = 1, } #[repr(C)] diff --git a/tests/expectations/tests/issue-1382-rust-primitive-types.rs b/tests/expectations/tests/issue-1382-rust-primitive-types.rs index b767d5e430..c060153826 100644 --- a/tests/expectations/tests/issue-1382-rust-primitive-types.rs +++ b/tests/expectations/tests/issue-1382-rust-primitive-types.rs @@ -5,14 +5,14 @@ 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; +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 { diff --git a/tests/expectations/tests/field_mangling.rs b/tests/expectations/tests/keyword_mangling.rs similarity index 83% rename from tests/expectations/tests/field_mangling.rs rename to tests/expectations/tests/keyword_mangling.rs index 475f3d665f..fd598a06b1 100644 --- a/tests/expectations/tests/field_mangling.rs +++ b/tests/expectations/tests/keyword_mangling.rs @@ -44,7 +44,7 @@ fn bindgen_test_layout_foo() { "Offset of field: ", stringify!(foo), "::", - stringify!(type_) + stringify!(type__) ) ); assert_eq!( @@ -54,7 +54,15 @@ fn bindgen_test_layout_foo() { "Offset of field: ", stringify!(foo), "::", - stringify!(type__) + stringify!(type___) ) ); } +pub const Type_let_: Type = 0; +pub const Type_match_: Type = 1; +pub const Type_match__: Type = 2; +pub type Type = ::std::os::raw::c_uint; +extern "C" { + #[link_name = "\u{1}type"] + pub fn type__(type___: Type, type__: Type) -> ::std::os::raw::c_int; +} diff --git a/tests/expectations/tests/keywords.rs b/tests/expectations/tests/keywords.rs index a1e7f877e1..aa41acbc32 100644 --- a/tests/expectations/tests/keywords.rs +++ b/tests/expectations/tests/keywords.rs @@ -7,221 +7,221 @@ extern "C" { #[link_name = "\u{1}u8"] - pub static mut u8_: ::std::os::raw::c_int; + pub static mut u8__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}u16"] - pub static mut u16_: ::std::os::raw::c_int; + pub static mut u16__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}u32"] - pub static mut u32_: ::std::os::raw::c_int; + pub static mut u32__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}u64"] - pub static mut u64_: ::std::os::raw::c_int; + pub static mut u64__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}i8"] - pub static mut i8_: ::std::os::raw::c_int; + pub static mut i8__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}i16"] - pub static mut i16_: ::std::os::raw::c_int; + pub static mut i16__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}i32"] - pub static mut i32_: ::std::os::raw::c_int; + pub static mut i32__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}i64"] - pub static mut i64_: ::std::os::raw::c_int; + pub static mut i64__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}f32"] - pub static mut f32_: ::std::os::raw::c_int; + pub static mut f32__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}f64"] - pub static mut f64_: ::std::os::raw::c_int; + pub static mut f64__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}usize"] - pub static mut usize_: ::std::os::raw::c_int; + pub static mut usize__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}isize"] - pub static mut isize_: ::std::os::raw::c_int; + 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; + 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; + pub static mut str__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}dyn"] - pub static mut dyn_: ::std::os::raw::c_int; + pub static mut dyn__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}as"] - pub static mut as_: ::std::os::raw::c_int; + pub static mut as__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}async"] - pub static mut async_: ::std::os::raw::c_int; + pub static mut async__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}await"] - pub static mut await_: ::std::os::raw::c_int; + pub static mut await__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}box"] - pub static mut box_: ::std::os::raw::c_int; + pub static mut box__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}crate"] - pub static mut crate_: ::std::os::raw::c_int; + pub static mut crate__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}false"] - pub static mut false_: ::std::os::raw::c_int; + pub static mut false__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}fn"] - pub static mut fn_: ::std::os::raw::c_int; + pub static mut fn__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}impl"] - pub static mut impl_: ::std::os::raw::c_int; + pub static mut impl__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}in"] - pub static mut in_: ::std::os::raw::c_int; + pub static mut in__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}let"] - pub static mut let_: ::std::os::raw::c_int; + pub static mut let__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}loop"] - pub static mut loop_: ::std::os::raw::c_int; + pub static mut loop__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}match"] - pub static mut match_: ::std::os::raw::c_int; + pub static mut match__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}mod"] - pub static mut mod_: ::std::os::raw::c_int; + pub static mut mod__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}move"] - pub static mut move_: ::std::os::raw::c_int; + pub static mut move__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}mut"] - pub static mut mut_: ::std::os::raw::c_int; + pub static mut mut__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}pub"] - pub static mut pub_: ::std::os::raw::c_int; + pub static mut pub__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}ref"] - pub static mut ref_: ::std::os::raw::c_int; + pub static mut ref__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}self"] - pub static mut self_: ::std::os::raw::c_int; + pub static mut self__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}Self"] - pub static mut Self_: ::std::os::raw::c_int; + pub static mut Self__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}super"] - pub static mut super_: ::std::os::raw::c_int; + pub static mut super__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}trait"] - pub static mut trait_: ::std::os::raw::c_int; + pub static mut trait__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}true"] - pub static mut true_: ::std::os::raw::c_int; + pub static mut true__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}try"] - pub static mut try_: ::std::os::raw::c_int; + pub static mut try__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}type"] - pub static mut type_: ::std::os::raw::c_int; + pub static mut type__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}unsafe"] - pub static mut unsafe_: ::std::os::raw::c_int; + pub static mut unsafe__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}use"] - pub static mut use_: ::std::os::raw::c_int; + pub static mut use__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}where"] - pub static mut where_: ::std::os::raw::c_int; + pub static mut where__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}abstract"] - pub static mut abstract_: ::std::os::raw::c_int; + pub static mut abstract__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}alignof"] - pub static mut alignof_: ::std::os::raw::c_int; + pub static mut alignof__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}become"] - pub static mut become_: ::std::os::raw::c_int; + pub static mut become__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}final"] - pub static mut final_: ::std::os::raw::c_int; + pub static mut final__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}macro"] - pub static mut macro_: ::std::os::raw::c_int; + pub static mut macro__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}offsetof"] - pub static mut offsetof_: ::std::os::raw::c_int; + pub static mut offsetof__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}override"] - pub static mut override_: ::std::os::raw::c_int; + pub static mut override__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}priv"] - pub static mut priv_: ::std::os::raw::c_int; + pub static mut priv__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}proc"] - pub static mut proc_: ::std::os::raw::c_int; + pub static mut proc__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}pure"] - pub static mut pure_: ::std::os::raw::c_int; + pub static mut pure__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}unsized"] - pub static mut unsized_: ::std::os::raw::c_int; + pub static mut unsized__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}virtual"] - pub static mut virtual_: ::std::os::raw::c_int; + pub static mut virtual__: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}yield"] - pub static mut yield_: ::std::os::raw::c_int; + pub static mut yield__: ::std::os::raw::c_int; } diff --git a/tests/expectations/tests/underscore.rs b/tests/expectations/tests/underscore.rs index bfc05ac17a..155d391610 100644 --- a/tests/expectations/tests/underscore.rs +++ b/tests/expectations/tests/underscore.rs @@ -5,7 +5,7 @@ non_upper_case_globals )] -pub const __: ::std::os::raw::c_int = 10; +pub const ___: ::std::os::raw::c_int = 10; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct ptr_t { diff --git a/tests/headers/field_mangling.h b/tests/headers/field_mangling.h deleted file mode 100644 index ca1b7eeacd..0000000000 --- a/tests/headers/field_mangling.h +++ /dev/null @@ -1,5 +0,0 @@ -typedef struct foo { - int type; - long type_; - long long type__; -}; diff --git a/tests/headers/keyword_mangling.h b/tests/headers/keyword_mangling.h new file mode 100644 index 0000000000..15832c2248 --- /dev/null +++ b/tests/headers/keyword_mangling.h @@ -0,0 +1,13 @@ +typedef struct foo { + int type; + long type_; + long long type__; +}; + +enum Type { + let, + match, + match_, +}; + +int type(enum Type type_, enum Type type) { return 1; }