Skip to content

Commit 3328fc2

Browse files
committed
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 9e35d2d commit 3328fc2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/types/impl-trait.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ Behind each return-position `impl Trait` abstract type is some hidden concrete t
9797

9898
## Automatic capturing
9999

100-
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.
100+
Return-position `impl Trait` abstract types automatically capture all in-scope generic parameters, including generic type, const, and lifetime parameters (including higher-ranked ones).
101101

102-
On items of trait impls and trait definitions, these types additionally automatically capture all in-scope generic lifetime parameters, including higher-ranked ones. 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.
102+
**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.
103103

104104
## Precise capturing
105105

0 commit comments

Comments
 (0)