This came up when implementing
Index support in rust-analyzer: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=f3f417b1731dcd6e09970651d8f5f084
It seems that rustc detects that since the parameter type is some kind of integer, only the
u32 impl can apply, and it infers that type. This won't be possible with current Chalk, since it has no concept of integer variables, right?
Yes and no
I've been wondering about this as I started to draft some notes for the "type library"
Probably the easiest thing to do is indeed to extend with a "kind" of type variable that can only be an integral type, but I was wondering if we could model it via predicates too
(e.g., some kind of
IsIntegral(T) predicate that is true for
u32 and friends)
It's a bit annoying since I don't really want to make integral types so special but there might be nothing for it
(There is also an analogous situation around floating point types; we have special variables for them in rustc too)
I think the problem with just having a predicate would be that Chalk would have to iterate through all impls to find potentially matching ones
if it knows the set of possible types, it could specifically look for them
although I guess the impl search could also be extended to know about the predicates
Certainly having variables that cannot be unified with non-integral types would let us reject faster; the compiler still (I think) iterates through all possible impls in this case, but it is able to reject them relatively quickly.
I'm wondering if there is some suitable "generalization" of this concept