@@ -226,6 +226,7 @@ r[destructors.scope.temporary.edition2024]
226
226
227
227
Some examples:
228
228
229
+ <!-- TODO: edition2024 -->
229
230
``` rust
230
231
# struct PrintOnDrop (& 'static str );
231
232
# impl Drop for PrintOnDrop {
@@ -243,17 +244,25 @@ if PrintOnDrop("If condition").0 == "If condition" {
243
244
unreachable! ()
244
245
};
245
246
247
+ if let " if let scrutinee" = PrintOnDrop (" if let scrutinee" ). 0 {
248
+ PrintOnDrop (" if let consequent" ). 0
249
+ // `if let consequent` dropped here
250
+ }
251
+ // `if let scrutinee` is dropped here
252
+ else {
253
+ PrintOnDrop (" if let else" ). 0
254
+ // `if let else` dropped here
255
+ };
256
+
246
257
// Dropped before the first ||
247
258
(PrintOnDrop (" first operand" ). 0 == ""
248
259
// Dropped before the )
249
260
|| PrintOnDrop (" second operand" ). 0 == "" )
250
261
// Dropped before the ;
251
262
|| PrintOnDrop (" third operand" ). 0 == "" ;
252
263
253
- // Dropped at the end of the function, after local variables.
254
- // Changing this to a statement containing a return expression would make the
255
- // temporary be dropped before the local variables. Binding to a variable
256
- // which is then returned would also make the temporary be dropped first.
264
+ // Scrutinee is dropped at the end of the function, before local variables
265
+ // (because this is the tail expression of the function body block).
257
266
match PrintOnDrop (" Matched value in final expression" ) {
258
267
// Dropped once the condition has been evaluated
259
268
_ if PrintOnDrop (" guard condition" ). 0 == "" => (),
0 commit comments