Okay, @bluss and @talchas kindly explained this to me on IRC.
The problem is in the granularity of the drop-checking rules, which require A
to strictly outlive B
. From the point of view of that code, A
and B
have the same lifetime, as if one had written:
struct A;
struct B<'a>(&'a A);
impl<'a> Drop for B<'a> {
fn drop(&mut self) {}
}
fn main() {
let (a, b);
a = A;
b = B(&a);
}
The reason the presence of the Drop
impl matters is that, when it's only references involved, it's permissible for reference and referent to have identical lifetimes: the reference can't be used unsafely. Introducing a Drop
impl to the situation requires the referent to strictly outlive the reference, to ensure there is a clear order in which to run drop
methods.