Skip to content

Commit 220b5f8

Browse files
committed
Add caveat on Captures<'a> + Captures<'b> in footnote
In a footnote, we describe how there are various ways that `Captures` can be defined. However, we should point out that `Captures<'a> + Captures<'b>` is not equivalent to `Captures<(&'a (), &'b ())>` as lifetimes do not participate in trait selection in Rust. This is in fact the main reason that we defined `Captures` to accept a type parameter rather than a lifetime parameter in this document. Let's include this caveat in the footnote. (Thanks to @compiler-errors for reminding everyone of this.)
1 parent a624afa commit 220b5f8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

text/3498-lifetime-capture-rules-2024.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ fn foo<'a, 'b>(x: &'a (), y: &'b ()) -> impl Sized + Captures<(&'a (), &'b ())>
174174

175175
While this does work, the `Captures` trick is ungainly, it's not widely known, and its purpose is not commonly well understood.
176176

177-
[^captures-trait]: Note that there are various ways to define the `Captures` trait. In most discussions about this trick, it has been defined as above. However, internally in the Rust compiler it is currently defined instead as `pub trait Captures<'a> {}`. These notational differences do not affect the semantics described in this RFC.
177+
[^captures-trait]: Note that there are various ways to define the `Captures` trait. In most discussions about this trick, it has been defined as above. However, internally in the Rust compiler it is currently defined instead as `trait Captures<'a> {}`. These notational differences do not affect the semantics described in this RFC. Note, however, that `Captures<'a> + Captures<'b>` is not equivalent to `Captures<(&'a (), &'b ())>` because lifetimes do not participate in trait selection in Rust. To get equivalent semantics, one would have to define `trait Captures2<'a, 'b> {}`, `trait Captures3<'a, 'b, 'c> {}`, etc.
178178

179179
## Behavior of RPIT in Rust 2021 with type parameters
180180

0 commit comments

Comments
 (0)