Closed
Description
Just to note: there appear to be two ICEs in here, but I don't know if they have the same underlying cause or not. The code for the second is included, just commented-out. The first error:
error: internal compiler error: src\librustc_trans\type_of.rs:157: Unexpected tail in unsized_info_ty: <Slice as Structure<Utf16>>::RefTarget for ty=SeStr<Slice, Utf16>
...
thread 'rustc' panicked at 'Box<Any>', src\librustc_errors\lib.rs:417
The second error which appears if you manually instantiate the generics:
error: internal compiler error: unexpected panic
...
thread 'rustc' panicked at 'assertion failed: tail.has_param_types() || tail.has_self_ty()', src\librustc\ty\layout.rs:1557
The code:
/*!
Compiled with `rustc run-aground.rs`.
Tested against:
- 1.15.1 (021bd294c 2017-02-08)
- 1.16.0-beta.3 (ecbf0b59e 2017-03-02)
- 1.17.0-nightly (c0b7112ba 2017-03-02)
*/
#![allow(dead_code)]
// Supporting types. Alone, these don't appear to trigger either crash.
trait Structure<E>: Sized where E: Encoding {
type RefTarget: ?Sized;
type FfiPtr;
unsafe fn borrow_from_ffi_ptr<'a>(ptr: Self::FfiPtr) -> Option<&'a Self::RefTarget>;
}
enum Slice {}
impl<E> Structure<E> for Slice where E: Encoding {
type RefTarget = [E::Unit];
type FfiPtr = (*const E::FfiUnit, usize);
unsafe fn borrow_from_ffi_ptr<'a>(_ptr: Self::FfiPtr) -> Option<&'a Self::RefTarget> {
panic!()
}
}
trait Encoding {
type Unit: Unit;
type FfiUnit;
}
trait Unit {}
enum Utf16 {}
impl Encoding for Utf16 {
type Unit = Utf16Unit;
type FfiUnit = u16;
}
struct Utf16Unit(pub u16);
impl Unit for Utf16Unit {}
// Replace `/*` with `//*` to uncomment a block. `Error 1` shows the first
// error. `Error 2` shows a *different* error after I manually instantiate the
// generics. `Works` is what happens when I also replace some of the indirect
// types with the types they should resolve to.
// Error 1:
//*
type SUtf16Str = SeStr<Slice, Utf16>;
struct SeStr<S, E> where S: Structure<E>, E: Encoding {
_data: S::RefTarget,
}
impl<S, E> SeStr<S, E> where S: Structure<E>, E: Encoding {
pub unsafe fn from_ptr<'a>(_ptr: S::FfiPtr) -> Option<&'a Self> {
panic!()
}
}
// */
// Error 2:
/*
struct SUtf16Str {
_data: <Slice as Structure<Utf16>>::RefTarget,
}
impl SUtf16Str {
pub unsafe fn from_ptr<'a>(ptr: <Slice as Structure<Utf16>>::FfiPtr)
-> Option<&'a Self> {
std::mem::transmute::<Option<&[<Utf16 as Encoding>::Unit]>, _>(
<Slice as Structure<Utf16>>::borrow_from_ffi_ptr(ptr))
}
}
// */
// Works:
/*
struct SUtf16Str {
_data: [<Utf16 as Encoding>::Unit],
}
impl SUtf16Str {
pub unsafe fn from_ptr<'a>(
_ptr: (*const <Utf16 as Encoding>::FfiUnit, usize),
) -> Option<&'a Self> {
panic!()
}
}
// */
fn main() {
const TEXT_U16: &'static [u16] = &[];
let _ = unsafe { SUtf16Str::from_ptr((TEXT_U16.as_ptr(), TEXT_U16.len())).unwrap() };
}
This was mostly tested and reduced with:
rustc 1.17.0-nightly (c0b7112ba 2017-03-02)
binary: rustc
commit-hash: c0b7112ba246d96f253ba845d91f36c0b7398e42
commit-date: 2017-03-02
host: i686-pc-windows-gnu
release: 1.17.0-nightly
LLVM version: 3.9
I won't bother to include the backtraces of the crashes, since it's just "drop" over and over again... I assume backtraces don't work, not that drop
is somehow now the compiler's entry point and only function.
The closest issue I could find was #16812, which is marked closed. Also, this doesn't involve an enum
, and appears to depend on generics and a trait, since once you remove those, it goes away.