File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed
src/test/run-make-fulldeps/return-non-c-like-enum Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ -include ../tools.mk
2+
3+ all :
4+ $(RUSTC ) --crate-type=staticlib nonclike.rs
5+ $(CC ) test.c $(call STATICLIB,nonclike) $(call OUT_EXE,test) \
6+ $(EXTRACFLAGS ) $(EXTRACXXFLAGS )
7+ $(call RUN,test)
Original file line number Diff line number Diff line change 1+ #![ crate_type = "lib" ]
2+ #![ crate_name = "nonclike" ]
3+
4+ #[ repr( C , u8 ) ]
5+ pub enum T {
6+ A ( u64 ) ,
7+ B ,
8+ }
9+
10+ #[ no_mangle]
11+ pub extern "C" fn t_new ( a : u64 ) -> T {
12+ T :: A ( a)
13+ }
Original file line number Diff line number Diff line change 1+ #include <stdint.h>
2+ #include <assert.h>
3+
4+ /* This is the code generated by cbindgen 0.12.1 for the `enum T` type
5+ * in nonclike.rs . */
6+ enum T_Tag {
7+ A ,
8+ B ,
9+ };
10+ typedef uint8_t T_Tag ;
11+
12+ typedef struct {
13+ uint64_t _0 ;
14+ } A_Body ;
15+
16+ typedef struct {
17+ T_Tag tag ;
18+ union {
19+ A_Body a ;
20+ };
21+ } T ;
22+
23+ /* This symbol is defined by the Rust staticlib built from
24+ * nonclike.rs. */
25+ extern T t_new (uint64_t v );
26+
27+ int main (int argc , char * argv []) {
28+ (void )argc ; (void )argv ;
29+
30+ T t = t_new (10 );
31+ assert (A == t .tag );
32+ assert (10 == t .a ._0 );
33+
34+ return 0 ;
35+ }
You can’t perform that action at this time.
0 commit comments