Skip to content

ICE: unexpected definition #38145

Closed
Closed
@mzji

Description

@mzji

The code breaking compiler:

extern crate byteorder;

use std::io::Result;

use byteorder::{ByteOrder, WriteBytesExt};

pub trait GenericWriteBytesMarker: Sized {}

impl GenericWriteBytesMarker for u16 {}

pub trait GenericWriteBytesExt<T>: WriteBytesExt
    where T: GenericWriteBytesMarker
{
    fn write_val<BO>(&mut self, val: &T) -> Result<()> where BO: ByteOrder;
}

impl<W: WriteBytesExt + ?Sized> GenericWriteBytesExt<u16> for W {
    #[inline]
    fn write_val<BO>(&mut self, val: &u16) -> Result<()> where BO: ByteOrder {
        self.write_u16::<BO>(*val)
    }
}

pub trait ArrayOrVec: Sized {
    type V: GenericWriteBytesMarker + Sized;

    fn len(&self) -> usize;
    fn to_slice(&self) -> &[Self::V];
}

#[derive(Clone)]
pub enum ArrayTwoU16OrVecU16 {
    Array([u16; 2]),
    Vec(Vec<u16>),
}

impl ArrayOrVec for ArrayTwoU16OrVecU16 {
    type V = u16;

    #[inline]
    fn len(&self) -> usize {
        match self {
            &ArrayTwoU16OrVecU16::Array(array) => array.len(),
            &ArrayTwoU16OrVecU16::Vec(ref vec) => vec.len(),
        }
    }

    #[inline]
    fn to_slice(&self) -> &[u16] {
        match self {
            &ArrayTwoU16OrVecU16::Array(ref array) => array,
            &ArrayTwoU16OrVecU16::Vec(ref vec) => vec.as_slice(),
        }
    }
}

impl<AOV: ArrayOrVec> GenericWriteBytesMarker for AOV {} 

impl<W: WriteBytesExt + ?Sized, AOV: ArrayOrVec + Sized>
    GenericWriteBytesExt<AOV> for W
{
    fn write_val<BO>(&mut self, aov: &AOV) -> Result<()>
        where BO: ByteOrder
    {
        for val in aov.to_slice() {
            GenericWriteBytesExt<AOV::V>::write_val::<BO>(&mut self, val)?
        };
        Ok(())
    }
}

// With the following code, the compiler works well:
/*
impl GenericWriteBytesMarker for ArrayTwoU16OrVecU16 {}

impl<W: WriteBytesExt + ?Sized> GenericWriteBytesExt<ArrayTwoU16OrVecU16> for W
{
    fn write_val<BO>(&mut self, aov: &ArrayTwoU16OrVecU16) -> Result<()>
        where BO: ByteOrder
    {
        for &val in aov.to_slice() {
            self.write_val::<BO>(&val)?
        };
        Ok(())
    }
}
*/

fn main() {
    println!("Hello, world!");
}

Cargo.toml

[package]
name = "compiler_confirm"
version = "0.1.0"
authors = ["mzji"]

[dependencies]
byteorder = "0.5.3"

The output of the compiler:

Running "cargo build":
   Compiling compiler_confirm v0.1.0 (file:///C:/Users/MYUSERNAME/Documents/Rust/compiler_confirm)
error: chained comparison operators require parentheses
  --> src\main.rs:66:33
   |
66 |             GenericWriteBytesExt<AOV::V>::write_val::<BO>(&mut self, val)?
   |                                 ^^^^^^^^^^
   |
   = help: use `::<...>` instead of `<...>` if you meant to specify type arguments

error[E0425]: unresolved name `GenericWriteBytesExt`
  --> src\main.rs:66:13
   |
66 |             GenericWriteBytesExt<AOV::V>::write_val::<BO>(&mut self, val)?
   |             ^^^^^^^^^^^^^^^^^^^^ unresolved name
   |
   = help: trait `GenericWriteBytesExt` cannot be used as an expression

error[E0425]: unresolved name `write_val`
  --> src\main.rs:66:41
   |
66 |             GenericWriteBytesExt<AOV::V>::write_val::<BO>(&mut self, val)?
   |                                         ^^^^^^^^^^^^^^^^^ did you mean to call `self.write_val`?

error: internal compiler error: ../src/librustc_typeck\check/mod.rs:4383: unexpected definition: AssociatedTy(DefId { krate: CrateNum(0), node: DefIndex(24) => compiler_confirm/2b369f45766dcbe5ff5c2c5ae6ed4704-exe::ArrayOrVec[0]::V[0] })

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

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'Box<Any>', ../src/librustc_errors/lib.rs:424
stack backtrace:
   0:     0x7ffa908802fa - std::panicking::Location::line::h9363ce800e842170
   1:     0x7ffa9087f784 - std::panicking::Location::line::h9363ce800e842170
   2:     0x7ffa908831dd - std::panicking::rust_panic_with_hook::ha5aed1dfc0e220e3
   3:     0x7ffaa2732910 - <unknown>
   4:     0x7ffaa274900e - rustc_errors::Handler::bug::h620f7270292f0095
   5:     0x7ffa8e873355 - rustc::session::bug_fmt::he2d2f00a4afa9d1e
   6:     0x7ffa8e87318a - rustc::session::bug_fmt::he2d2f00a4afa9d1e
   7:     0x7ffa8e8728fc - rustc::session::bug_fmt::he2d2f00a4afa9d1e
   8:     0x7ffa8ee75aca - rustc_typeck::check::FnCtxt::instantiate_value_path::h4229ac945aebfa55
   9:     0x7ffa8ee5fb2e - rustc_typeck::check::FnCtxt::check_struct_path::hd07032c88b73af38
  10:     0x7ffa8ee5e551 - rustc_typeck::check::FnCtxt::check_struct_path::hd07032c88b73af38
  11:     0x7ffa8ee350ce - rustc_typeck::check::op::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::check_binop::h5bae574a47e9d682
  12:     0x7ffa8ee34557 - rustc_typeck::check::op::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::check_binop::h5bae574a47e9d682
  13:     0x7ffa8ee5ed24 - rustc_typeck::check::FnCtxt::check_struct_path::hd07032c88b73af38
  14:     0x7ffa8ee5e551 - rustc_typeck::check::FnCtxt::check_struct_path::hd07032c88b73af38
  15:     0x7ffa8ee34457 - rustc_typeck::check::op::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::check_binop::h5bae574a47e9d682
  16:     0x7ffa8ee5ed24 - rustc_typeck::check::FnCtxt::check_struct_path::hd07032c88b73af38
  17:     0x7ffa8ee5e551 - rustc_typeck::check::FnCtxt::check_struct_path::hd07032c88b73af38
  18:     0x7ffa8ee742a3 - rustc_typeck::check::FnCtxt::check_block_no_value::h3ac235dc3eaa76c3
  19:     0x7ffa8ee5ea3e - rustc_typeck::check::FnCtxt::check_struct_path::hd07032c88b73af38
  20:     0x7ffa8ee5e551 - rustc_typeck::check::FnCtxt::check_struct_path::hd07032c88b73af38
  21:     0x7ffa8edd8fc4 - rustc_typeck::check::_match::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::check_match::h54f69213176d4c8f
  22:     0x7ffa8ee5ed72 - rustc_typeck::check::FnCtxt::check_struct_path::hd07032c88b73af38
  23:     0x7ffa8ee5e551 - rustc_typeck::check::FnCtxt::check_struct_path::hd07032c88b73af38
  24:     0x7ffa8ee742a3 - rustc_typeck::check::FnCtxt::check_block_no_value::h3ac235dc3eaa76c3
  25:     0x7ffa8ee5ebe3 - rustc_typeck::check::FnCtxt::check_struct_path::hd07032c88b73af38
  26:     0x7ffa8ee5e551 - rustc_typeck::check::FnCtxt::check_struct_path::hd07032c88b73af38
  27:     0x7ffa8edd8fc4 - rustc_typeck::check::_match::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::check_match::h54f69213176d4c8f
  28:     0x7ffa8ee5ed72 - rustc_typeck::check::FnCtxt::check_struct_path::hd07032c88b73af38
  29:     0x7ffa8ee5e551 - rustc_typeck::check::FnCtxt::check_struct_path::hd07032c88b73af38
  30:     0x7ffa8ee73a9f - rustc_typeck::check::FnCtxt::check_decl_initializer::h43ea4d26b2a62ae8
  31:     0x7ffa8ee73beb - rustc_typeck::check::FnCtxt::check_decl_local::h15d42ee7f4d79e8d
  32:     0x7ffa8ee73f37 - rustc_typeck::check::FnCtxt::check_stmt::h155d968e61fdfae6
  33:     0x7ffa8ee7426e - rustc_typeck::check::FnCtxt::check_block_no_value::h3ac235dc3eaa76c3
  34:     0x7ffa8ee5ea3e - rustc_typeck::check::FnCtxt::check_struct_path::hd07032c88b73af38
  35:     0x7ffa8ee5e551 - rustc_typeck::check::FnCtxt::check_struct_path::hd07032c88b73af38
  36:     0x7ffa8ee73eab - rustc_typeck::check::FnCtxt::check_stmt::h155d968e61fdfae6
  37:     0x7ffa8ee7426e - rustc_typeck::check::FnCtxt::check_block_no_value::h3ac235dc3eaa76c3
  38:     0x7ffa8ee5ea3e - rustc_typeck::check::FnCtxt::check_struct_path::hd07032c88b73af38
  39:     0x7ffa8ee5e551 - rustc_typeck::check::FnCtxt::check_struct_path::hd07032c88b73af38
  40:     0x7ffa8ee3e32c - <rustc_typeck::check::GatherLocalsVisitor<'a, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::visit_ty::hdcba5921c886305a
  41:     0x7ffa8ee3c68b - rustc_typeck::check::check_drop_impls::hb6e6926f4342f9e2
  42:     0x7ffa8ee40a06 - rustc_typeck::check::check_item_body::h1e039ede2f960fb9
  43:     0x7ffa8ee3936d - rustc_typeck::check::check_item_bodies::hd22adb7703cc56d7
  44:     0x7ffa8eec01d0 - rustc_typeck::check_crate::h92f6bdfe03b6afba
  45:     0x7ffa917db10e - rustc_driver::driver::count_nodes::h84f03318ea2320a8
  46:     0x7ffa9172f92b - <unknown>
  47:     0x7ffa917b7316 - rustc_driver::driver::compile_input::h8e119234b60571d5
  48:     0x7ffa918088c7 - rustc_driver::run_compiler::hbdfc4f84e2e0f4b9
  49:     0x7ffa916ed6ae - <unknown>
  50:     0x7ffa90885c11 - _rust_maybe_catch_panic
  51:     0x7ffa91717134 - <unknown>
  52:     0x7ffa9087d84e - std::sys::imp::thread::Thread::new::h6aed1fb5ec32a04f
  53:     0x7ffac1388363 - BaseThreadInitThunk

error: Could not compile `compiler_confirm`.

To learn more, run the command again with --verbose.

"cargo build" completed with code 101
It took approximately 0.712 seconds

rustc info:

rustc 1.15.0-nightly (1c448574b 2016-11-28)
binary: rustc
commit-hash: 1c448574bc668b0de70ed75223bf8798d17bf058
commit-date: 2016-11-28
host: x86_64-pc-windows-msvc
release: 1.15.0-nightly
LLVM version: 3.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    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