File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ pattern often reveals smaller units of functionality.
2020Here is a contrived example of where the borrow checker foils us in our plan to
2121use a struct:
2222
23- ``` rust,ignore
23+ ``` rust
2424struct A {
2525 f1 : u32 ,
2626 f2 : u32 ,
@@ -31,10 +31,11 @@ fn foo(a: &mut A) -> &u32 { &a.f2 }
3131fn bar (a : & mut A ) -> u32 { a . f1 + a . f3 }
3232
3333fn baz (a : & mut A ) {
34- // x causes a to be borrowed for the rest of the function.
34+ // The later usage of x causes a to be borrowed for the rest of the function.
3535 let x = foo (a );
36- // Borrow check error
37- let y = bar(a); //~ ERROR: cannot borrow `*a` as mutable more than once at a time
36+ // Borrow checker error:
37+ // let y = bar(a); // ~ ERROR: cannot borrow `*a` as mutable more than once at a time
38+ println! (" {}" , x );
3839}
3940```
4041
@@ -63,6 +64,7 @@ fn baz(a: &mut A) {
6364 let x = foo (& mut a . b);
6465 // Now it's OK!
6566 let y = bar (& mut a . c);
67+ println! (" {}" , x );
6668}
6769```
6870
You can’t perform that action at this time.
0 commit comments