Skip to content

ICE typechecking closure object with bound lifetime #63031

Description

@alexreg

I don't think this was previously submitted as an issue, though it was mentioned on the Rust Internals forum.

trait Lf<'a> { type Type; }

struct F32;
impl<'a> Lf<'a> for F32 { type Type = f32; }

struct RefI32;
impl<'a> Lf<'a> for RefI32 { type Type = &'a i32; }

fn add_closure<T: for<'b> Lf<'b> + 'static>(v: &mut Vec<Box<for<'a> FnMut(<T as Lf<'a>>::Type)>>) {
    v.push(Box::new(move |_| {
    }));
}

fn main() {
    // bug? compiler can't seem to deduce <F32 as Lf<'a>>::Type == f32 nor <RefI32 as Lf<'a>>::Type == &'a i32
    let mut v1 = Vec::<Box<for<'a> FnMut(<F32 as Lf<'a>>::Type)>>::new();
    let mut v2 = Vec::<Box<for<'a> FnMut(<RefI32 as Lf<'a>>::Type)>>::new();
    add_closure::<F32>(&mut v1);
    add_closure::<RefI32>(&mut v2);
}

This crashes both on stable and latest nightly.

error: internal compiler error: src/librustc/traits/codegen/mod.rs:55: Encountered error `OutputTypeParameterMismatch(Binder(<[closure@src/main.rs:10:21: 11:6] as std::ops::FnMut<(<F32 as Lf<'_>>::Type,)>>), Binder(<[closure@src/main.rs:10:21: 11:6] as std::ops::FnMut<(f32,)>>), Sorts(ExpectedFound { expected: f32, found: <F32 as Lf<'_>>::Type }))` selecting `Binder(<[closure@src/main.rs:10:21: 11:6] as std::ops::FnMut<(f32,)>>)` during codegen

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:646:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: aborting due to previous error

Playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)A-codegenArea: Code generationC-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