Skip to content

Commit 35e3a81

Browse files
committed
freeze.md: Incorrect example
The freeze example is meant to show that a value cannot be immutably borrowed while the original value is modified within the same scope. However, as the immutably borrowed value is not used after the mutation, the borrow checker allows the example to be compiled successfully, contrary to what we intend to demonstrate. Solution: Use the immutably borrowed value after original value is modified.
1 parent 7d0357d commit 35e3a81

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/scope/borrow/freeze.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ fn main() {
99
1010
{
1111
// Borrow `_mutable_integer`
12-
let _large_integer = &_mutable_integer;
12+
let large_integer = &_mutable_integer;
1313
1414
// Error! `_mutable_integer` is frozen in this scope
1515
_mutable_integer = 50;
1616
// FIXME ^ Comment out this line
1717
18+
println!("Immutably borrowed {}", large_integer);
19+
1820
// `_large_integer` goes out of scope
1921
}
2022

0 commit comments

Comments
 (0)