@@ -185,8 +185,8 @@ let declared_first = PrintOnDrop("Dropped last in outer scope");
185
185
let declared_last = PrintOnDrop (" Dropped first in outer scope" );
186
186
```
187
187
188
- r[ destructors.scope.bindings.pattern-drop-order ]
189
- If a pattern binds multiple variables, they are dropped in reverse order of declaration.
188
+ r[ destructors.scope.bindings.patterns ]
189
+ Variables in patterns are dropped in reverse order of declaration within the pattern .
190
190
191
191
``` rust
192
192
# struct PrintOnDrop (& 'static str );
@@ -201,8 +201,8 @@ let (declared_first, declared_last) = (
201
201
);
202
202
```
203
203
204
- r[ destructors.scope.bindings.or-pattern-declaration-order ]
205
- For the purpose of drop order, [ or-patterns] declare their bindings in the order given by their first sub-pattern .
204
+ r[ destructors.scope.bindings.or-patterns ]
205
+ For the purpose of drop order, [ or-patterns] declare bindings in the order given by the first subpattern .
206
206
207
207
``` rust
208
208
# struct PrintOnDrop (& 'static str );
@@ -211,20 +211,31 @@ For the purpose of drop order, [or-patterns] declare their bindings in the order
211
211
# println! (" drop({})" , self . 0 );
212
212
# }
213
213
# }
214
- // Drops `declared_last`, then `declared_first`.
215
- fn fixed_variable_drop_order <T >(
216
- (Ok ([declared_first , declared_last ])
217
- | Err ([declared_last , declared_first ])): Result <[T ; 2 ], [T ; 2 ]>
214
+ // Drops `x` before `y`.
215
+ fn or_pattern_drop_order <T >(
216
+ (Ok ([x , y ]) | Err ([y , x ])): Result <[T ; 2 ], [T ; 2 ]>
217
+ // ^^^^^^^^^^ ^^^^^^^^^^^ This is the second subpattern.
218
+ // |
219
+ // This is the first subpattern.
220
+ //
221
+ // In the first subpattern, `x` is declared before `y`. Since it is
222
+ // the first subpattern, that is the order used even if the second
223
+ // subpattern, where the bindings are declared in the opposite
224
+ // order, is matched.
218
225
) {}
219
226
220
- fixed_variable_drop_order (Ok ([
221
- PrintOnDrop (" Dropped last" ),
222
- PrintOnDrop (" Dropped first" ),
227
+ // Here we match the first subpattern, and the drops happen according
228
+ // to the declaration order in the first subpattern.
229
+ or_pattern_drop_order (Ok ([
230
+ PrintOnDrop (" Declared first, dropped last" ),
231
+ PrintOnDrop (" Declared last, dropped first" ),
223
232
]));
224
233
225
- fixed_variable_drop_order (Err ([
226
- PrintOnDrop (" Dropped first" ),
227
- PrintOnDrop (" Dropped last" ),
234
+ // Here we match the second subpattern, and the drops still happen
235
+ // according to the declaration order in the first subpattern.
236
+ or_pattern_drop_order (Err ([
237
+ PrintOnDrop (" Declared last, dropped first" ),
238
+ PrintOnDrop (" Declared first, dropped last" ),
228
239
]));
229
240
```
230
241
0 commit comments