Skip to content

Compiler error with float structs and foreign functions #6753

@jeremyletang

Description

@jeremyletang

I'm trying de do a binding for a c library and i get an error when i try to pass a struct of float to a C foreign function. This is the error given by rustc :

rust: task failed at 'index out of bounds: the len is 2 but the index is 2', /rust_install/rust-0.6/src/librustc/middle/trans/cabi_x86_64.rs:248
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=1,::rt::backtrace to get further details and report the results to github.com/mozilla/rust/issues
rust: task failed at 'explicit failure', /rust_install/rust-0.6/src/librustc/rustc.rc:357
rust: domain main @0x13863c0 root task failed

And this is the code who produce the error

#[link(name = "my_lib",
       vers = "0.1")];

#[crate_type = "lib"];

use core::libc::{c_void};

pub extern "C" {
    fn rect_create() -> *rect;
    fn set_point(rect : *rect, pos : Vector2f) -> ();
}

pub struct rect {
    This : *c_void
}

pub struct Vector2f {
    x : f32,
    y : f32
}

pub struct RectWrapped {
    priv rect : *rect
}

impl RectWrapped {
    pub fn new() -> RectWrapped {
        RectWrapped {rect :  unsafe {rect_create()}}
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationI-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