Skip to content

Commit d7cb40b

Browse files
authored
Merge pull request #157 from chansuke/update-error-diagnostic
Update the diagnostic of `error[E0597]` in dropck.md
2 parents 9c912bf + dc9019c commit d7cb40b

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/dropck.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
We have seen how lifetimes provide us some fairly simple rules for ensuring
44
that 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
88
gets dropped at the same time as another, right? This is why we used the
99
following desugaring of `let` statements:
@@ -35,7 +35,7 @@ let tuple = (vec![], vec![]);
3535

3636
The left vector is dropped first. But does it mean the right one strictly
3737
outlives 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
3939
still be unable to decide what outlives what in case of vector elements, which
4040
are dropped manually via pure-library code the borrow checker doesn't
4141
understand.
@@ -93,15 +93,16 @@ fn main() {
9393

9494
```text
9595
error[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

107108
You 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

114115
Interestingly, only generic types need to worry about this. If they aren't
115116
generic, 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
118119
of the finer details of how the drop checker validates types is totally up in
119120
the air. However The Big Rule is the subtlety that we have focused on this whole
120121
section:
@@ -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
194195
checker during the analysis of `fn main`, saying that `days` does not
195196
live long enough.
196197

197198
The 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
199200
far as the borrow checker knows while it is analyzing `main`, the body
200201
of 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
216217
know not to inspect during destruction.
217218

218219
In 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
220221
not access any expired data, even if its type gives it the capability
221222
to do so.
222223

@@ -274,8 +275,8 @@ It is sometimes obvious that no such access can occur, like the case above.
274275
However, when dealing with a generic type parameter, such access can
275276
occur 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
281282
other avenues for such indirect access.)
@@ -334,7 +335,6 @@ worry at all about doing the right thing for the drop checker. However there
334335
is one special case that you need to worry about, which we will look at in
335336
the 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

Comments
 (0)