-
Notifications
You must be signed in to change notification settings - Fork 717
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix recursive aliases to const module enum
Item::is_constified_enum_module() only returns true for the base type, not for "layers" of aliases. Added a "simple alias" test and added content to the types test.
- Loading branch information
Showing
7 changed files
with
312 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
tests/expectations/tests/constify-module-enums-simple-alias.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* automatically generated by rust-bindgen */ | ||
|
||
|
||
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] | ||
|
||
|
||
pub mod Foo { | ||
pub type Type = ::std::os::raw::c_int; | ||
pub const Variant1: Type = 0; | ||
pub const Variant2: Type = 1; | ||
pub const Variant3: Type = 2; | ||
} | ||
pub use self::Foo::Type as Foo_alias1; | ||
pub use self::Foo_alias1 as Foo_alias2; | ||
pub use self::Foo_alias2 as Foo_alias3; | ||
#[repr(C)] | ||
#[derive(Debug, Copy)] | ||
pub struct Bar { | ||
pub baz1: Foo::Type, | ||
pub baz2: Foo_alias1, | ||
pub baz3: Foo_alias2, | ||
pub baz4: Foo_alias3, | ||
pub baz_ptr1: *mut Foo::Type, | ||
pub baz_ptr2: *mut Foo_alias1, | ||
pub baz_ptr3: *mut Foo_alias2, | ||
pub baz_ptr4: *mut Foo_alias3, | ||
} | ||
#[test] | ||
fn bindgen_test_layout_Bar() { | ||
assert_eq!(::std::mem::size_of::<Bar>() , 48usize , concat ! ( | ||
"Size of: " , stringify ! ( Bar ) )); | ||
assert_eq! (::std::mem::align_of::<Bar>() , 8usize , concat ! ( | ||
"Alignment of " , stringify ! ( Bar ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const Bar ) ) . baz1 as * const _ as usize } , | ||
0usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( Bar ) , "::" , | ||
stringify ! ( baz1 ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const Bar ) ) . baz2 as * const _ as usize } , | ||
4usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( Bar ) , "::" , | ||
stringify ! ( baz2 ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const Bar ) ) . baz3 as * const _ as usize } , | ||
8usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( Bar ) , "::" , | ||
stringify ! ( baz3 ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const Bar ) ) . baz4 as * const _ as usize } , | ||
12usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( Bar ) , "::" , | ||
stringify ! ( baz4 ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const Bar ) ) . baz_ptr1 as * const _ as usize | ||
} , 16usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( Bar ) , "::" , | ||
stringify ! ( baz_ptr1 ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const Bar ) ) . baz_ptr2 as * const _ as usize | ||
} , 24usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( Bar ) , "::" , | ||
stringify ! ( baz_ptr2 ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const Bar ) ) . baz_ptr3 as * const _ as usize | ||
} , 32usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( Bar ) , "::" , | ||
stringify ! ( baz_ptr3 ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const Bar ) ) . baz_ptr4 as * const _ as usize | ||
} , 40usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( Bar ) , "::" , | ||
stringify ! ( baz_ptr4 ) )); | ||
} | ||
impl Clone for Bar { | ||
fn clone(&self) -> Self { *self } | ||
} | ||
impl Default for Bar { | ||
fn default() -> Self { unsafe { ::std::mem::zeroed() } } | ||
} |
40 changes: 40 additions & 0 deletions
40
tests/expectations/tests/constify-module-enums-simple-nonamespace.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* automatically generated by rust-bindgen */ | ||
|
||
|
||
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] | ||
|
||
|
||
pub mod one_Foo { | ||
pub type Type = ::std::os::raw::c_int; | ||
pub const Variant1: Type = 0; | ||
pub const Variant2: Type = 1; | ||
} | ||
#[repr(C)] | ||
#[derive(Debug, Copy)] | ||
pub struct Bar { | ||
pub baz1: one_Foo::Type, | ||
pub baz2: *mut one_Foo::Type, | ||
} | ||
#[test] | ||
fn bindgen_test_layout_Bar() { | ||
assert_eq!(::std::mem::size_of::<Bar>() , 16usize , concat ! ( | ||
"Size of: " , stringify ! ( Bar ) )); | ||
assert_eq! (::std::mem::align_of::<Bar>() , 8usize , concat ! ( | ||
"Alignment of " , stringify ! ( Bar ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const Bar ) ) . baz1 as * const _ as usize } , | ||
0usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( Bar ) , "::" , | ||
stringify ! ( baz1 ) )); | ||
assert_eq! (unsafe { | ||
& ( * ( 0 as * const Bar ) ) . baz2 as * const _ as usize } , | ||
8usize , concat ! ( | ||
"Alignment of field: " , stringify ! ( Bar ) , "::" , | ||
stringify ! ( baz2 ) )); | ||
} | ||
impl Clone for Bar { | ||
fn clone(&self) -> Self { *self } | ||
} | ||
impl Default for Bar { | ||
fn default() -> Self { unsafe { ::std::mem::zeroed() } } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// bindgen-flags: --constified-enum-module Foo | ||
|
||
enum class Foo { | ||
Variant1, Variant2, Variant3, | ||
}; | ||
|
||
typedef Foo Foo_alias1; | ||
typedef Foo_alias1 Foo_alias2; | ||
typedef Foo_alias2 Foo_alias3; | ||
|
||
class Bar { | ||
Foo baz1; | ||
Foo_alias1 baz2; | ||
Foo_alias2 baz3; | ||
Foo_alias3 baz4; | ||
|
||
Foo *baz_ptr1; | ||
Foo_alias1 *baz_ptr2; | ||
Foo_alias2 *baz_ptr3; | ||
Foo_alias3 *baz_ptr4; | ||
}; |
12 changes: 12 additions & 0 deletions
12
tests/headers/constify-module-enums-simple-nonamespace.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// bindgen-flags: --constified-enum-module one_Foo | ||
|
||
namespace one { | ||
enum class Foo { | ||
Variant1, Variant2, | ||
}; | ||
} | ||
|
||
class Bar { | ||
one::Foo baz1; | ||
one::Foo* baz2; | ||
}; |
Oops, something went wrong.