Skip to content

Commit 5f75caa

Browse files
committed
Unwrap memory model chapters
This unwraps the text to follow our style guide.
1 parent 1723e6d commit 5f75caa

2 files changed

Lines changed: 9 additions & 29 deletions

File tree

src/memory-allocation-and-lifetime.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,7 @@ r[alloc]
22
# Memory allocation and lifetime
33

44
r[alloc.static]
5-
The _items_ of a program are those functions, modules, and types that have their
6-
value calculated at compile-time and stored uniquely in the memory image of the
7-
rust process. Items are neither dynamically allocated nor freed.
5+
The _items_ of a program are those functions, modules, and types that have their value calculated at compile-time and stored uniquely in the memory image of the rust process. Items are neither dynamically allocated nor freed.
86

97
r[alloc.dynamic]
10-
The _heap_ is a general term that describes boxes. The lifetime of an
11-
allocation in the heap depends on the lifetime of the box values pointing to
12-
it. Since box values may themselves be passed in and out of frames, or stored
13-
in the heap, heap allocations may outlive the frame they are allocated within.
14-
An allocation in the heap is guaranteed to reside at a single location in the
15-
heap for the whole lifetime of the allocation - it will never be relocated as
16-
a result of moving a box value.
8+
The _heap_ is a general term that describes boxes. The lifetime of an allocation in the heap depends on the lifetime of the box values pointing to it. Since box values may themselves be passed in and out of frames, or stored in the heap, heap allocations may outlive the frame they are allocated within. An allocation in the heap is guaranteed to reside at a single location in the heap for the whole lifetime of the allocation - it will never be relocated as a result of moving a box value.

src/variables.md

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,21 @@ r[variable]
22
# Variables
33

44
r[variable.intro]
5-
A _variable_ is a component of a stack frame, either a named function parameter,
6-
an anonymous [temporary](expressions.md#temporaries), or a named local
7-
variable.
5+
A _variable_ is a component of a stack frame, either a named function parameter, an anonymous [temporary](expressions.md#temporaries), or a named local variable.
86

97
r[variable.local]
10-
A _local variable_ (or *stack-local* allocation) holds a value directly,
11-
allocated within the stack's memory. The value is a part of the stack frame.
8+
A _local variable_ (or *stack-local* allocation) holds a value directly, allocated within the stack's memory. The value is a part of the stack frame.
129

1310
r[variable.local-mut]
14-
Local variables are immutable unless declared otherwise. For example:
15-
`let mut x = ...`.
11+
Local variables are immutable unless declared otherwise. For example: `let mut x = ...`.
1612

1713
r[variable.param-mut]
18-
Function parameters are immutable unless declared with `mut`. The `mut` keyword
19-
applies only to the following parameter. For example: `|mut x, y|` and
20-
`fn f(mut x: Box<i32>, y: Box<i32>)` declare one mutable variable `x` and one
21-
immutable variable `y`.
14+
Function parameters are immutable unless declared with `mut`. The `mut` keyword applies only to the following parameter. For example: `|mut x, y|` and `fn f(mut x: Box<i32>, y: Box<i32>)` declare one mutable variable `x` and one immutable variable `y`.
2215

2316
r[variable.init]
24-
Local variables are not initialized when allocated. Instead, the entire frame
25-
worth of local variables are allocated, on frame-entry, in an uninitialized
26-
state. Subsequent statements within a function may or may not initialize the
27-
local variables. Local variables can be used only after they have been
28-
initialized through all reachable control flow paths.
29-
30-
In this next example, `init_after_if` is initialized after the [`if` expression]
31-
while `uninit_after_if` is not because it is not initialized in the `else` case.
17+
Local variables are not initialized when allocated. Instead, the entire frame worth of local variables are allocated, on frame-entry, in an uninitialized state. Subsequent statements within a function may or may not initialize the local variables. Local variables can be used only after they have been initialized through all reachable control flow paths.
18+
19+
In this next example, `init_after_if` is initialized after the [`if` expression] while `uninit_after_if` is not because it is not initialized in the `else` case.
3220

3321
```rust
3422
# fn random_bool() -> bool { true }

0 commit comments

Comments
 (0)