Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE typechecking closure object with bound lifetime #63031

Closed
alexreg opened this issue Jul 27, 2019 · 4 comments
Closed

ICE typechecking closure object with bound lifetime #63031

alexreg opened this issue Jul 27, 2019 · 4 comments
Labels
A-closures Area: Closures (`|…| { … }`) A-codegen Area: Code generation C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@alexreg
Copy link
Contributor

alexreg commented Jul 27, 2019

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

@alexreg alexreg changed the title ICE in typechecking ICE typechecking closure object with bound lifetime Jul 27, 2019
@Centril Centril added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-nominated A-closures Area: Closures (`|…| { … }`) A-codegen Area: Code generation labels Jul 27, 2019
@nagisa
Copy link
Member

nagisa commented Aug 1, 2019

Appears to be failing all the way back to at least 1.10.0.

@nagisa nagisa added P-medium Medium priority and removed I-nominated labels Aug 1, 2019
@nagisa
Copy link
Member

nagisa commented Aug 1, 2019

Since the issue is ancient, marking it as P-medium. It would still be great to fix this ICE, regardless.

@alexreg
Copy link
Contributor Author

alexreg commented Aug 1, 2019

@nagisa Indeed... I'm surprised it went without discovery this long. Well, I guess it's a tad obscure. I'm probably not the best person take this on, but hopefully someone else will.

@jackh726
Copy link
Member

Closing as duplicate of #62529

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: Closures (`|…| { … }`) A-codegen Area: Code generation C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants