From 5acc59fe14a31c268576b1e9af07c7ec66827a4a Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Sat, 4 Oct 2025 20:10:42 +0200 Subject: [PATCH 1/2] add lifetime extension tests for tuple struct temporaries --- src/destructors.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/destructors.md b/src/destructors.md index d89c069c8..6368aca7c 100644 --- a/src/destructors.md +++ b/src/destructors.md @@ -526,6 +526,14 @@ let x = (&*&temp(),); // Operand of tuple constructor. # x; let x = { [Some(&temp())] }; // Final expr of block. # x; +# struct TupleStruct(T); +let x = TupleStruct(&temp()); // Argument of tuple struct. +# x; +# enum Enum { +# TupleVariant(T), +# } +let x = Enum::TupleVariant(&temp()); // Argument of tuple enum variant. +# x; let x = const { &temp() }; // Final expr of `const` block. # x; let x = unsafe { &temp() }; // Final expr of `unsafe` block. From 76cd60a0275f085ec1f379324b0314da1902c431 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Sun, 5 Oct 2025 08:02:14 +0000 Subject: [PATCH 2/2] Revise extending tuple struct constructor examples The example for the tuple enum variant constructor should go above the example that already uses a tuple enum variant constructor in a nested manner. This also matches the order in the list of extending expressions above -- the list items for tuple struct constructors and tuple enum variant constructors come after tuple expressions and before block expressions. For demonstrating a tuple enum variant constructor, it's better to use `Some(_)` than to define one; `Option` is well known enough. For the tuple struct that we need to define, let's use a short name like `W` here rather than `TupleStruct` (and show its definition). When I see a name like `TupleStruct`, it takes me a moment to confirm it's just a name and not more than that. We use this `W(T)` "wrapper" tuple struct definition elsewhere in the Reference. As a wording matter, we say "argument to" rather than "argument of". Similarly, something isn't an argument to a tuple struct but an argument to the tuple struct constructor, so let's say that. --- src/destructors.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/destructors.md b/src/destructors.md index 6368aca7c..37016223e 100644 --- a/src/destructors.md +++ b/src/destructors.md @@ -524,15 +524,12 @@ let x = &temp() as &dyn Send; // Operand of cast. # x; let x = (&*&temp(),); // Operand of tuple constructor. # x; -let x = { [Some(&temp())] }; // Final expr of block. +struct W(T); +let x = W(&temp()); // Argument to tuple struct constructor. # x; -# struct TupleStruct(T); -let x = TupleStruct(&temp()); // Argument of tuple struct. +let x = Some(&temp()); // Argument to tuple enum variant constructor. # x; -# enum Enum { -# TupleVariant(T), -# } -let x = Enum::TupleVariant(&temp()); // Argument of tuple enum variant. +let x = { [Some(&temp())] }; // Final expr of block. # x; let x = const { &temp() }; // Final expr of `const` block. # x;