Rules of liveness: about the "discard point"
-
with no drop glue, no "library" code gets executed, so a fortiori, no lifetimes/borrows/w/e are used/dereferenced, so it would be sound for lifetimes of the discardee to be dangling here.
⇒ No need for liveness to extend to this point
-
with drop glue:
-
either the drop glue does somehow refer to that lifetime,
⇒ liveness needs to extend to this discard point,
-
Examples:
-
type T<'lt> = PrintOnDrop<&'lt str>
Code
use ::core::fmt::Debug; use Drop as PrependExtraDropGlue; struct PrintOnDrop<T : Debug>(T); impl<T : Debug> PrependExtraDropGlue for PrintOnDrop<T> { fn drop(&mut self) { dbg!(&self.0); } } // when T = &'lt str, for instance, we have: #[cfg(example)] impl<'lt> PrependExtraDropGlue for PrintOnDrop<&'lt str> { fn drop(&mut self) { /* stuff we don't know about, from the outside */ } }
-
type T<'lt> = MutexGuard<'lt, …>
-
type T<'lt> = impl use<…, 'lt, …> + Trait
-
type T<'lt> = dyn 'lt + Trait or dyn Trait<… 'lt …>
-
-
-
or it is "known not to", so we are kind of back to the "no drop glue" case, and:
⇒ No need for liveness to extend to this point.
-
Examples:
type T<'lt> = (&'lt str, Vec<u8>)
type U<'lt> = Vec<&'lt str>
// <- subtle!
-
-