-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Sized bound from scoped_thread_local! and ScopedKey #25232
Conversation
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
Fixes rust-lang#25193 Fix whitespace
Unfortunately it's still more limited than I'd like: this is a case where HKT would help, since the "type" of a scoped thread local, should actually be a type constructor, which would produce a concrete type given an arbitraty lifetime. However, I think it's also possible to implement the same thing using macros so that the following would be possible:
This allows more complicated uses: The only tricky part is how to check that |
Now that I recall the limitation that we're using OS TLS as a backend sometimes, which has the requirement that the pointer is word-sized, I'm now actually somewhat more hesitant about this. This is adding an extra layer of indirection in all cases, which may not always be desired. I think the problems you pointed out about still being able to specify a lifetime are still relevant to this primitive, so it may be best to fix those first perhaps? |
@alexcrichton Yes I hadn't noticed that at first either. However, without specialization or negative trait bounds it's not possible to get optimal behaviour in both cases, so I opted for an extra layer of indirection. I did manage to implement the enhancement to "scoped_thread_local!": The implementation might be too much of a hack to get merged in right now (what do you think?) although mostly because of unnecessary limitations in the compiler, which would not be too much work to fix:
|
Oh wow, interesting! I do suspect, however, that that's a bit complicated to land in-tree right now. I believe that adding a lifetime token for a macro may not be too hard (would require an RFC, but seems backwards compatible), but the hygiene problem may be difficult to overcome. |
I opened an issue a little while back about the lack of a lifetime macro fragment. #23956 |
Ok for now I'm going to close this due to the need for the double-indirection in sized types, I think we may be able to explore some more macro-fun possibilities here in the future, but for now limiting this to word-sized storage is the OS limitation. |
Fixes #25193