File tree Expand file tree Collapse file tree 2 files changed +6
-8
lines changed Expand file tree Collapse file tree 2 files changed +6
-8
lines changed Original file line number Diff line number Diff line change 2727 - [ Mutability] ( variable_bindings/mut.md )
2828 - [ Scope and Shadowing] ( variable_bindings/scope.md )
2929 - [ Declare first] ( variable_bindings/declare.md )
30+ - [ Freezing] ( variable_bindings/freeze.md )
3031
3132- [ Types] ( types.md )
3233 - [ Casting] ( types/cast.md )
117118 - [ Mutability] ( scope/move/mut.md )
118119 - [ Borrowing] ( scope/borrow.md )
119120 - [ Mutability] ( scope/borrow/mut.md )
120- - [ Freezing] ( scope/borrow/freeze.md )
121121 - [ Aliasing] ( scope/borrow/alias.md )
122122 - [ The ref pattern] ( scope/borrow/ref.md )
123123 - [ Lifetimes] ( scope/lifetime.md )
Original file line number Diff line number Diff line change 11# Freezing
22
3- When data is immutably borrowed , it also * freezes* . * Frozen* data can't be
4- modified via the original object until all references to it go out of scope:
3+ When data is bound by the same name immutably , it also * freezes* . * Frozen* data can't be
4+ modified until the immutable binding goes out of scope:
55
66``` rust,editable,ignore,mdbook-runnable
77fn main() {
88 let mut _mutable_integer = 7i32;
99
1010 {
11- // Borrow `_mutable_integer`
12- let large_integer = & _mutable_integer;
11+ // Shadowing by immutable `_mutable_integer`
12+ let _mutable_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-
20- // `large_integer` goes out of scope
18+ // `_mutable_integer` goes out of scope
2119 }
2220
2321 // Ok! `_mutable_integer` is not frozen in this scope
You can’t perform that action at this time.
0 commit comments