From 0a25deacbb059f0a099753f4da410b531715b224 Mon Sep 17 00:00:00 2001 From: dianne Date: Tue, 26 Aug 2025 09:09:25 -0700 Subject: [PATCH 1/2] clean up and properly test temporary lifetime extension in doctests - Removes an unused trait and impl from the successful tests. - Adds uses following all tests so they test lifetime extension. --- src/destructors.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/destructors.md b/src/destructors.md index 36e0fe1ed..24ed38e2f 100644 --- a/src/destructors.md +++ b/src/destructors.md @@ -448,15 +448,18 @@ Here are some examples where expressions have extended temporary scopes: ```rust # fn temp() {} -# trait Use { fn use_temp(&self) -> &Self { self } } -# impl Use for () {} // The temporary that stores the result of `temp()` lives in the same scope // as x in these cases. let x = &temp(); +# x; let x = &temp() as &dyn Send; +# x; let x = (&*&temp(),); +# x; let x = { [Some(&temp()) ] }; +# x; let ref x = temp(); +# x; let ref x = *&temp(); # x; ``` @@ -471,6 +474,7 @@ Here are some examples where expressions don't have extended temporary scopes: // end of the let statement in these cases. let x = std::convert::identity(&temp()); // ERROR +# x; let x = (&temp()).use_temp(); // ERROR # x; ``` From e5ff66ddac7a944cb4381720ca18bc10b932296d Mon Sep 17 00:00:00 2001 From: dianne Date: Tue, 26 Aug 2025 09:14:45 -0700 Subject: [PATCH 2/2] specify lifetime extension of `match` arms and `if` tail expressions --- src/destructors.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/destructors.md b/src/destructors.md index 24ed38e2f..6d6226d35 100644 --- a/src/destructors.md +++ b/src/destructors.md @@ -435,6 +435,8 @@ expression which is one of the following: expression. * The arguments to an extending [tuple struct] or [tuple variant] constructor expression. * The final expression of any extending [block expression]. +* The arm(s) of an extending [`match`] expression. +* The final expressions of an extending [`if`] expression's consequent, `else if`, and `else` blocks. So the borrow expressions in `&mut 0`, `(&1, &mut 2)`, and `Some(&mut 3)` are all extending expressions. The borrows in `&0 + &1` and `f(&mut 0)` are not. @@ -458,6 +460,10 @@ let x = (&*&temp(),); # x; let x = { [Some(&temp()) ] }; # x; +let x = match () { _ => &temp() }; +# x; +let x = if true { &temp() } else { &temp() }; +# x; let ref x = temp(); # x; let ref x = *&temp(); @@ -477,6 +483,8 @@ let x = std::convert::identity(&temp()); // ERROR # x; let x = (&temp()).use_temp(); // ERROR # x; +let x = match &temp() { x => x }; // ERROR +# x; ``` r[destructors.forget]