Skip to content

Commit bcfbb98

Browse files
committed
Add example for temp scope of while let
1 parent 04317e3 commit bcfbb98

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/destructors.md

+8
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ r[destructors.scope.temporary.edition2024]
221221
Some examples:
222222

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

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

0 commit comments

Comments
 (0)