Properly pass down immutability info for thread-locals. by EdSchouten · Pull Request #47425 · rust-lang/rust (original) (raw)

Maybe I should take a look at what it might mean to integrate more "properly" into borrowck? It feels like that would likely be very easy to do (i.e., maybe even a smaller diff than what is here).
Or @EdSchouten if you feel like digging you can do some explring on your own. =)

I think the main thing is that this line has to change:

Categorization::StaticItem => {
Ok(())
}

This basically says that a loan of static content can have any lifetime. But in the case of a static item tagged with #[thread_local], we would want to check that the loan lifetime does not exceed current function (mostly, it should be a ReScope, but we might have to be careful around closures).