Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite freeze.md #1314

Merged
merged 1 commit into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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