From 9f00f6fdc579fa01783d4963480c9244a06231de Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 20 Oct 2020 23:50:24 +0300 Subject: [PATCH] Remove artificial restriction on lifetime parameters on enums --- src/bindgen/parser.rs | 8 -------- tests/expectations/lifetime_arg.both.c | 18 +++++++++++++++++- tests/expectations/lifetime_arg.both.compat.c | 18 +++++++++++++++++- tests/expectations/lifetime_arg.c | 18 +++++++++++++++++- tests/expectations/lifetime_arg.compat.c | 18 +++++++++++++++++- tests/expectations/lifetime_arg.cpp | 18 +++++++++++++++++- tests/expectations/lifetime_arg.tag.c | 18 +++++++++++++++++- tests/expectations/lifetime_arg.tag.compat.c | 18 +++++++++++++++++- tests/rust/lifetime_arg.rs | 8 +++++++- 9 files changed, 126 insertions(+), 16 deletions(-) diff --git a/src/bindgen/parser.rs b/src/bindgen/parser.rs index 6e7695d..8c985b0 100644 --- a/src/bindgen/parser.rs +++ b/src/bindgen/parser.rs @@ -906,14 +906,6 @@ impl Parse { mod_cfg: Option<&Cfg>, item: &syn::ItemEnum, ) { - if item.generics.lifetimes().count() > 0 { - info!( - "Skip {}::{} - (has generics or lifetimes or where bounds).", - crate_name, &item.ident - ); - return; - } - match Enum::load(item, mod_cfg, config) { Ok(en) => { info!("Take {}::{}.", crate_name, &item.ident); diff --git a/tests/expectations/lifetime_arg.both.c b/tests/expectations/lifetime_arg.both.c index ea160c6..241d362 100644 --- a/tests/expectations/lifetime_arg.both.c +++ b/tests/expectations/lifetime_arg.both.c @@ -7,4 +7,20 @@ typedef struct A { const int32_t *data; } A; -void root(A _a); +typedef enum E_Tag { + V, + U, +} E_Tag; + +typedef struct U_Body { + const uint8_t *_0; +} U_Body; + +typedef struct E { + E_Tag tag; + union { + U_Body u; + }; +} E; + +void root(A _a, E _e); diff --git a/tests/expectations/lifetime_arg.both.compat.c b/tests/expectations/lifetime_arg.both.compat.c index 9bb4d49..ba99107 100644 --- a/tests/expectations/lifetime_arg.both.compat.c +++ b/tests/expectations/lifetime_arg.both.compat.c @@ -7,11 +7,27 @@ typedef struct A { const int32_t *data; } A; +typedef enum E_Tag { + V, + U, +} E_Tag; + +typedef struct U_Body { + const uint8_t *_0; +} U_Body; + +typedef struct E { + E_Tag tag; + union { + U_Body u; + }; +} E; + #ifdef __cplusplus extern "C" { #endif // __cplusplus -void root(A _a); +void root(A _a, E _e); #ifdef __cplusplus } // extern "C" diff --git a/tests/expectations/lifetime_arg.c b/tests/expectations/lifetime_arg.c index 5bb91e7..0585056 100644 --- a/tests/expectations/lifetime_arg.c +++ b/tests/expectations/lifetime_arg.c @@ -7,4 +7,20 @@ typedef struct { const int32_t *data; } A; -void root(A _a); +typedef enum { + V, + U, +} E_Tag; + +typedef struct { + const uint8_t *_0; +} U_Body; + +typedef struct { + E_Tag tag; + union { + U_Body u; + }; +} E; + +void root(A _a, E _e); diff --git a/tests/expectations/lifetime_arg.compat.c b/tests/expectations/lifetime_arg.compat.c index 8b66368..743a5b8 100644 --- a/tests/expectations/lifetime_arg.compat.c +++ b/tests/expectations/lifetime_arg.compat.c @@ -7,11 +7,27 @@ typedef struct { const int32_t *data; } A; +typedef enum { + V, + U, +} E_Tag; + +typedef struct { + const uint8_t *_0; +} U_Body; + +typedef struct { + E_Tag tag; + union { + U_Body u; + }; +} E; + #ifdef __cplusplus extern "C" { #endif // __cplusplus -void root(A _a); +void root(A _a, E _e); #ifdef __cplusplus } // extern "C" diff --git a/tests/expectations/lifetime_arg.cpp b/tests/expectations/lifetime_arg.cpp index 5e5de0f..dc5ed99 100644 --- a/tests/expectations/lifetime_arg.cpp +++ b/tests/expectations/lifetime_arg.cpp @@ -8,8 +8,24 @@ struct A { const int32_t *data; }; +struct E { + enum class Tag { + V, + U, + }; + + struct U_Body { + const uint8_t *_0; + }; + + Tag tag; + union { + U_Body u; + }; +}; + extern "C" { -void root(A _a); +void root(A _a, E _e); } // extern "C" diff --git a/tests/expectations/lifetime_arg.tag.c b/tests/expectations/lifetime_arg.tag.c index 0bea2f4..07df4ea 100644 --- a/tests/expectations/lifetime_arg.tag.c +++ b/tests/expectations/lifetime_arg.tag.c @@ -7,4 +7,20 @@ struct A { const int32_t *data; }; -void root(struct A _a); +enum E_Tag { + V, + U, +}; + +struct U_Body { + const uint8_t *_0; +}; + +struct E { + enum E_Tag tag; + union { + struct U_Body u; + }; +}; + +void root(struct A _a, struct E _e); diff --git a/tests/expectations/lifetime_arg.tag.compat.c b/tests/expectations/lifetime_arg.tag.compat.c index 0f5b039..bb36f43 100644 --- a/tests/expectations/lifetime_arg.tag.compat.c +++ b/tests/expectations/lifetime_arg.tag.compat.c @@ -7,11 +7,27 @@ struct A { const int32_t *data; }; +enum E_Tag { + V, + U, +}; + +struct U_Body { + const uint8_t *_0; +}; + +struct E { + enum E_Tag tag; + union { + struct U_Body u; + }; +}; + #ifdef __cplusplus extern "C" { #endif // __cplusplus -void root(struct A _a); +void root(struct A _a, struct E _e); #ifdef __cplusplus } // extern "C" diff --git a/tests/rust/lifetime_arg.rs b/tests/rust/lifetime_arg.rs index 1336f73..b80fde2 100644 --- a/tests/rust/lifetime_arg.rs +++ b/tests/rust/lifetime_arg.rs @@ -3,6 +3,12 @@ struct A<'a> { data: &'a i32 } +#[repr(C)] +enum E<'a> { + V, + U(&'a u8), +} + #[no_mangle] -pub extern "C" fn root<'a>(_a: A<'a>) +pub extern "C" fn root<'a>(_a: A<'a>, _e: E<'a>) { }