diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/expectations/tests/func_return_must_use.rs | 76 | ||||
-rw-r--r-- | tests/headers/func_return_must_use.h | 36 |
2 files changed, 112 insertions, 0 deletions
diff --git a/tests/expectations/tests/func_return_must_use.rs b/tests/expectations/tests/func_return_must_use.rs new file mode 100644 index 00000000..9f40aaa6 --- /dev/null +++ b/tests/expectations/tests/func_return_must_use.rs @@ -0,0 +1,76 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +pub type MustUseInt = ::std::os::raw::c_int; +extern "C" { + #[must_use] + pub fn return_int() -> MustUseInt; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +#[must_use] +pub struct MustUseStruct { + _unused: [u8; 0], +} +extern "C" { + pub fn return_struct() -> MustUseStruct; +} +/// <div rustbindgen mustusetype></div> +pub type AnnotatedInt = ::std::os::raw::c_int; +extern "C" { + #[must_use] + pub fn return_annotated_int() -> AnnotatedInt; +} +extern "C" { + pub fn return_plain_int() -> ::std::os::raw::c_int; +} +/// <div rustbindgen mustusetype></div> +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +#[must_use] +pub struct AnnotatedStruct {} +#[test] +fn bindgen_test_layout_AnnotatedStruct() { + assert_eq!( + ::std::mem::size_of::<AnnotatedStruct>(), + 0usize, + concat!("Size of: ", stringify!(AnnotatedStruct)) + ); + assert_eq!( + ::std::mem::align_of::<AnnotatedStruct>(), + 1usize, + concat!("Alignment of ", stringify!(AnnotatedStruct)) + ); +} +extern "C" { + pub fn return_annotated_struct() -> AnnotatedStruct; +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct PlainStruct {} +#[test] +fn bindgen_test_layout_PlainStruct() { + assert_eq!( + ::std::mem::size_of::<PlainStruct>(), + 0usize, + concat!("Size of: ", stringify!(PlainStruct)) + ); + assert_eq!( + ::std::mem::align_of::<PlainStruct>(), + 1usize, + concat!("Alignment of ", stringify!(PlainStruct)) + ); +} +/// <div rustbindgen mustusetype></div> +pub type TypedefPlainStruct = PlainStruct; +extern "C" { + pub fn return_plain_struct() -> PlainStruct; +} +extern "C" { + #[must_use] + pub fn return_typedef_struct() -> TypedefPlainStruct; +} diff --git a/tests/headers/func_return_must_use.h b/tests/headers/func_return_must_use.h new file mode 100644 index 00000000..f05bd2de --- /dev/null +++ b/tests/headers/func_return_must_use.h @@ -0,0 +1,36 @@ +// bindgen-flags: --must-use-type 'MustUse.*' + +typedef int MustUseInt; + +MustUseInt return_int(); + +struct MustUseStruct; + +struct MustUseStruct return_struct(); + +/** + * <div rustbindgen mustusetype></div> + */ +typedef int AnnotatedInt; + +AnnotatedInt return_annotated_int(); + +int return_plain_int(); + +/** + * <div rustbindgen mustusetype></div> + */ +struct AnnotatedStruct {}; + +struct AnnotatedStruct return_annotated_struct(); + +struct PlainStruct {}; + +/** + * <div rustbindgen mustusetype></div> + */ +typedef struct PlainStruct TypedefPlainStruct; + +struct PlainStruct return_plain_struct(); + +TypedefPlainStruct return_typedef_struct(); |