forked from rust-lang/rust-bindgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Look for
must_use
on typdefs in function return
Closes rust-lang#2206
- Loading branch information
1 parent
8a6eae9
commit 9191306
Showing
4 changed files
with
142 additions
and
5 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
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,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; | ||
} |
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,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(); |