Skip to content

Commit 0c7e5bd

Browse files
authored
Merge pull request #298 from ssbr/patch-1
Document lifetime elision for fn types, Fn*, impl
2 parents bf9b837 + 3abf036 commit 0c7e5bd

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/lifetime-elision.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ T<'a>
1414

1515
Lifetime positions can appear as either "input" or "output":
1616

17-
* For `fn` definitions, input refers to the types of the formal arguments
18-
in the `fn` definition, while output refers to
17+
* For `fn` definitions, `fn` types, and the traits `Fn`, `FnMut`, and `FnOnce`,
18+
input refers to the types of the formal arguments, while output refers to
1919
result types. So `fn foo(s: &str) -> (&str, &str)` has elided one lifetime in
20-
input position and two lifetimes in output position.
21-
Note that the input positions of a `fn` method definition do not
22-
include the lifetimes that occur in the method's `impl` header
23-
(nor lifetimes that occur in the trait header, for a default method).
24-
25-
* In the future, it should be possible to elide `impl` headers in the same manner.
20+
input position and two lifetimes in output position. Note that the input
21+
positions of a `fn` method definition do not include the lifetimes that occur
22+
in the method's `impl` header (nor lifetimes that occur in the trait header,
23+
for a default method).
24+
25+
* For `impl` headers, all types are input. So `impl Trait<&T> for Struct<&T>`
26+
has elided two lifetimes in input position, while `impl Struct<&T>` has elided
27+
one.
2628

2729
Elision rules are as follows:
2830

0 commit comments

Comments
 (0)