Skip to content

Commit

Permalink
Merge pull request #1314 from dalance/rewrite_freeze
Browse files Browse the repository at this point in the history
Rewrite freeze.md
  • Loading branch information
marioidival authored Mar 11, 2020
2 parents 0465376 + cb32f06 commit b7c9cd9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- [Mutability](variable_bindings/mut.md)
- [Scope and Shadowing](variable_bindings/scope.md)
- [Declare first](variable_bindings/declare.md)
- [Freezing](variable_bindings/freeze.md)

- [Types](types.md)
- [Casting](types/cast.md)
Expand Down Expand Up @@ -117,7 +118,6 @@
- [Mutability](scope/move/mut.md)
- [Borrowing](scope/borrow.md)
- [Mutability](scope/borrow/mut.md)
- [Freezing](scope/borrow/freeze.md)
- [Aliasing](scope/borrow/alias.md)
- [The ref pattern](scope/borrow/ref.md)
- [Lifetimes](scope/lifetime.md)
Expand Down
12 changes: 5 additions & 7 deletions src/scope/borrow/freeze.md → src/variable_bindings/freeze.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
# Freezing

When data is immutably borrowed, it also *freezes*. *Frozen* data can't be
modified via the original object until all references to it go out of scope:
When data is bound by the same name immutably, it also *freezes*. *Frozen* data can't be
modified until the immutable binding goes out of scope:

```rust,editable,ignore,mdbook-runnable
fn main() {
let mut _mutable_integer = 7i32;
{
// Borrow `_mutable_integer`
let large_integer = &_mutable_integer;
// Shadowing by immutable `_mutable_integer`
let _mutable_integer = _mutable_integer;
// Error! `_mutable_integer` is frozen in this scope
_mutable_integer = 50;
// FIXME ^ Comment out this line
println!("Immutably borrowed {}", large_integer);
// `large_integer` goes out of scope
// `_mutable_integer` goes out of scope
}
// Ok! `_mutable_integer` is not frozen in this scope
Expand Down

0 comments on commit b7c9cd9

Please sign in to comment.