Small fixes.

pull/4/head
Edd Barrett 8 years ago
parent 37fe162af1
commit 09274f379d

@ -289,7 +289,7 @@ such rule is as follows:
> `&'q T` if the lifetime of `&'p T` is equal or longer than `&'q T`. > `&'q T` if the lifetime of `&'p T` is equal or longer than `&'q T`.
At our call site, the type of the arguments are `&'s1 str` and `&'s2 str`, and At our call site, the type of the arguments are `&'s1 str` and `&'s2 str`, and
we know that a `&'s1 str' outlives an `&'s2 str`, so we can substitute `&'s1 we know that a `&'s1 str'` outlives an `&'s2 str`, so we can substitute `&'s1
s1` with `&'s2 s2`. After this both arguments are of lifetime `&'s2` and the s1` with `&'s2 s2`. After this both arguments are of lifetime `&'s2` and the
call-site is consistent with the signature of `print_shortest`. call-site is consistent with the signature of `print_shortest`.
@ -356,16 +356,16 @@ res: &'res = shortest(&'s2 s1, &'s2 s2);
But we now have the additional reference to check. We must now prove that the But we now have the additional reference to check. We must now prove that the
returned reference can have the same lifetime as the arguments of lifetime returned reference can have the same lifetime as the arguments of lifetime
'&'s2'. This brings us to a second rule: `&'s2`. This brings us to a second rule:
> The return value of a function `&'r T` can be converted to an argument `&'s T` > The return value of a function `&'r T` can be converted to an argument `&'s T`
> if the lifetime of `&'r T` is equal or shorter than `&'s T`. > if the lifetime of `&'r T` is equal or shorter than `&'s T`.
To make our program compile, we would have to subsitute `res: &'res` for `res: To make our program compile, we would have to subsitute `res: &'res` for `res:
&'s2`, but we can't since `&'res` in fact out-lives `&'s2`. This program is in &'s2`, but we can't since `&'res` in fact out-lives `&'s2`. This program is
fact inconsistent and the compiler rightfully rejects the program because we inconsistent and the compiler rightfully rejects the program because we
try make a reference (`&'res`) which outlives one of the values it refer to try make a reference (`res`) which outlives one of the values it may refer to
(`&'s2`). (`s2`).
[Formally, function return values are said to be *contravariant*, the opposite [Formally, function return values are said to be *contravariant*, the opposite
of *covariant*.] of *covariant*.]

Loading…
Cancel
Save