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

CryZe opened this Issue Jul 30, 2018 · 1 comment


None yet
3 participants
Copy link

CryZe commented Jul 30, 2018

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


existential type Foo<T>: Default;

fn foo<T: Default>(t: T) -> Foo<T> {

struct NotDefault;

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


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\ Encountered error `Unimplemented` selecting `Binder(<NotDefault as std::default::Default>)` during codegen

thread 'main' panicked at 'Box<Any>', librustc_errors\
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:

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.


This comment has been minimized.

Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment