My question was about whether Foo<X>
in two different places produces the same type or not.
-
These can be in two different crates using the crate with the definition of
Foo
, with no way to communicate with each-other. -
It gets even worse with traits, because all impls of
Trait
are instantiated every time<T as Trait>
is attempted to be resolved.
That would mean impl resolution can succeed once and then fail unless you cached all instantiations.
So you end up with a system where… the value is fixed after being first observed?
But you can only do this in the same crate, as shown by 1. above.
I forget if I’ve used this argument before, but I didn’t expect to actually… prove it’s impossible to generate the same type.
Combine 1 and 2, say you have a crate with:
trait Trait<B> {}
impl<T> Trait<[u8; rand(0, size_of::<T>())]> for T {}
Now different downstream crates will observe different sets of impls, and if you combine two of those crates, you will have broken coherence.
EDIT: XPOST https://www.reddit.com/r/rust/comments/907a6d/thoughts_on_compiletime_function_evaluation_and/e2pdqnt/ (you might want to read that comment too)