The following code runs fine:
fn set<'a, 'b>(dest: &'b mut &'a i32, src: &'a i32) where 'a: 'b {
*dest = src;
}
fn main() {
let i : i32 = 0;
{
let mut r : &i32 = &5;
set(&mut r, &i);
}
}
and that makes sense to me: 'a : 'b
means "'a encloses 'b".
Or so I thought. If I replace where 'a : 'b
with the reverse, where 'b : 'a
, the program still compiles. Clearly the lifetime of i
encloses that of r
, but 'b
does not enclose `'a'.
I assumed that the appearance of the type &'b mut &'a i32
in the argument list would cause Rust to infer that 'a
must enclose 'b
, and then my contrary constraint in the where
clause would essentially make 'a
and 'b
identical: if a < b and b < a, then a == b. But that's not what's going on either.
So I'm obviously missing something pretty fundamental here.
[edit: I'm re-reading the appropriate section from the Rustonomicon so I'll be a little more likely to be able to understand whatever explanations are offered]