Skip to content

Commit 86b1c87

Browse files
timotree3ehuss
authored andcommitted
Copy-edit subtyping.md
1 parent ea95076 commit 86b1c87

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/subtyping.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ All it does is take a mutable reference and a value and overwrite the referent w
244244
What's important about this function is that it creates a type equality constraint. It
245245
clearly says in its signature the referent and the value must be the *exact same* type.
246246

247-
Meanwhile, in the caller we pass in `&mut &'static str` and `&'spike_str str`.
247+
Meanwhile, in the caller we pass in `&mut &'static str` and `&'world str`.
248248

249249
Because `&mut T` is invariant over `T`, the compiler concludes it can't apply any subtyping
250250
to the first argument, and so `T` must be exactly `&'static str`.
@@ -263,9 +263,9 @@ So the compiler decides that `&'static str` can become `&'b str` if and only if
263263
`&'static str` is a subtype of `&'b str`, which will hold if `'static: 'b`.
264264
This is true, so the compiler is happy to continue compiling this code.
265265

266-
As it turns out, the argument for why it's ok for Box (and Vec, Hashmap, etc.) to be covariant is pretty similar to the argument for why it's ok for lifetimes to be covariant: as soon as you try to stuff them in something like a mutable reference, they inherit invariance and you're prevented from doing anything bad.
266+
As it turns out, the argument for why it's ok for Box (and Vec, HashMap, etc.) to be covariant is pretty similar to the argument for why it's ok for lifetimes to be covariant: as soon as you try to stuff them in something like a mutable reference, they inherit invariance and you're prevented from doing anything bad.
267267

268-
However Box makes it easier to focus on by-value aspect of references that we partially glossed over.
268+
However Box makes it easier to focus on the by-value aspect of references that we partially glossed over.
269269

270270
Unlike a lot of languages which allow values to be freely aliased at all times, Rust has a very strict rule: if you're allowed to mutate or move a value, you are guaranteed to be the only one with access to it.
271271

@@ -279,7 +279,7 @@ world = hello;
279279
```
280280

281281
There is no problem at all with the fact that we have forgotten that `hello` was alive for `'static`,
282-
because as soon as we moved `hello` to a variable that only knew he it was alive for `'b`,
282+
because as soon as we moved `hello` to a variable that only knew it was alive for `'b`,
283283
**we destroyed the only thing in the universe that remembered it lived for longer**!
284284

285285
Only one thing left to explain: function pointers.

0 commit comments

Comments
 (0)