Skip to content

Commit 80aeca8

Browse files
Apply suggestions from code review
Style and grammar fixes Co-Authored-By: matthewjasper <mjjasper1@gmail.com>
1 parent 484995d commit 80aeca8

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/destructors.md

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Destructors
22

3-
When an [initialized]&#32;[variable] or [temporary] in Rust goes out of
3+
When an [initialized]&#32;[variable] or [temporary] goes out of
44
[scope](#drop-scopes) its *destructor* is run, or it is *dropped*. [Assignment]
55
also runs the destructor of its left-hand operand, if it's initialized. If a
66
variable has been partially initialized, only its initialized fields are
77
dropped.
88

9-
The destructor of a type `T` consists of
9+
The destructor of a type `T` consists of:
1010

1111
1. If `T: Drop`, calling [`<T as std::ops::Drop>::drop`]
1212
2. Recursively running the destructor of all of its fields.
@@ -41,10 +41,11 @@ let tuple = (ShowOnDrop("Tuple first"), ShowOnDrop("Tuple second"));
4141
let moved;
4242
// No destructor run on assignment.
4343
moved = ShowOnDrop("Drops when moved");
44-
// drops now, but is then uninitialized
44+
// Drops now, but is then uninitialized.
4545
moved;
46+
4647
let uninitialized: ShowOnDrop;
47-
// Only the first element is dropped
48+
// Only the first element is dropped.
4849
let mut partially_initialized: (ShowOnDrop, ShowOnDrop);
4950
partially_initialized.0 = ShowOnDrop("Partial tuple first");
5051
```
@@ -55,7 +56,7 @@ Each variable or temporary is associated to a *drop scope*. When control flow
5556
leaves a drop scope all variables associated to that scope are dropped in
5657
reverse order of declaration (for variables) or creation (for temporaries).
5758

58-
Drop scopes are determined after replacing [`for`], [`if let`] and
59+
Drop scopes are determined after replacing [`for`], [`if let`], and
5960
[`while let`] expressions with the equivalent expressions using [`match`].
6061
Overloaded operators are not distinguished from built-in operators and [binding
6162
modes] are not considered.
@@ -82,17 +83,17 @@ from the inside outwards.
8283
* The parent of a statement scope is the scope of the block that contains the
8384
statement.
8485
* The parent of the expression for a `match` guard is the scope of the arm that
85-
it's for.
86+
the guard is for.
8687
* The parent of the expression for a given `match` arm is that arm's scope.
87-
* The parent of the arm scope is the scope of the match expression that it
88+
* The parent of the arm scope is the scope of the `match` expression that it
8889
belongs to.
8990
* The parent of all other scopes is the scope of the immediately enclosing
9091
expression.
9192

9293
### Scopes of function parameters
9394

9495
All function parameters are in the scope of the entire function body, so are
95-
dropped last when evaluating the function. The actual function parameter is
96+
dropped last when evaluating the function. Actual function parameters are
9697
dropped after any named parameters that are bound to parts of it.
9798

9899
```rust
@@ -119,7 +120,7 @@ patterns_in_parameters(
119120

120121
Local variables declared in a `let` statement are associated to the scope of
121122
the block that contains the `let` statement. Local variables declared in a
122-
match are associated to the arm scope of the `match` arm that they are declared
123+
`match` expression are associated to the arm scope of the `match` arm that they are declared
123124
in.
124125

125126
```rust
@@ -136,7 +137,7 @@ let declared_first = ShowOnDrop("Dropped last in outer scope");
136137
let declared_last = ShowOnDrop("Dropped first in outer scope");
137138
```
138139

139-
If multiple patterns are used in the same arm for a match, then an unspecified
140+
If multiple patterns are used in the same arm for a `match` expression, then an unspecified
140141
pattern will be used to determine the drop order.
141142

142143
### Temporary scopes
@@ -251,7 +252,7 @@ let x = &mut 0;
251252
println!("{}", x);
252253
```
253254

254-
If a borrow, dereference, field or tuple indexing expression has an extended
255+
If a borrow, dereference, field, or tuple indexing expression has an extended
255256
temporary scope then so does its operand. If an indexing expression has an
256257
extended temporary scope then the indexed expression also has an extended
257258
temporary scope.
@@ -262,7 +263,7 @@ An *extending pattern* is either
262263

263264
* An [identifier pattern] that binds by reference or mutable reference.
264265
* A [struct][struct pattern], [tuple][tuple pattern], [tuple struct][tuple
265-
struct pattern] or [slice][slice pattern] pattern where at least one of the
266+
struct pattern], or [slice][slice pattern] pattern where at least one of the
266267
direct subpatterns is a extending pattern.
267268

268269
So `ref x`, `V(ref x)` and `[ref x, y]` are all extending patterns, but `x`,
@@ -277,13 +278,13 @@ For a let statement with an initializer, an *extending expression* is an
277278
expression which is one of the following:
278279

279280
* The initializer expression.
280-
* The operand of a extending [borrow expression].
281+
* The operand of an extending [borrow expression].
281282
* The operand(s) of an extending [array][array expression], [cast][cast
282-
expression], [braced struct][struct expression] or [tuple][tuple expression]
283+
expression], [braced struct][struct expression], or [tuple][tuple expression]
283284
expression.
284285
* The final expression of any extending [block expression][block expressions].
285286

286-
So the borrow expressions in `&mut 0`, `(&1, &mut 2)` and `Some { 0: &mut 3 }`
287+
So the borrow expressions in `&mut 0`, `(&1, &mut 2)`, and `Some { 0: &mut 3 }`
287288
are all extending expressions, while the borrows in `&0 + &1` and
288289
`Some(&mut 0)` are not.
289290

@@ -315,7 +316,7 @@ Here are some examples where expressions don't have extended temporary scopes:
315316
# fn temp() {}
316317
# trait Use { fn use_temp(&self) -> &Self { self } }
317318
# impl Use for () {}
318-
// The temporary that stores the result of `temp()` lives only lives until the
319+
// The temporary that stores the result of `temp()` only lives until the
319320
// end of the let statement in these cases.
320321
321322
let x = Some(&temp()); // ERROR

0 commit comments

Comments
 (0)