Skip to content

Commit 898ac44

Browse files
traviscrossehuss
authored andcommitted
Add Lifetime Capture Rules 2024
The rules for which generic lifetime parameters are automatically captured in an RPIT-like opaque type are changing in Rust 2024 according to RFC 3498. Let's document these changes.
1 parent 4ad2685 commit 898ac44

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/types/impl-trait.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,10 @@ Behind each return-position `impl Trait` abstract type is some hidden concrete t
119119
r[type.impl-trait.generic-capture.auto]
120120

121121
r[type.impl-trait.generic-capture.auto.intro]
122-
Return-position `impl Trait` abstract types automatically capture certain of the in-scope generic parameters. Everywhere, these automatically capture all in-scope type and const generic parameters.
122+
Return-position `impl Trait` abstract types automatically capture all in-scope generic parameters, including generic type, const, and lifetime parameters (including higher-ranked ones).
123123

124-
r[type.impl-trait.generic-capture.auto.trait]
125-
On items of trait impls and trait definitions, these types additionally automatically capture all in-scope generic lifetime parameters, including higher-ranked ones\1
126-
127-
r[type.impl-trait.generic-capture.auto.fn]
128-
On free functions and on associated functions and methods of inherent impls, only the generic lifetime parameters that appear in the bounds of abstract return type are captured.
124+
r[type.impl-trait.generic-capture.edition2024]
125+
**Edition differences**: Before the 2024 edition, on free functions and on associated functions and methods of inherent impls, generic lifetime parameters that do not appear in the bounds of the abstract return type are not automatically captured.
129126

130127
## Precise capturing
131128

0 commit comments

Comments
 (0)