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

Function main

tests/binary/mutable_borrow/src/main.rs:28–49  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26// Function taking a mutable borrow of the whole Point
27fn shift_point(p: &mut Point) {
28 p.x += 10; // Modify field directly via mutable borrow of struct
29 make_y_negative(&mut p.y); // Re-borrow field mutably and pass to another function
30 p.x += 5; // Modify field again after inner borrow ended
31}
32
33fn check_arrays_of_mutable_references() {
34 let mut first = 1;
35 let mut second = 2;
36 {
37 let refs = [&mut first, &mut second];
38 *refs[0] += 10;
39 *refs[1] += 20;
40 assert!(*refs[0] == 11);
41 assert!(*refs[1] == 22);
42 }
43
44 let mut left = Point { x: 3, y: 4 };
45 let mut right = Point { x: 5, y: 6 };
46 {
47 let refs = [&mut left, &mut right];
48 refs[0].x += 30;
49 refs[1].y += 60;
50 assert!(refs[0].x == 33);
51 assert!(refs[1].y == 66);
52 }

Callers

nothing calls this directly

Calls 2

get_x_coordFunction · 0.85
shift_pointFunction · 0.85

Tested by

no test coverage detected