()
| 26 | // Function taking a mutable borrow of the whole Point |
| 27 | fn 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 | |
| 33 | fn 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 | } |
nothing calls this directly
no test coverage detected