Skip to content

ICE using associated type from higher ranked trait #70120

Closed
@lord

Description

@lord

Apologies if this is already reported somewhere; couldn't find it during a quick search.

Getting an internal compiler error for this code (playground):

pub trait MyTrait<'a> {
    type Output: 'a;
    fn gimme_value(&self) -> Self::Output;
}

pub struct MyStruct;

impl<'a> MyTrait<'a> for MyStruct {
    type Output = &'a usize;
    fn gimme_value(&self) -> Self::Output {
        unimplemented!()
    }
}

fn meow<T, F>(t: T, f: F)
where
    T: for<'any> MyTrait<'any>,
    F: for<'any2> Fn(<T as MyTrait<'any2>>::Output),
{
    let v = t.gimme_value();
    f(v);
}

fn main() {
    let struc = MyStruct;
    meow(struc, |foo| {
        println!("{:?}", foo);
    })
}

The error reads:

error: internal compiler error: src/librustc_infer/traits/codegen/mod.rs:61: Encountered error `OutputTypeParameterMismatch(Binder(<[closure@src/main.rs:26:17: 28:6] as std::ops::Fn<(<MyStruct as MyTrait<'_>>::Output,)>>), Binder(<[closure@src/main.rs:26:17: 28:6] as std::ops::Fn<(&usize,)>>), Sorts(ExpectedFound { expected: &usize, found: <MyStruct as MyTrait<'_>>::Output }))` selecting `Binder(<[closure@src/main.rs:26:17: 28:6] as std::ops::Fn<(&usize,)>>)` during codegen

Tested in 1.42.0, 1.43.0-beta.1, and 1.44.0-nightly (2020-03-17 7ceebd98c6a15ae30e77)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-codegenArea: Code generationA-trait-systemArea: Trait systemC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions