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 on unsound usage of existential types #52843

Closed
CryZe opened this issue Jul 30, 2018 · 5 comments · Fixed by #77741
Closed

ICE on unsound usage of existential types #52843

CryZe opened this issue Jul 30, 2018 · 5 comments · Fixed by #77741
Assignees
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. 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-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` 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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@CryZe
Copy link
Contributor

CryZe commented Jul 30, 2018

You can construct an existential type that implements traits that it shouldn't have like so:

#![feature(existential_type)]

existential type Foo<T>: Default;

#[allow(unused)]
fn foo<T: Default>(t: T) -> Foo<T> {
    t
}

struct NotDefault;

fn main() {
    let _ = Foo::<NotDefault>::default();
}

Playground

As you can see Foo's type parameter T doesn't have a Default bound, but it still implements the Default trait as a whole. If you actually abuse this with a type parameter that doesn't implement Default, you can construct a value even though the type doesn't implement Default. This results in an ICE atm:

$ cargo +nightly run
   Compiling unsound-existentials v0.1.0 (file:///C:/Projekte/one-offs/unsound-existentials)
error: internal compiler error: librustc\traits\codegen\mod.rs:68: Encountered error `Unimplemented` selecting `Binder(<NotDefault as std::default::Default>)` during codegen

thread 'main' panicked at 'Box<Any>', librustc_errors\lib.rs:578:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: aborting due to previous error


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.29.0-nightly (866a71325 2018-07-29) running on x86_64-pc-windows-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `unsound-existentials`.

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

This may just be an unimplemented check due to existential types being brand new on nightly.

@kennytm kennytm added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 30, 2018
@oli-obk
Copy link
Contributor

oli-obk commented Jan 25, 2019

foo should not be a defining use for Foo, because its bindings differ.

@oli-obk oli-obk self-assigned this Jan 25, 2019
@Centril Centril added F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` requires-nightly This issue requires a nightly compiler in some way. labels Jul 28, 2019
@JohnTitor
Copy link
Member

Doesn't reproduce in the latest nightly

@JohnTitor JohnTitor added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. and removed E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. labels Aug 8, 2019
@JohnTitor
Copy link
Member

Ah, wait, the latest example is here, this is still ICE.

@Aaron1011
Copy link
Member

Updated version (playground):

#![feature(type_alias_impl_trait)]

type Foo<T> = impl Default;

#[allow(unused)]
fn foo<T: Default>(t: T) -> Foo<T> {
    t
}

struct NotDefault;

fn main() {
    let _ = Foo::<NotDefault>::default();
}

@JohnTitor
Copy link
Member

Triage: This is no longer ICE with the latest nightly, 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 Oct 7, 2020
@bors bors closed this as completed in 5565241 Oct 14, 2020
jacob-hughes added a commit to jacob-hughes/alloy that referenced this issue Jan 10, 2022
Also remove `NoFinalize` from tuple implemenations as this can result in
cyclic trait lookups in trait resolution and cause an ICE.

See issue rust-lang#52843
jacob-hughes added a commit to jacob-hughes/alloy that referenced this issue May 17, 2023
Also remove `NoFinalize` from tuple implemenations as this can result in
cyclic trait lookups in trait resolution and cause an ICE.

See issue rust-lang#52843
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. 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-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` 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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Development

Successfully merging a pull request may close this issue.

7 participants