I'm going to guess this has come up before but I don't immediately see why this wouldn't work.
TLS data in Rust is a little painful to access, because you have to go through
LocalKey::with and introduce a lambda and a level of nesting to access your data. This prevents you from writing idiomatic code that could return references to thread locals, even in cases where this would be safe.
Why not have a
'thread lifetime, which would automatically be associated with references taken of a thread local variable? As far as I can tell the semantics wouldn't be too complicated:
'thread would be longer than every lifetime except
'static. Because thread spawning requires
'static, there would be no danger of thread local data being accessed across threads. But the compiler would still be able to understand that thread locals will live longer than a stack variable, and would be safe to return from a function and access without a