File tree 1 file changed +9
-4
lines changed
1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -472,10 +472,15 @@ thread-safe counterpart of `Rc<T>`.
472
472
473
473
## Lifetime Elision
474
474
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.
479
484
480
485
When talking about lifetime elision, we use the term * input lifetime* and
481
486
* output lifetime* . An * input lifetime* is a lifetime associated with a parameter
You can’t perform that action at this time.
0 commit comments