22
33We have seen how lifetimes provide us some fairly simple rules for ensuring
44that we never read dangling references. However up to this point we have only ever
5- interacted with the * outlives *  relationship in an inclusive manner. That is,
6- when we talked about ` 'a: 'b ` , it was ok for ` 'a `  to live * exactly *  as long as
5+ interacted with the _ outlives _  relationship in an inclusive manner. That is,
6+ when we talked about ` 'a: 'b ` , it was ok for ` 'a `  to live _ exactly _  as long as
77` 'b ` . At first glance, this seems to be a meaningless distinction. Nothing ever
88gets dropped at the same time as another, right? This is why we used the
99following desugaring of ` let `  statements:
@@ -35,7 +35,7 @@ let tuple = (vec![], vec![]);
3535
3636The left vector is dropped first. But does it mean the right one strictly
3737outlives it in the eyes of the borrow checker? The answer to this question is
38- * no * . The borrow checker could track fields of tuples separately, but it would
38+ _ no _ . The borrow checker could track fields of tuples separately, but it would
3939still be unable to decide what outlives what in case of vector elements, which
4040are dropped manually via pure-library code the borrow checker doesn't
4141understand.
@@ -93,15 +93,16 @@ fn main() {
9393
9494``` text 
9595error[E0597]: `world.days` does not live long enough 
96-   --> src/main.rs:20:39  
96+   --> src/main.rs:19:38  
9797   | 
98- 20  |     world.inspector = Some(Inspector(&world.days));
99-    |                                        ^^^^^^^^^^ borrowed value does not live long enough 
98+ 19  |     world.inspector = Some(Inspector(&world.days));
99+    |                                      ^ ^^^^^^^^^^ borrowed value does not live long enough 
100100... 
101- 23 | } 
102-    | - `world.days` dropped here while still borrowed 
103-    | 
104-    = note: values in a scope are dropped in the opposite order they are created 
101+ 22 | } 
102+    | - 
103+    | | 
104+    | `world.days` dropped here while still borrowed 
105+    | borrow might be used here, when `world` is dropped and runs the destructor for type `World<'_>` 
105106``` 
106107
107108You can try changing the order of fields or use a tuple instead of the struct,
@@ -113,8 +114,8 @@ live as long as it does actually were destroyed first.
113114
114115Interestingly, only generic types need to worry about this. If they aren't
115116generic, then the only lifetimes they can harbor are ` 'static ` , which will truly
116- live * forever * . This is why this problem is referred to as * sound  generic drop * .
117- Sound generic drop is enforced by the * drop checker * . As of this writing, some
117+ live _ forever _ . This is why this problem is referred to as _ sound  generic drop _ .
118+ Sound generic drop is enforced by the _ drop checker _ . As of this writing, some
118119of the finer details of how the drop checker validates types is totally up in
119120the air. However The Big Rule is the subtlety that we have focused on this whole
120121section:
@@ -190,12 +191,12 @@ fn main() {
190191} 
191192``` 
192193
193- However, * both *  of the above variants are rejected by the borrow
194+ However, _ both _  of the above variants are rejected by the borrow
194195checker during the analysis of ` fn main ` , saying that ` days `  does not
195196live long enough.
196197
197198The reason is that the borrow checking analysis of ` main `  does not
198- know about the internals of each ` Inspector ` 's ` Drop `  implementation.   As
199+ know about the internals of each ` Inspector ` 's ` Drop `  implementation. As
199200far as the borrow checker knows while it is analyzing ` main ` , the body
200201of an inspector's destructor might access that borrowed data.
201202
@@ -216,7 +217,7 @@ This would help address cases such as the two `Inspector`s above that
216217know not to inspect during destruction.
217218
218219In the meantime, there is an unstable attribute that one can use to
219- assert (unsafely) that a generic type's destructor is * guaranteed *  to
220+ assert (unsafely) that a generic type's destructor is _ guaranteed _  to
220221not access any expired data, even if its type gives it the capability
221222to do so.
222223
@@ -274,8 +275,8 @@ It is sometimes obvious that no such access can occur, like the case above.
274275However, when dealing with a generic type parameter, such access can
275276occur indirectly. Examples of such indirect access are:
276277
277-   *  invoking a callback,
278-   *  via a trait method call.
278+ -  invoking a callback,
279+ -  via a trait method call.
279280
280281(Future changes to the language, such as impl specialization, may add
281282other avenues for such indirect access.)
@@ -334,7 +335,6 @@ worry at all about doing the right thing for the drop checker. However there
334335is one special case that you need to worry about, which we will look at in
335336the next section.
336337
337- 
338338[ rfc1327 ] : https://github.com/rust-lang/rfcs/blob/master/text/1327-dropck-param-eyepatch.md 
339339[ rfc1857 ] : https://github.com/rust-lang/rfcs/blob/master/text/1857-stabilize-drop-order.md 
340- [ `ManuallyDrop ` ] : ../std/mem/struct.ManuallyDrop.html 
340+ [ `manuallydrop ` ] : ../std/mem/struct.ManuallyDrop.html 
0 commit comments