Skip to content

ICE: manually implementing Fn traits for unit structs #33687

Closed
@jFransham

Description

@jFransham

I know the Fn traits are unstable and are therefore completely allowed to eat my laundry and sell my dog to ISIS, but this is probably an important bug nontheless: on current nightly (rustc 1.8.0 (db2939409 2016-04-11), unless playground doesn't use current nightly), the following code ICEs

#![feature(unboxed_closures)]
#![feature(fn_traits)]

struct Test;

impl FnOnce<(u32, u32)> for Test {
    type Output = u32;

    extern "rust-call" fn call_once(self, (a, b): (u32, u32)) -> u32 {
        a + b
    }
}

fn main() {
    println!("{:?}", Test(1u32, 2u32));
}

It also ICEs with an empty struct definition (struct Test {} instead of struct Test;). The following code does not ICE:

#![feature(unboxed_closures)]
#![feature(fn_traits)]

struct Dummy;
struct Test(Dummy);

impl FnOnce<(u32, u32)> for Test {
    type Output = u32;

    extern "rust-call" fn call_once(self, (a, b): (u32, u32)) -> u32 {
        a + b
    }
}

fn main() {
    println!("{:?}", Test(Dummy)(1u32, 2u32));
}

Error message:

error: internal compiler error: ../src/librustc_trans/adt.rs:430: adt::represent_type called on non-ADT type: u32
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
thread 'rustc' panicked at 'Box<Any>', ../src/libsyntax/errors/mod.rs:584
note: Run with `RUST_BACKTRACE=1` for a backtrace.

playpen: application terminated with error code 101

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