Skip to content

ICE when abusing CoerceUnsized through specialization #44861

Closed
@arielb1

Description

@arielb1

I was attempting to figure out the feature landscape for #27941, and I found this ICE when playing with it and specialization:

Code

#![feature(specialization)]
#![feature(unsize, coerce_unsized)]

use std::ops::CoerceUnsized;
use std::marker::Unsize;

pub struct SmartassPtr<A: Smartass+?Sized>(A::Data);

pub trait Smartass {
    type Data;
    type Data2: CoerceUnsized<*const [u8]>;
}

pub trait MaybeObjectSafe {
// fn not_object_safe(self: SmartassPtr<Self>);
}

impl MaybeObjectSafe for () {}

impl<T> Smartass for T {
    type Data = <Self as Smartass>::Data2;
    default type Data2 = ();
}

impl Smartass for () {
    type Data2 = *const [u8; 1];
}

impl Smartass for MaybeObjectSafe {
    type Data = *const [u8];
    type Data2 = *const [u8; 0];
}

impl<U: Smartass+?Sized, T: Smartass+?Sized> CoerceUnsized<SmartassPtr<T>> for SmartassPtr<U>
    where <U as Smartass>::Data: std::ops::CoerceUnsized<<T as Smartass>::Data>
{}

pub fn conv(s: SmartassPtr<()>) -> SmartassPtr<MaybeObjectSafe> {
    s
}

fn main() {
}

ICE:

error: internal compiler error: /checkout/src/librustc_trans/collector.rs:820: find_vtable_types_for_unsizing: invalid coercion <() as Smartass>::Data -> <MaybeObjectSafe as Smartass>::Data

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: rustc 1.22.0-nightly (6c476ce46 2017-09-25) running on x86_64-unknown-linux-gnu

thread 'rustc' panicked at 'Box<Any>', /checkout/src/librustc_errors/lib.rs:492:8
note: Run with `RUST_BACKTRACE=1` for a backtrace

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-specializationArea: Trait impl specializationC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.F-coerce_unsizedThe `CoerceUnsized` traitF-specialization`#![feature(specialization)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️glacierICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions