Add a type_id intrinsic by alexcrichton · Pull Request #10182 · rust-lang/rust (original) (raw)

Hm, this could get interesting. So in theory the signature of the type_id intrinsic is fn type_id<T: 'static>() -> u64, but this means that callers need to have a 'static bound, which Any currently does not, and apparently you can't make trait Foo: 'static.

This also seems a little limiting to the Any trait to make it only applicable for types which don't have any borrowed pointers inside of them. It looks like the types that we're hashing aren't necessarily the "trans types" in that they've had all their regions substituted, so why can't we hash the regions as well? You could have some possibly equivalent types have different types, but I think that it's fine to have that happen (especially when lots of weird regions are involved).