# \[MIR\] constant evaluation

**URL:** <https://internals.rust-lang.org/t/mir-constant-evaluation/3143>\
**Category:** compiler\
**Created:** [February 2, 2016, 12:48pm UTC](https://internals.rust-lang.org/t/mir-constant-evaluation/3143 "2016-02-02T12:48:22Z")\
**Posts on this page:** 1\
**Showing post:** 47

<div class="post-metadata">

**Author:** ![eddyb](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/eddyb/32/8411_2.png) [@eddyb](https://internals.rust-lang.org/u/eddyb)\
**Post date:** [February 11, 2016, 1:46pm UTC](https://internals.rust-lang.org/t/mir-constant-evaluation/3143/47 "2016-02-11T13:46:38Z")

</div>

My question was about whether `Foo<X>` in two different places produces the same type or not.

1. These can be in two different crates _using the crate with the definition of `Foo`_, with no way to communicate with each-other.

2. 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:

```rust
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/](https://www.reddit.com/r/rust/comments/907a6d/thoughts_on_compiletime_function_evaluation_and/e2pdqnt/) (you might want to read that comment too)

---

_[View the full topic](https://internals.rust-lang.org/t/mir-constant-evaluation/3143)._
