Can't move a closure into a spawned thread

move doesn't extend any lifetimes. Ownership and lifetimes are orthogonal. For example &mut must be moved to remain mutable, but that doesn't make its target live any longer. You can own MutexGuard<'_> or Cow<'tmp>, but end up with dangling pointers if you force them to live for an arbitrary lifetime.

Note that any lifetime bounds, including 'static, apply only to references and types containing references. They do nothing when applied to self-contained types. This means that String is not 'static, but rather it isn't affected by any lifetime bound. And on the other hand, owning a type doesn't mean you control its lifetime. You can own Box<&'tmp i32>, but not be able to use it beyond the 'tmp scope of its content.

5 Likes