Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document lifetime elision for fn types, Fn*, impl #298

Merged
merged 1 commit into from
Aug 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/lifetime-elision.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ T<'a>

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

* For `fn` definitions, input refers to the types of the formal arguments
in the `fn` definition, while output refers to
* For `fn` definitions, `fn` types, and the traits `Fn`, `FnMut`, and `FnOnce`,
input refers to the types of the formal arguments, while output refers to
result types. So `fn foo(s: &str) -> (&str, &str)` has elided one lifetime in
input position and two lifetimes in output position.
Note that the input positions of a `fn` method definition do not
include the lifetimes that occur in the method's `impl` header
(nor lifetimes that occur in the trait header, for a default method).

* In the future, it should be possible to elide `impl` headers in the same manner.
input position and two lifetimes in output position. Note that the input
positions of a `fn` method definition do not include the lifetimes that occur
in the method's `impl` header (nor lifetimes that occur in the trait header,
for a default method).

* For `impl` headers, all types are input. So `impl Trait<&T> for Struct<&T>`
has elided two lifetimes in input position, while `impl Struct<&T>` has elided
one.

Elision rules are as follows:

Expand Down