Skip to content

Commit acef005

Browse files
author
brandondong
authored
Update compose structs compile error example for NLL (#136)
1 parent bff48fa commit acef005

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

patterns/compose-structs.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pattern often reveals smaller units of functionality.
2020
Here is a contrived example of where the borrow checker foils us in our plan to
2121
use a struct:
2222

23-
```rust,ignore
23+
```rust
2424
struct A {
2525
f1: u32,
2626
f2: u32,
@@ -31,10 +31,11 @@ fn foo(a: &mut A) -> &u32 { &a.f2 }
3131
fn bar(a: &mut A) -> u32 { a.f1 + a.f3 }
3232

3333
fn 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

0 commit comments

Comments
 (0)