Skip to content

Commit 61924f5

Browse files
committed
Add example for temp scope of while let
1 parent 697bd0c commit 61924f5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/destructors.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ r[destructors.scope.temporary.edition2024]
222222
Some examples:
223223

224224
```rust
225+
# #![allow(irrefutable_let_patterns)]
225226
# struct PrintOnDrop(&'static str);
226227
# impl Drop for PrintOnDrop {
227228
# fn drop(&mut self) {
@@ -248,6 +249,13 @@ else {
248249
// `if let else` dropped here
249250
};
250251

252+
while let x = PrintOnDrop("while let scrutinee").0 {
253+
PrintOnDrop("while let loop body").0;
254+
break;
255+
// `while let loop body` dropped here.
256+
// `while let scrutinee` dropped here.
257+
}
258+
251259
// Dropped before the first ||
252260
(PrintOnDrop("first operand").0 == ""
253261
// Dropped before the )

0 commit comments

Comments
 (0)