-
Notifications
You must be signed in to change notification settings - Fork 13.3k
TypeId only allows sized types that have a 'static bound #20168
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
Comments
I don't really think it would be possible to do usefully. Since lifetimes have subtype relations, you really want to be able to ask "outlives" (a la instanceof) questions about them, which isn't something well-suited to simple equality. And the case of recursive functions with lifetimes (so lifetimes aren't always monomorphizable) means that I don't think you could assign a globally unique |
You are probably right that it might not be possible to do usefully but I believe that for my purposes I would be happy if I could retrieve the TypeId for Foo<'static> if I have a Foo<'a>. I believe I could handle any other lifetime issues manually. Being unable to retrieve any sort of TypeId at all once you have a non-static type feels a bit limiting though. |
This requires an RFC I think. |
Maybe have an |
I think it would be good to get some movement on this. The I can put together an RFC if nobody's actively working on it. |
For anyone looking for a workaround to this limitation I am using this pattern to get |
I played around with a similar idea, but didn't like that it's possible to implement incorrectly, which in my case would mean interpreting memory incorrectly. Which I guess is why you've marked it as I'd like to propose simply removing the |
We've accepted an RFC for this: https://github.com/rust-lang/rfcs/blob/master/text/1849-non-static-type-id.md, tracking issue #41875. |
Ran into the 'static bound when trying to use std::any::Any with types containing borrowed references. The original issue about TypeId indicates that it would be possible but might be problematic to implement #9913.
It would seem that now with DST it might also be possible to get the TypeId of unsized types as well (might also be relevant for TyDesc which allows non 'static bound but not DST).
The text was updated successfully, but these errors were encountered: