fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #71365 - Mark-Simulacrum:stable-next, r=Mark-Simulacrum4fb7144ed15

1.43.0
1.2 KiB66 linesraw
1#include <stdint.h>
2#include <assert.h>
3
4#include <stdio.h>
5
6/* This is the code generated by cbindgen 0.12.1 for the `enum TT`
7 * type in nonclike.rs . */
8enum TT_Tag {
9  AA,
10  BB,
11};
12typedef uint8_t TT_Tag;
13
14typedef struct {
15  uint64_t _0;
16  uint64_t _1;
17} AA_Body;
18
19typedef struct {
20  TT_Tag tag;
21  union {
22    AA_Body aa;
23  };
24} TT;
25
26/* This is the code generated by cbindgen 0.12.1 for the `enum T` type
27 * in nonclike.rs . */
28enum T_Tag {
29  A,
30  B,
31};
32typedef uint8_t T_Tag;
33
34typedef struct {
35  uint64_t _0;
36} A_Body;
37
38typedef struct {
39  T_Tag tag;
40  union {
41    A_Body a;
42  };
43} T;
44
45/* These symbols are defined by the Rust staticlib built from
46 * nonclike.rs. */
47extern uint64_t t_add(T a, T b);
48extern uint64_t tt_add(TT a, TT b);
49
50int main(int argc, char *argv[]) {
51  (void)argc; (void)argv;
52
53  /* This example works. */
54  TT xx = { .tag = AA, .aa = { ._0 = 1, ._1 = 2 } };
55  TT yy = { .tag = AA, .aa = { ._0 = 10, ._1 = 20 } };
56  uint64_t rr = tt_add(xx, yy);
57  assert(33 == rr);
58
59  /* This one used to return an incorrect result (see issue #68190). */
60  T x = { .tag = A, .a = { ._0 = 1 } };
61  T y = { .tag = A, .a = { ._0 = 10 } };
62  uint64_t r = t_add(x, y);
63  assert(11 == r);
64
65  return 0;
66}