Skip to content

Commit 5feb3a6

Browse files
authored
Merge pull request #1779 from kpreid/patch-2
Mention the temporary scope of `while let`.
2 parents acd0231 + 61924f5 commit 5feb3a6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/destructors.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ smallest scope that contains the expression and is one of the following:
209209
* The body expression for a match arm.
210210
* Each operand of a [lazy boolean expression].
211211
* The pattern-matching condition(s) and consequent body of [`if`] ([destructors.scope.temporary.edition2024]).
212+
* The pattern-matching condition and loop body of [`while`].
212213
* The entirety of the tail expression of a block ([destructors.scope.temporary.edition2024]).
213214

214215
> [!NOTE]
@@ -221,6 +222,7 @@ r[destructors.scope.temporary.edition2024]
221222
Some examples:
222223

223224
```rust
225+
# #![allow(irrefutable_let_patterns)]
224226
# struct PrintOnDrop(&'static str);
225227
# impl Drop for PrintOnDrop {
226228
# fn drop(&mut self) {
@@ -247,6 +249,13 @@ else {
247249
// `if let else` dropped here
248250
};
249251

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+
250259
// Dropped before the first ||
251260
(PrintOnDrop("first operand").0 == ""
252261
// Dropped before the )

0 commit comments

Comments
 (0)