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

ICE when abusing CoerceUnsized through specialization #44861

Closed
arielb1 opened this issue Sep 26, 2017 · 8 comments · Fixed by #73646
Closed

ICE when abusing CoerceUnsized through specialization #44861

arielb1 opened this issue Sep 26, 2017 · 8 comments · Fixed by #73646
Labels
A-specialization Area: Trait impl specialization C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-coerce_unsized The `CoerceUnsized` trait F-specialization `#![feature(specialization)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way.

Comments

@arielb1
Copy link
Contributor

arielb1 commented Sep 26, 2017

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
@arielb1 arielb1 added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Sep 26, 2017
@TimNN TimNN added the C-bug Category: This is a bug. label Sep 27, 2017
@Seeker14491
Copy link
Contributor

The given code builds fine on current nightly.

@JohnTitor
Copy link
Member

This is still an ICE on current nightly when not cargo run. playground

@JohnTitor JohnTitor added the A-specialization Area: Trait impl specialization label Oct 13, 2019
@Seeker14491
Copy link
Contributor

This code compiles without a problem whether I do cargo build or cargo run using current nightly: rustc 1.40.0-nightly (1721c9685 2019-10-12). Tested on Windows 10 x64 and Ubuntu x64.

@JohnTitor
Copy link
Member

@Seeker14491 Really? But on the playground, the ICE still appears. Can you check the above link?

@Seeker14491
Copy link
Contributor

Yes, I get an ICE in the playground when I just build.

@Centril Centril added F-specialization `#![feature(specialization)]` requires-nightly This issue requires a nightly compiler in some way. labels Oct 25, 2019
@jonas-schievink jonas-schievink added the F-coerce_unsized The `CoerceUnsized` trait label Jan 8, 2020
@mati865
Copy link
Contributor

mati865 commented Jan 8, 2020

It doesn't ICE on the playground any more.
It does ICE when using build instead of run.

@JohnTitor
Copy link
Member

@mati865 You need cargo build or cargo test, not cargo run. It seems like a still ICE to me.

@JohnTitor
Copy link
Member

Triage: the latest nightly rejects the code without an ICE. Marking as E-needs-test.

@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jun 22, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Jun 23, 2020
Manishearth added a commit to Manishearth/rust that referenced this issue Jun 24, 2020
@bors bors closed this as completed in 45de677 Jun 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-specialization Area: Trait impl specialization C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-coerce_unsized The `CoerceUnsized` trait F-specialization `#![feature(specialization)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants