diff options
| author | Steve Klabnik <steve@steveklabnik.com> | 2015-03-20 12:31:05 -0400 |
|---|---|---|
| committer | Steve Klabnik <steve@steveklabnik.com> | 2015-03-30 14:49:22 -0400 |
| commit | 8f0c952499ed31da47be09eaf198c095050f9cba (patch) | |
| tree | a8d67029acfcba63a1fd11e09be472a525626630 | |
| parent | 0834bd1b3db4e9c1477871cc962459b11e298234 (diff) | |
| download | rust-8f0c952499ed31da47be09eaf198c095050f9cba.tar.gz rust-8f0c952499ed31da47be09eaf198c095050f9cba.zip | |
Explain why 'elision'
| -rw-r--r-- | src/doc/trpl/ownership.md | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/doc/trpl/ownership.md b/src/doc/trpl/ownership.md index 6aced23ede0..fafd9903714 100644 --- a/src/doc/trpl/ownership.md +++ b/src/doc/trpl/ownership.md @@ -472,10 +472,15 @@ thread-safe counterpart of `Rc<T>`. ## Lifetime Elision -Earlier, we mentioned *lifetime elision*, a feature of Rust which allows you to -not write lifetime annotations in certain circumstances. All references have a -lifetime, and so if you elide a lifetime (like `&T` instead of `&'a T`), Rust -will do three things to determine what those lifetimes should be. +Rust supports powerful local type inference in function bodies, but it’s +forbidden in item signatures to allow reasoning about the types just based in +the item signature alone. However, for ergonomic reasons a very restricted +secondary inference algorithm called “lifetime elision” applies in function +signatures. It infers only based on the signature components themselves and not +based on the body of the function, only infers lifetime paramters, and does +this with only three easily memorizable and unambiguous rules. This makes +lifetime elision a shorthand for writing an item signature, while not hiding +away the actual types involved as full local inference would if applied to it. When talking about lifetime elision, we use the term *input lifetime* and *output lifetime*. An *input lifetime* is a lifetime associated with a parameter |
