Skip to content

ICE: Failed to unify Obligation(...) and ProjectionPredicate(...) in projection #24204

Closed
@stevenblenkinsop

Description

@stevenblenkinsop

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions