Skip to content

Commit 83d3503

Browse files
committed
Rollup merge of rust-lang#23558 - steveklabnik:explain_elision, r=gankro
2 parents 6cf3b0b + 8f0c952 commit 83d3503

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/doc/trpl/ownership.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -472,10 +472,15 @@ thread-safe counterpart of `Rc<T>`.
472472

473473
## Lifetime Elision
474474

475-
Earlier, we mentioned *lifetime elision*, a feature of Rust which allows you to
476-
not write lifetime annotations in certain circumstances. All references have a
477-
lifetime, and so if you elide a lifetime (like `&T` instead of `&'a T`), Rust
478-
will do three things to determine what those lifetimes should be.
475+
Rust supports powerful local type inference in function bodies, but it’s
476+
forbidden in item signatures to allow reasoning about the types just based in
477+
the item signature alone. However, for ergonomic reasons a very restricted
478+
secondary inference algorithm called “lifetime elision” applies in function
479+
signatures. It infers only based on the signature components themselves and not
480+
based on the body of the function, only infers lifetime paramters, and does
481+
this with only three easily memorizable and unambiguous rules. This makes
482+
lifetime elision a shorthand for writing an item signature, while not hiding
483+
away the actual types involved as full local inference would if applied to it.
479484

480485
When talking about lifetime elision, we use the term *input lifetime* and
481486
*output lifetime*. An *input lifetime* is a lifetime associated with a parameter

0 commit comments

Comments
 (0)