MCPcopy Create free account
hub / github.com/IntegralPilot/rustc_codegen_jvm / main

Function main

tests/binary/structs/src/main.rs:12–63  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10}
11
12fn main() {
13 // === Nested STRUCT + TUPLE + ARRAY ===
14 let mut outer = Outer {
15 label: "start",
16 inner_struct: Inner {
17 x: 100,
18 y: (5, 10),
19 },
20 data: [1, 2, 3],
21 };
22
23 // === Access nested values ===
24 assert!(outer.label == "start");
25 assert!(outer.inner_struct.x == 100, "Inner x should be 100");
26 assert!(outer.inner_struct.y.0 == 5, "Inner tuple y.0 should be 5");
27 assert!(outer.inner_struct.y.1 == 10, "Inner tuple y.1 should be 10");
28 assert!(outer.data[0] == 1, "Array element at index 0 should be 1");
29
30 // === Mutate nested values ===
31 outer.label = "updated";
32 outer.inner_struct.x = 200;
33 outer.inner_struct.y.1 = 999;
34 outer.data[1] = 42;
35
36 // === Assert mutations ===
37 assert!(outer.label == "updated", "Outer label should be updated");
38 assert!(outer.inner_struct.x == 200, "Inner x should now be 200");
39 assert!(outer.inner_struct.y.1 == 999, "Inner tuple y.1 should now be 999");
40 assert!(outer.data[1] == 42, "Array element at index 1 should now be 42");
41
42 // === Tuple nesting test ===
43 let mut big_tuple = (
44 (10, 20),
45 Inner { x: 50, y: (7, 8) },
46 ["a", "b", "c"],
47 );
48
49 // Access nested tuple values
50 assert!((big_tuple.0).1 == 20, "First tuple's second element should be 20");
51 assert!(big_tuple.1.y.0 == 7, "Nested tuple inside struct should be 7");
52 assert!(big_tuple.2[2] == "c", "Array inside tuple should contain 'c' at index 2");
53
54 // Mutate nested values
55 (big_tuple.0).0 = 99;
56 big_tuple.1.x = 123;
57 big_tuple.2[1] = "z";
58
59 // Assert changes
60 assert!((big_tuple.0).0 == 99, "Tuple value mutated to 99");
61 assert!(big_tuple.1.x == 123, "Inner struct field x mutated to 123");
62 assert!(big_tuple.2[1] == "z", "Tuple's array element at index 1 mutated to 'z'");
63}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected