Skip to content

ICE when attempting to manually implement FnMut #21461

Closed
@blaenk

Description

@blaenk
Contributor

While trying to figure out how to properly implement FnMut for this struct I ran into this ICE. I still don't know how to properly implement it, chances are I was doing it wrong, but I imagine that an ICE isn't expected in any case so I decided to post this up in case it hasn't been brought up.

#![feature(unboxed_closures)]

struct VecEnv<'a> {
    vec: Vec<i32>,
}

impl<'a> FnMut(&mut i32, &i32) -> i32 for VecEnv<'a> {
    extern "rust-call" fn call_mut(&mut self, (output, text): (&mut i32, &i32)) -> i32 {
        println!("CLOSURE");
        1i32
    }
}

fn main() {}
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'assertion failed: !generic_bounds.has_escaping_regions()', /build/rust-git/src/rust/src/librustc_typeck/check/mod.rs:1784

playpen

Activity

added
A-closuresArea: Closures (`|…| { … }`)
I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
on Jan 21, 2015
tamird

tamird commented on Apr 21, 2015

@tamird
Contributor

No longer gets that far:

$ rustc main.rs
main.rs:7:35: 7:38 error: associated type bindings are not allowed here [E0229]
main.rs:7 impl<'a> FnMut(&mut i32, &i32) -> i32 for VecEnv<'a> {
                                            ^~~
error: aborting due to previous error

@blaenk can you update this?

apasel422

apasel422 commented on Oct 24, 2015

@apasel422
Contributor

I'm not sure if this can really be reproduced today. I got the following to compile:

#![feature(core, unboxed_closures)]

struct VecEnv<'a> {
    vec: Vec<i32>,
    marker: std::marker::PhantomData<&'a ()>,
}

impl<'a, 'b, 'c> FnOnce<(&'b mut i32, &'c i32)> for VecEnv<'a> {
    type Output = i32;

    extern "rust-call" fn call_once(self, (output, text): (&'b mut i32, &'c i32)) -> i32 {
        println!("CLOSURE");
        1i32
    }
}

fn main() {}
arielb1

arielb1 commented on Oct 24, 2015

@arielb1
Contributor

@apasel422

They used the "impl Fn(i32) -> i32 for XYZ" syntax.

arielb1

arielb1 commented on Oct 24, 2015

@arielb1
Contributor

duplicate of #24682 + #26638.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

        Participants

        @blaenk@Aatch@tamird@arielb1@apasel422

        Issue actions

          ICE when attempting to manually implement FnMut · Issue #21461 · rust-lang/rust