Closed
Description
Came across this error (ab)using the type system in the following way:
#![allow(dead_code)]
trait MultiDispatch<T> {
type O;
}
trait Trait {
type A: MultiDispatch<Self::B, O = Self>;
type B;
fn new<U>(u: U) -> <Self::A as MultiDispatch<U>>::O where Self::A : MultiDispatch<U>;
}
fn test<T: Trait<B=i32>>(b: i32) -> T where T::A : MultiDispatch<i32> { T::new(b) }
fn main() {}
This created the following ICE:
<anon>:14:73: 14:79 error: internal compiler error: Failed to unify `Obligation(predicate=<<T as Trait>::A as MultiDispatch<_>>::O,depth=0)` and `ProjectionPredicate(<<T as Trait>::A as MultiDispatch<<T as Trait>::B>>::O, T)` in projection: expected associated type, found i32
<anon>:14 fn test<T: Trait<B=i32>>(b: i32) -> T where T::A : MultiDispatch<i32> { T::new(b) }
^~~~~~
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'Box<Any>', /home/rustbuild/src/rust-buildbot/slave/beta-dist-rustc-linux/build/src/libsyntax/diagnostic.rs:130
Note that changing test
to:
fn test<T: Trait<B=i32>>(b: i32) -> T where T::A : MultiDispatch<i32, O = T> { T::new(b) }
so that it matches the bound on Trait::A
fixes the issue. This makes the whole where
clause appear redundant, but removing it causes an error, apparently ignoring the bound expressed on Trait::A
(though clearly not completely, since the bound on Trait::A
is still able to cause the original ICE). This is probably an instance of issue #24159.