From 697bd0c7b8b95ccd857fa30bd6c2652755fbef93 Mon Sep 17 00:00:00 2001 From: Kevin Reid Date: Thu, 3 Apr 2025 08:39:47 -0700 Subject: [PATCH 1/2] Mention the temporary scope of `while let` I'm not an expert here, but because `while let` is a loop, it *has to* drop temporaries when it loops, so it must have at least one temporary scope, and empirically, the same scope includes the scrutinee and the body because the body can use temporaries from the scrutinee. --- src/destructors.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/destructors.md b/src/destructors.md index dbf1dcd1d..49bfad0c4 100644 --- a/src/destructors.md +++ b/src/destructors.md @@ -209,6 +209,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(s) and consequent body of [`if`] ([destructors.scope.temporary.edition2024]). +* The pattern-matching condition and loop body of [`while`]. * The entirety of the tail expression of a block ([destructors.scope.temporary.edition2024]). > [!NOTE] From 61924f5b23a569e036ed0962c4e2fba6c0be4a88 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Thu, 8 May 2025 16:49:36 +0000 Subject: [PATCH 2/2] Add example for temp scope of `while let` --- src/destructors.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/destructors.md b/src/destructors.md index 49bfad0c4..7e164c4de 100644 --- a/src/destructors.md +++ b/src/destructors.md @@ -222,6 +222,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) { @@ -248,6 +249,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 )