You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/subtyping.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -244,7 +244,7 @@ All it does is take a mutable reference and a value and overwrite the referent w
244
244
What's important about this function is that it creates a type equality constraint. It
245
245
clearly says in its signature the referent and the value must be the *exact same* type.
246
246
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`.
248
248
249
249
Because `&mut T` is invariant over `T`, the compiler concludes it can't apply any subtyping
250
250
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
263
263
`&'static str` is a subtype of `&'b str`, which will hold if `'static: 'b`.
264
264
This is true, so the compiler is happy to continue compiling this code.
265
265
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.
267
267
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.
269
269
270
270
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.
271
271
@@ -279,7 +279,7 @@ world = hello;
279
279
```
280
280
281
281
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`,
283
283
**we destroyed the only thing in the universe that remembered it lived for longer**!
284
284
285
285
Only one thing left to explain: function pointers.
0 commit comments