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 27
27
- [ Mutability] ( variable_bindings/mut.md )
28
28
- [ Scope and Shadowing] ( variable_bindings/scope.md )
29
29
- [ Declare first] ( variable_bindings/declare.md )
30
+ - [ Freezing] ( variable_bindings/freeze.md )
30
31
31
32
- [ Types] ( types.md )
32
33
- [ Casting] ( types/cast.md )
117
118
- [ Mutability] ( scope/move/mut.md )
118
119
- [ Borrowing] ( scope/borrow.md )
119
120
- [ Mutability] ( scope/borrow/mut.md )
120
- - [ Freezing] ( scope/borrow/freeze.md )
121
121
- [ Aliasing] ( scope/borrow/alias.md )
122
122
- [ The ref pattern] ( scope/borrow/ref.md )
123
123
- [ Lifetimes] ( scope/lifetime.md )
Original file line number Diff line number Diff line change 1
1
# Freezing
2
2
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:
5
5
6
6
``` rust,editable,ignore,mdbook-runnable
7
7
fn main() {
8
8
let mut _mutable_integer = 7i32;
9
9
10
10
{
11
- // Borrow `_mutable_integer`
12
- let large_integer = & _mutable_integer;
11
+ // Shadowing by immutable `_mutable_integer`
12
+ let _mutable_integer = _mutable_integer;
13
13
14
14
// Error! `_mutable_integer` is frozen in this scope
15
15
_mutable_integer = 50;
16
16
// FIXME ^ Comment out this line
17
17
18
- println!("Immutably borrowed {}", large_integer);
19
-
20
- // `large_integer` goes out of scope
18
+ // `_mutable_integer` goes out of scope
21
19
}
22
20
23
21
// Ok! `_mutable_integer` is not frozen in this scope
You can’t perform that action at this time.
0 commit comments