@@ -25,30 +25,30 @@ pointer, [`std::ptr::drop_in_place`] can be used.
25
25
Some examples:
26
26
27
27
``` rust
28
- struct ShowOnDrop (& 'static str );
28
+ struct PrintOnDrop (& 'static str );
29
29
30
- impl Drop for ShowOnDrop {
30
+ impl Drop for PrintOnDrop {
31
31
fn drop (& mut self ) {
32
32
println! (" {}" , self . 0 );
33
33
}
34
34
}
35
35
36
- let mut overwritten = ShowOnDrop (" drops when overwritten" );
37
- overwritten = ShowOnDrop (" drops when scope ends" );
36
+ let mut overwritten = PrintOnDrop (" drops when overwritten" );
37
+ overwritten = PrintOnDrop (" drops when scope ends" );
38
38
39
- let tuple = (ShowOnDrop (" Tuple first" ), ShowOnDrop (" Tuple second" ));
39
+ let tuple = (PrintOnDrop (" Tuple first" ), PrintOnDrop (" Tuple second" ));
40
40
41
41
let moved ;
42
42
// No destructor run on assignment.
43
- moved = ShowOnDrop (" Drops when moved" );
43
+ moved = PrintOnDrop (" Drops when moved" );
44
44
// Drops now, but is then uninitialized.
45
45
moved ;
46
46
47
47
// Uninitialized does not drop.
48
- let uninitialized : ShowOnDrop ;
48
+ let uninitialized : PrintOnDrop ;
49
49
50
50
// After a partial move, only the remaining fields are dropped.
51
- let mut partial_move = (ShowOnDrop (" first" ), ShowOnDrop (" forgotten" ));
51
+ let mut partial_move = (PrintOnDrop (" first" ), PrintOnDrop (" forgotten" ));
52
52
// Perform a partial move, leaving only `partial_move.0` initialized.
53
53
core :: mem :: forget (partial_move . 1 );
54
54
// When partial_move's scope ends, only the first field is dropped.
@@ -101,22 +101,22 @@ dropped last when evaluating the function. Actual function parameters are
101
101
dropped after any named parameters that are bound to parts of it.
102
102
103
103
``` rust
104
- # struct ShowOnDrop (& 'static str );
105
- # impl Drop for ShowOnDrop {
104
+ # struct PrintOnDrop (& 'static str );
105
+ # impl Drop for PrintOnDrop {
106
106
# fn drop (& mut self ) {
107
107
# println! (" drop({})" , self . 0 );
108
108
# }
109
109
# }
110
110
// Drops the second parameter, then `y`, then the first parameter, then `x`
111
111
fn patterns_in_parameters (
112
- (x , _ ): (ShowOnDrop , ShowOnDrop ),
113
- (_ , y ): (ShowOnDrop , ShowOnDrop ),
112
+ (x , _ ): (PrintOnDrop , PrintOnDrop ),
113
+ (_ , y ): (PrintOnDrop , PrintOnDrop ),
114
114
) {}
115
115
116
116
// drop order is 3 2 0 1
117
117
patterns_in_parameters (
118
- (ShowOnDrop (" 0" ), ShowOnDrop (" 1" )),
119
- (ShowOnDrop (" 2" ), ShowOnDrop (" 3" )),
118
+ (PrintOnDrop (" 0" ), PrintOnDrop (" 1" )),
119
+ (PrintOnDrop (" 2" ), PrintOnDrop (" 3" )),
120
120
);
121
121
```
122
122
@@ -128,17 +128,17 @@ the block that contains the `let` statement. Local variables declared in a
128
128
in.
129
129
130
130
``` rust
131
- # struct ShowOnDrop (& 'static str );
132
- # impl Drop for ShowOnDrop {
131
+ # struct PrintOnDrop (& 'static str );
132
+ # impl Drop for PrintOnDrop {
133
133
# fn drop (& mut self ) {
134
134
# println! (" drop({})" , self . 0 );
135
135
# }
136
136
# }
137
- let declared_first = ShowOnDrop (" Dropped last in outer scope" );
137
+ let declared_first = PrintOnDrop (" Dropped last in outer scope" );
138
138
{
139
- let declared_in_block = ShowOnDrop (" Dropped in inner scope" );
139
+ let declared_in_block = PrintOnDrop (" Dropped in inner scope" );
140
140
}
141
- let declared_last = ShowOnDrop (" Dropped first in outer scope" );
141
+ let declared_last = PrintOnDrop (" Dropped first in outer scope" );
142
142
```
143
143
144
144
If multiple patterns are used in the same arm for a ` match ` expression, then an unspecified
@@ -157,7 +157,8 @@ smallest scope that contains the expression and is for one of the following:
157
157
* A statement.
158
158
* The body of a [ ` if ` ] , [ ` while ` ] or [ ` loop ` ] expression.
159
159
* The ` else ` block of an ` if ` expression.
160
- * The condition expression of an ` if ` or ` while ` expression, or a ` match ` guard.
160
+ * The condition expression of an ` if ` or ` while ` expression, or a ` match `
161
+ guard.
161
162
* The expression for a match arm.
162
163
* The second operand of a [ lazy boolean expression] .
163
164
@@ -168,36 +169,36 @@ smallest scope that contains the expression and is for one of the following:
168
169
Some examples:
169
170
170
171
``` rust
171
- # struct ShowOnDrop (& 'static str );
172
- # impl Drop for ShowOnDrop {
172
+ # struct PrintOnDrop (& 'static str );
173
+ # impl Drop for PrintOnDrop {
173
174
# fn drop (& mut self ) {
174
175
# println! (" drop({})" , self . 0 );
175
176
# }
176
177
# }
177
- let local_var = ShowOnDrop (" local var" );
178
+ let local_var = PrintOnDrop (" local var" );
178
179
179
180
// Dropped once the condition has been evaluated
180
- if ShowOnDrop (" If condition" ). 0 == " If condition" {
181
+ if PrintOnDrop (" If condition" ). 0 == " If condition" {
181
182
// Dropped at the end of the block
182
- ShowOnDrop (" If body" ). 0
183
+ PrintOnDrop (" If body" ). 0
183
184
} else {
184
185
unreachable! ()
185
186
};
186
187
187
188
// Dropped at the end of the statement
188
- (ShowOnDrop (" first operand" ). 0 == ""
189
+ (PrintOnDrop (" first operand" ). 0 == ""
189
190
// Dropped at the )
190
- || ShowOnDrop (" second operand" ). 0 == "" )
191
+ || PrintOnDrop (" second operand" ). 0 == "" )
191
192
// Dropped at the end of the expression
192
- || ShowOnDrop (" third operand" ). 0 == "" ;
193
+ || PrintOnDrop (" third operand" ). 0 == "" ;
193
194
194
195
// Dropped at the end of the function, after local variables.
195
196
// Changing this to a statement containing a return expression would make the
196
197
// temporary be dropped before the local variables. Binding to a variable
197
198
// which is then returned would also make the temporary be dropped first.
198
- match ShowOnDrop (" Matched value in final expression" ) {
199
+ match PrintOnDrop (" Matched value in final expression" ) {
199
200
// Dropped once the condition has been evaluated
200
- _ if ShowOnDrop (" guard condition" ). 0 == "" => (),
201
+ _ if PrintOnDrop (" guard condition" ). 0 == "" => (),
201
202
_ => (),
202
203
}
203
204
```
@@ -211,23 +212,23 @@ once the expression is evaluated, dropping them has no effect unless one of the
211
212
operands to an expression breaks out of the expression, returns, or panics.
212
213
213
214
``` rust
214
- # struct ShowOnDrop (& 'static str );
215
- # impl Drop for ShowOnDrop {
215
+ # struct PrintOnDrop (& 'static str );
216
+ # impl Drop for PrintOnDrop {
216
217
# fn drop (& mut self ) {
217
218
# println! (" drop({})" , self . 0 );
218
219
# }
219
220
# }
220
221
loop {
221
222
// Tuple expression doesn't finish evaluating so operands drop in reverse order
222
223
(
223
- ShowOnDrop (" Outer tuple first" ),
224
- ShowOnDrop (" Outer tuple second" ),
224
+ PrintOnDrop (" Outer tuple first" ),
225
+ PrintOnDrop (" Outer tuple second" ),
225
226
(
226
- ShowOnDrop (" Inner tuple first" ),
227
- ShowOnDrop (" Inner tuple second" ),
227
+ PrintOnDrop (" Inner tuple first" ),
228
+ PrintOnDrop (" Inner tuple second" ),
228
229
break ,
229
230
),
230
- ShowOnDrop (" Never created" ),
231
+ PrintOnDrop (" Never created" ),
231
232
);
232
233
}
233
234
```
0 commit comments