And the code will not compile because I use of generic parameter from outer function. What I don't understand is the hint:
error[E0401]: can't use generic parameters from outer function
--> src/main.rs:7:35
|
5 | impl<T> Foo<T> {
| - type parameter from outer function
6 | thread_local! {
7 | static TL: UnsafeCell<Vec<T>> = UnsafeCell::new(Vec::new());
| ^ use of generic parameter from outer function
|
= help: try using a local generic parameter instead
What is a "local generic parameter"? And how do you design thread locals like this(thread local with generic)?
P.S. the compiler will panic if you run the code on stable 1.63.0, I've already create a ticket
The error message probably makes more sense for the result of expanding the macro. (I'm in mobile right now, so please excuse I'm not verifying this myself.) I assume it might involve a function or struct or so [1], defined inside of the method you're in. "Local" generic parameter would then refer to a generic parameter of that inner function or struct.
or maybe the static itself creates such error messages, too? Anyways it's going to be some form of nested itemâŠī¸
AFAICT no, the issue is not a lack of implementation. The technical problem is that linking can't guarantee uniqueness of statics when trying to merge multiple instantiations of a generic with identical sets of type parameters.
I was originally going to use STRING.with(|s| COUNT.with(|c| println!("{}", s.repeat(c))) as the example but ran into a panic because COUNT.with() was calling registry.borrow_mut() while STRINGS.with() had a live registry.borrow().
You should be able to solve that with more RefCells, though, so I'll leave re-entrancy as an exercise for the reader.