@@ -25,30 +25,30 @@ pointer, [`std::ptr::drop_in_place`] can be used.
2525Some examples:
2626
2727``` rust
28- struct ShowOnDrop (& 'static str );
28+ struct PrintOnDrop (& 'static str );
2929
30- impl Drop for ShowOnDrop {
30+ impl Drop for PrintOnDrop {
3131 fn drop (& mut self ) {
3232 println! (" {}" , self . 0 );
3333 }
3434}
3535
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" );
3838
39- let tuple = (ShowOnDrop (" Tuple first" ), ShowOnDrop (" Tuple second" ));
39+ let tuple = (PrintOnDrop (" Tuple first" ), PrintOnDrop (" Tuple second" ));
4040
4141let moved ;
4242// No destructor run on assignment.
43- moved = ShowOnDrop (" Drops when moved" );
43+ moved = PrintOnDrop (" Drops when moved" );
4444// Drops now, but is then uninitialized.
4545moved ;
4646
4747// Uninitialized does not drop.
48- let uninitialized : ShowOnDrop ;
48+ let uninitialized : PrintOnDrop ;
4949
5050// 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" ));
5252// Perform a partial move, leaving only `partial_move.0` initialized.
5353core :: mem :: forget (partial_move . 1 );
5454// 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
101101dropped after any named parameters that are bound to parts of it.
102102
103103``` rust
104- # struct ShowOnDrop (& 'static str );
105- # impl Drop for ShowOnDrop {
104+ # struct PrintOnDrop (& 'static str );
105+ # impl Drop for PrintOnDrop {
106106# fn drop (& mut self ) {
107107# println! (" drop({})" , self . 0 );
108108# }
109109# }
110110// Drops the second parameter, then `y`, then the first parameter, then `x`
111111fn patterns_in_parameters (
112- (x , _ ): (ShowOnDrop , ShowOnDrop ),
113- (_ , y ): (ShowOnDrop , ShowOnDrop ),
112+ (x , _ ): (PrintOnDrop , PrintOnDrop ),
113+ (_ , y ): (PrintOnDrop , PrintOnDrop ),
114114) {}
115115
116116// drop order is 3 2 0 1
117117patterns_in_parameters (
118- (ShowOnDrop (" 0" ), ShowOnDrop (" 1" )),
119- (ShowOnDrop (" 2" ), ShowOnDrop (" 3" )),
118+ (PrintOnDrop (" 0" ), PrintOnDrop (" 1" )),
119+ (PrintOnDrop (" 2" ), PrintOnDrop (" 3" )),
120120);
121121```
122122
@@ -128,17 +128,17 @@ the block that contains the `let` statement. Local variables declared in a
128128in.
129129
130130``` rust
131- # struct ShowOnDrop (& 'static str );
132- # impl Drop for ShowOnDrop {
131+ # struct PrintOnDrop (& 'static str );
132+ # impl Drop for PrintOnDrop {
133133# fn drop (& mut self ) {
134134# println! (" drop({})" , self . 0 );
135135# }
136136# }
137- let declared_first = ShowOnDrop (" Dropped last in outer scope" );
137+ let declared_first = PrintOnDrop (" Dropped last in outer scope" );
138138{
139- let declared_in_block = ShowOnDrop (" Dropped in inner scope" );
139+ let declared_in_block = PrintOnDrop (" Dropped in inner scope" );
140140}
141- let declared_last = ShowOnDrop (" Dropped first in outer scope" );
141+ let declared_last = PrintOnDrop (" Dropped first in outer scope" );
142142```
143143
144144If 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:
157157* A statement.
158158* The body of a [ ` if ` ] , [ ` while ` ] or [ ` loop ` ] expression.
159159* 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.
161162* The expression for a match arm.
162163* The second operand of a [ lazy boolean expression] .
163164
@@ -168,36 +169,36 @@ smallest scope that contains the expression and is for one of the following:
168169Some examples:
169170
170171``` rust
171- # struct ShowOnDrop (& 'static str );
172- # impl Drop for ShowOnDrop {
172+ # struct PrintOnDrop (& 'static str );
173+ # impl Drop for PrintOnDrop {
173174# fn drop (& mut self ) {
174175# println! (" drop({})" , self . 0 );
175176# }
176177# }
177- let local_var = ShowOnDrop (" local var" );
178+ let local_var = PrintOnDrop (" local var" );
178179
179180// Dropped once the condition has been evaluated
180- if ShowOnDrop (" If condition" ). 0 == " If condition" {
181+ if PrintOnDrop (" If condition" ). 0 == " If condition" {
181182 // Dropped at the end of the block
182- ShowOnDrop (" If body" ). 0
183+ PrintOnDrop (" If body" ). 0
183184} else {
184185 unreachable! ()
185186};
186187
187188// Dropped at the end of the statement
188- (ShowOnDrop (" first operand" ). 0 == ""
189+ (PrintOnDrop (" first operand" ). 0 == ""
189190// Dropped at the )
190- || ShowOnDrop (" second operand" ). 0 == "" )
191+ || PrintOnDrop (" second operand" ). 0 == "" )
191192// Dropped at the end of the expression
192- || ShowOnDrop (" third operand" ). 0 == "" ;
193+ || PrintOnDrop (" third operand" ). 0 == "" ;
193194
194195// Dropped at the end of the function, after local variables.
195196// Changing this to a statement containing a return expression would make the
196197// temporary be dropped before the local variables. Binding to a variable
197198// 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" ) {
199200 // Dropped once the condition has been evaluated
200- _ if ShowOnDrop (" guard condition" ). 0 == "" => (),
201+ _ if PrintOnDrop (" guard condition" ). 0 == "" => (),
201202 _ => (),
202203}
203204```
@@ -211,23 +212,23 @@ once the expression is evaluated, dropping them has no effect unless one of the
211212operands to an expression breaks out of the expression, returns, or panics.
212213
213214``` rust
214- # struct ShowOnDrop (& 'static str );
215- # impl Drop for ShowOnDrop {
215+ # struct PrintOnDrop (& 'static str );
216+ # impl Drop for PrintOnDrop {
216217# fn drop (& mut self ) {
217218# println! (" drop({})" , self . 0 );
218219# }
219220# }
220221loop {
221222 // Tuple expression doesn't finish evaluating so operands drop in reverse order
222223 (
223- ShowOnDrop (" Outer tuple first" ),
224- ShowOnDrop (" Outer tuple second" ),
224+ PrintOnDrop (" Outer tuple first" ),
225+ PrintOnDrop (" Outer tuple second" ),
225226 (
226- ShowOnDrop (" Inner tuple first" ),
227- ShowOnDrop (" Inner tuple second" ),
227+ PrintOnDrop (" Inner tuple first" ),
228+ PrintOnDrop (" Inner tuple second" ),
228229 break ,
229230 ),
230- ShowOnDrop (" Never created" ),
231+ PrintOnDrop (" Never created" ),
231232 );
232233}
233234```
0 commit comments