diff --git a/doc/tutorial.md b/doc/tutorial.md index fbeda4257f5..7518e3ef676 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -1173,10 +1173,7 @@ For a more in-depth explanation of borrowed pointers, read the ## Freezing Borrowing an immutable pointer to an object freezes it and prevents mutation. -`Owned` objects have freezing enforced statically at compile-time. Mutable -managed boxes handle freezing dynamically when any of their contents are -borrowed, and the task will fail if an attempt to modify them is made while -they are frozen. +`Owned` objects have freezing enforced statically at compile-time. ~~~~ let mut x = 5; @@ -1186,6 +1183,20 @@ let mut x = 5; // x is now unfrozen again ~~~~ +Mutable managed boxes handle freezing dynamically when any of their contents +are borrowed, and the task will fail if an attempt to modify them is made while +they are frozen: + +~~~~ +let x = @mut 5; +let y = x; +{ + let y = &*y; // the managed box is now frozen + // modifying it through x or y will cause a task failure +} +// the box is now unfrozen again +~~~~ + # Dereferencing pointers Rust uses the unary star operator (`*`) to access the contents of a