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

internal compiler error: type_of with ty_param #10954

Closed
bstrie opened this issue Dec 13, 2013 · 4 comments
Closed

internal compiler error: type_of with ty_param #10954

bstrie opened this issue Dec 13, 2013 · 4 comments
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@bstrie
Copy link
Contributor

bstrie commented Dec 13, 2013

There was an old closed bug with this title, I've opened a new issue rather than reopening that one.

Compiling this file exhibits the bug (received from IRC, not minimized yet):

#[allow(dead_code, unused_variable)];

use std::libc::{c_void, c_char};
use std::c_str::{CString};
use std::cast::{transmute};
use std::ptr::{null};

struct _DBusCon;
struct _DBusMsg;

#[repr(C)]
enum DBusHandlerResult {
    DBusHandlerResultHandled,
    DBusHandlerResultNotYetHandled,
    DBusHandlerResultNeedMemory,
}

struct _DBusObjectPathVTable<T> {
    unreg_func: extern "C" fn(con: *_DBusCon, data: *_data<T>),
    msg_func: extern "C" fn(con: *_DBusCon, mes: *_DBusMsg, data: *_data<T>) -> DBusHandlerResult,
    dbus_internal_pad1: *c_void,
    dbus_internal_pad2: *c_void,
    dbus_internal_pad3: *c_void,
    dbus_internal_pad4: *c_void,
    dbus_internal_pad5: *c_void,
}

struct DBusCon {
    priv raw: *_DBusCon,
}

impl DBusCon {
    fn reg_obj_path<T>(&self, path: &str, msg_func: |DBusMsg,&T| -> DBusHandlerResult, unreg_func: |&T|, data: ~T) {
        unsafe {
            let vtable: ~_DBusObjectPathVTable<T> = ~_DBusObjectPathVTable {
                unreg_func: _unreg_func,
                msg_func: _msg_func,
                dbus_internal_pad1: null(),
                dbus_internal_pad2: null(),
                dbus_internal_pad3: null(),
                dbus_internal_pad4: null(),
                dbus_internal_pad5: null(),
            };
            let _path = path.to_c_str().unwrap();
            let _vtable: *_DBusObjectPathVTable<T> = transmute(vtable);
            let _data = ~_data {
                msg_func: msg_func,
                unreg_func: unreg_func,
                path: _path,
                data: data,
                vtable: _vtable,
            };
            let __data: *_data<T> = transmute(_data);
        }
    }
}

extern "C" fn _msg_func<T>(con: *_DBusCon, _msg: *_DBusMsg, data: *_data<T>) -> DBusHandlerResult {
    unsafe {
        let msg = DBusMsg::new(_msg);
        ((*data).msg_func)(msg, (*data).data)
    }
}
extern "C" fn _unreg_func<T>(con: *_DBusCon, data: *_data<T>) {
    unsafe {
        ((*data).unreg_func)((*data).data);
        CString::new((*data).path, true);
        let d: ~_data<T>  = transmute(data);
        let v: ~_DBusObjectPathVTable<T> = transmute(d.vtable);
    }
}

struct _data<'a, T> {
    msg_func: 'a |DBusMsg,&T| -> DBusHandlerResult,
    unreg_func: 'a |&'a T|,
    path: *c_char,
    data: ~T,
    vtable: *_DBusObjectPathVTable<T>,
}

struct DBusMsg {
    priv raw: *_DBusMsg,
}

impl DBusMsg {
    fn new(raw: *_DBusMsg) -> DBusMsg {
        DBusMsg { raw: raw }
    }
}

fn main() {}

Compiler output:

error: internal compiler error: type_of with ty_param
This message reflects a bug in the Rust compiler.
We would appreciate a bug report: https://github.com/mozilla/rust/wiki/HOWTO-submit-a-Rust-bug-report
task 'rustc' failed at 'explicit failure', /root/catacombs/scrap/rust/src/libsyntax/diagnostic.rs:102
task '<main>' failed at 'explicit failure', /root/catacombs/scrap/rust/src/librustc/lib.rs:393
@mahkoh
Copy link
Contributor

mahkoh commented Dec 13, 2013

#[allow(dead_code)];

extern "C" fn a<T>(_: *A<T>) { }

struct A<'a, T> {
    a: 'a |&T|,
}

fn main() { }

Same error. Remove extern "C" to make it work.

@mahkoh
Copy link
Contributor

mahkoh commented Dec 13, 2013

#[allow(dead_code)];
use std::libc::c_void;
use std::cast::transmute;

extern "C" fn a<T>(a: *c_void) {
    unsafe {
        let _: *A<T> = transmute(a);
    }
}

struct A<'a, T> {
    a: &'a T,
}

fn main() { }


task 'rustc' failed at 'assertion failed: !ty::type_has_params(t)', /build/rust-git/src/rust/src/librustc/middle/trans/common.rs:1117
error: internal compiler error: unexpected failure
This message reflects a bug in the Rust compiler. 
We would appreciate a bug report: https://github.com/mozilla/rust/wiki/HOWTO-submit-a-Rust-bug-report
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=1 to get further details and report the results to github.com/mozilla/rust/issues
task '<main>' failed at 'explicit failure', /build/rust-git/src/rust/src/librustc/lib.rs:393

Edit: Same thing with a: &'a T replaced by a: T.

Edit: Replacing "C" by "Rust" produces: internal compiler error: unimplemented Foreign functions with Rust ABI

@huonw
Copy link
Member

huonw commented Jan 20, 2014

The following fails with the type_of with ty_param error:

extern "C" fn foo<T>(_: T) {}

fn main() {}

@alexcrichton
Copy link
Member

Closed by 8f3f666, foreign functions can't have type parameters right now

flip1995 pushed a commit to flip1995/rust that referenced this issue Jun 30, 2023
[`derivable_impls`]: don't lint if `default()` call expr unsize-coerces to trait object

Fixes rust-lang#10158.

This fixes a FP where the derive-generated Default impl would have different behavior because of unsize coercion from `Box<T>` to `Box<dyn Trait>`:
```rs
struct S {
  x: Box<dyn std::fmt::Debug>
}
impl Default for S {
  fn default() -> Self {
    Self {
      x: Box::<()>::default()
     // ^~ Box<()> coerces to Box<dyn Debug>
     // #[derive(Default)] would call Box::<dyn Debug>::default()
    }
  }
}
```
(this intentionally only looks for trait objects `dyn` specifically, and not any unsize coercion, e.g. `&[i32; 5]` to `&[i32]`, because that breaks existing tests and isn't actually problematic, as far as I can tell)

changelog: [`derivable_impls`]: don't lint if `default()` call expression unsize-coerces to trait object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

4 participants