|
1 | 1 | # Destructors
|
2 |
| -r[destructors] |
3 | 2 |
|
4 |
| - |
5 |
| -r[destructors.general] |
| 3 | +r[destructors.intro] |
6 | 4 | When an [initialized] [variable] or [temporary] goes out of
|
7 | 5 | [scope](#drop-scopes), its *destructor* is run, or it is *dropped*. [Assignment]
|
8 | 6 | also runs the destructor of its left-hand operand, if it's initialized. If a
|
@@ -62,78 +60,77 @@ core::mem::forget(partial_move.1);
|
62 | 60 |
|
63 | 61 | ## Drop scopes
|
64 | 62 |
|
65 |
| -r[destructor.scope] |
66 |
| - |
| 63 | +r[destructors.scope] |
67 | 64 |
|
68 |
| -r[destructor.scope.general] |
| 65 | +r[destructors.scope.intro] |
69 | 66 | Each variable or temporary is associated to a *drop scope*. When control flow
|
70 | 67 | leaves a drop scope all variables associated to that scope are dropped in
|
71 | 68 | reverse order of declaration (for variables) or creation (for temporaries).
|
72 | 69 |
|
73 |
| -r[destructor.scope.desugaring] |
| 70 | +r[destructors.scope.desugaring] |
74 | 71 | Drop scopes are determined after replacing [`for`], [`if let`], and
|
75 | 72 | [`while let`] expressions with the equivalent expressions using [`match`].
|
76 | 73 |
|
77 |
| -r[destructor.scope.operators] |
| 74 | +r[destructors.scope.operators] |
78 | 75 | Overloaded operators are not distinguished from built-in operators and [binding
|
79 | 76 | modes] are not considered.
|
80 | 77 |
|
81 |
| -r[destructor.scope.list] |
| 78 | +r[destructors.scope.list] |
82 | 79 | Given a function, or closure, there are drop scopes for:
|
83 | 80 |
|
84 |
| -r[destructor.scope.function] |
| 81 | +r[destructors.scope.function] |
85 | 82 | * The entire function
|
86 | 83 |
|
87 |
| -r[destructor.scope.statement] |
| 84 | +r[destructors.scope.statement] |
88 | 85 | * Each [statement]
|
89 | 86 |
|
90 |
| -r[destructor.scope.expression] |
| 87 | +r[destructors.scope.expression] |
91 | 88 | * Each [expression]
|
92 | 89 |
|
93 |
| -r[destructor.scope.block] |
| 90 | +r[destructors.scope.block] |
94 | 91 | * Each block, including the function body
|
95 | 92 | * In the case of a [block expression], the scope for the block and the
|
96 | 93 | expression are the same scope.
|
97 | 94 |
|
98 |
| -r[destructor.scope.match-arm] |
| 95 | +r[destructors.scope.match-arm] |
99 | 96 | * Each arm of a `match` expression
|
100 | 97 |
|
101 |
| -r[destructor.scope.nesting] |
| 98 | +r[destructors.scope.nesting] |
102 | 99 | Drop scopes are nested within one another as follows. When multiple scopes are
|
103 | 100 | left at once, such as when returning from a function, variables are dropped
|
104 | 101 | from the inside outwards.
|
105 | 102 |
|
106 |
| -r[destructor.scope.nesting.function] |
| 103 | +r[destructors.scope.nesting.function] |
107 | 104 | * The entire function scope is the outer most scope.
|
108 | 105 |
|
109 |
| -r[destructor.scope.nesting.function-body] |
| 106 | +r[destructors.scope.nesting.function-body] |
110 | 107 | * The function body block is contained within the scope of the entire function.
|
111 | 108 |
|
112 |
| -r[destructor.scope.nesting.expr-statement] |
| 109 | +r[destructors.scope.nesting.expr-statement] |
113 | 110 | * The parent of the expression in an expression statement is the scope of the
|
114 | 111 | statement.
|
115 | 112 |
|
116 |
| -r[destructor.scope.nesting.let-initializer] |
| 113 | +r[destructors.scope.nesting.let-initializer] |
117 | 114 | * The parent of the initializer of a [`let` statement] is the `let` statement's
|
118 | 115 | scope.
|
119 | 116 |
|
120 |
| -r[destructor.scope.nesting.statement] |
| 117 | +r[destructors.scope.nesting.statement] |
121 | 118 | * The parent of a statement scope is the scope of the block that contains the
|
122 | 119 | statement.
|
123 | 120 |
|
124 |
| -r[destructor.scope.nesting.match-guard] |
| 121 | +r[destructors.scope.nesting.match-guard] |
125 | 122 | * The parent of the expression for a `match` guard is the scope of the arm that
|
126 | 123 | the guard is for.
|
127 | 124 |
|
128 |
| -r[destructor.scope.nesting.match-arm] |
| 125 | +r[destructors.scope.nesting.match-arm] |
129 | 126 | * The parent of the expression after the `=>` in a `match` expression is the
|
130 | 127 | scope of the arm that it's in.
|
131 | 128 |
|
132 |
| -r[destructor.scope.nesting.match] |
| 129 | +r[destructors.scope.nesting.match] |
133 | 130 | * The parent of the arm scope is the scope of the `match` expression that it
|
134 | 131 | belongs to.
|
135 | 132 |
|
136 |
| -r[destructor.scope.nesting.other] |
| 133 | +r[destructors.scope.nesting.other] |
137 | 134 | * The parent of all other scopes is the scope of the immediately enclosing
|
138 | 135 | expression.
|
139 | 136 |
|
@@ -167,9 +164,9 @@ patterns_in_parameters(
|
167 | 164 |
|
168 | 165 | ### Scopes of local variables
|
169 | 166 |
|
170 |
| -r[destructor.scope.bindings] |
| 167 | +r[destructors.scope.bindings] |
171 | 168 |
|
172 |
| -r[destructor.scope.bindings.general] |
| 169 | +r[destructors.scope.bindings.intro] |
173 | 170 | Local variables declared in a `let` statement are associated to the scope of
|
174 | 171 | the block that contains the `let` statement. Local variables declared in a
|
175 | 172 | `match` expression are associated to the arm scope of the `match` arm that they
|
@@ -197,13 +194,12 @@ unspecified pattern will be used to determine the drop order.
|
197 | 194 |
|
198 | 195 | r[destructors.scope.temporary]
|
199 | 196 |
|
200 |
| - |
201 |
| -r[destructor.scope.temporary.general] |
| 197 | +r[destructors.scope.temporary.intro] |
202 | 198 | The *temporary scope* of an expression is the scope that is used for the
|
203 | 199 | temporary variable that holds the result of that expression when used in a
|
204 | 200 | [place context], unless it is [promoted].
|
205 | 201 |
|
206 |
| -r[destructor.scope.temporary.enclosing] |
| 202 | +r[destructors.scope.temporary.enclosing] |
207 | 203 | Apart from lifetime extension, the temporary scope of an expression is the
|
208 | 204 | smallest scope that contains the expression and is one of the following:
|
209 | 205 |
|
@@ -341,7 +337,6 @@ temporary scope.
|
341 | 337 |
|
342 | 338 | r[destructors.scope.lifetime-extension.patterns]
|
343 | 339 |
|
344 |
| - |
345 | 340 | r[destructors.scope.lifetime-extension.patterns.extending]
|
346 | 341 | An *extending pattern* is either
|
347 | 342 |
|
|
0 commit comments