diff --git a/src/destructors.md b/src/destructors.md index 2f4711815..71907c5dd 100644 --- a/src/destructors.md +++ b/src/destructors.md @@ -208,6 +208,7 @@ smallest scope that contains the expression and is one of the following: * The body expression for a match arm. * Each operand of a [lazy boolean expression]. * The pattern-matching condition and consequent body of [`if let`] ([destructors.scope.temporary.edition2024]). +* The pattern-matching condition and loop body of [`while let`]. * The entirety of the tail expression of a block ([destructors.scope.temporary.edition2024]). > [!NOTE] @@ -220,6 +221,7 @@ r[destructors.scope.temporary.edition2024] Some examples: ```rust +# #![allow(irrefutable_let_patterns)] # struct PrintOnDrop(&'static str); # impl Drop for PrintOnDrop { # fn drop(&mut self) { @@ -246,6 +248,13 @@ else { // `if let else` dropped here }; +while let x = PrintOnDrop("while let scrutinee").0 { + PrintOnDrop("while let loop body").0; + break; + // `while let loop body` dropped here. + // `while let scrutinee` dropped here. +} + // Dropped before the first || (PrintOnDrop("first operand").0 == "" // Dropped before the )