summaryrefslogtreecommitdiffstats
path: root/tests/run-make/return-non-c-like-enum-from-c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/run-make/return-non-c-like-enum-from-c')
-rw-r--r--tests/run-make/return-non-c-like-enum-from-c/Makefile6
-rw-r--r--tests/run-make/return-non-c-like-enum-from-c/nonclike.rs31
-rw-r--r--tests/run-make/return-non-c-like-enum-from-c/test.c61
3 files changed, 98 insertions, 0 deletions
diff --git a/tests/run-make/return-non-c-like-enum-from-c/Makefile b/tests/run-make/return-non-c-like-enum-from-c/Makefile
new file mode 100644
index 000000000..bd441d321
--- /dev/null
+++ b/tests/run-make/return-non-c-like-enum-from-c/Makefile
@@ -0,0 +1,6 @@
+# ignore-cross-compile
+include ../tools.mk
+
+all: $(call NATIVE_STATICLIB,test)
+ $(RUSTC) nonclike.rs -L$(TMPDIR) -ltest
+ $(call RUN,nonclike)
diff --git a/tests/run-make/return-non-c-like-enum-from-c/nonclike.rs b/tests/run-make/return-non-c-like-enum-from-c/nonclike.rs
new file mode 100644
index 000000000..ea22a2a56
--- /dev/null
+++ b/tests/run-make/return-non-c-like-enum-from-c/nonclike.rs
@@ -0,0 +1,31 @@
+#[repr(C, u8)]
+pub enum TT {
+ AA(u64, u64),
+ BB,
+}
+
+#[repr(C,u8)]
+pub enum T {
+ A(u64),
+ B,
+}
+
+extern "C" {
+ pub fn t_new(a: u64) -> T;
+ pub fn tt_new(a: u64, b: u64) -> TT;
+}
+
+fn main() {
+ if let TT::AA(a, b) = unsafe { tt_new(10, 11) } {
+ assert_eq!(10, a);
+ assert_eq!(11, b);
+ } else {
+ panic!("expected TT::AA");
+ }
+
+ if let T::A(a) = unsafe { t_new(10) } {
+ assert_eq!(10, a);
+ } else {
+ panic!("expected T::A");
+ }
+}
diff --git a/tests/run-make/return-non-c-like-enum-from-c/test.c b/tests/run-make/return-non-c-like-enum-from-c/test.c
new file mode 100644
index 000000000..3ad135bab
--- /dev/null
+++ b/tests/run-make/return-non-c-like-enum-from-c/test.c
@@ -0,0 +1,61 @@
+#include <stdint.h>
+
+/* This is the code generated by cbindgen 0.12.1 for the `enum TT`
+ * type in nonclike.rs . */
+enum TT_Tag {
+ AA,
+ BB,
+};
+typedef uint8_t TT_Tag;
+
+typedef struct {
+ uint64_t _0;
+ uint64_t _1;
+} AA_Body;
+
+typedef struct {
+ TT_Tag tag;
+ union {
+ AA_Body aa;
+ };
+} TT;
+
+/* This is the code generated by cbindgen 0.12.1 for the `enum T` type
+ * in nonclike.rs . */
+enum T_Tag {
+ A,
+ B,
+};
+typedef uint8_t T_Tag;
+
+typedef struct {
+ uint64_t _0;
+} A_Body;
+
+typedef struct {
+ T_Tag tag;
+ union {
+ A_Body a;
+ };
+} T;
+
+TT tt_new(uint64_t a, uint64_t b) {
+ TT tt = {
+ .tag = AA,
+ .aa = {
+ ._0 = a,
+ ._1 = b,
+ },
+ };
+ return tt;
+}
+
+T t_new(uint64_t a) {
+ T t = {
+ .tag = A,
+ .a = {
+ ._0 = a,
+ },
+ };
+ return t;
+}