Skip to content

compiler crash using specialization #77026

@avl

Description

@avl

I tried this code:

#![feature(specialization)]

pub enum Either<L,R> {
    Left(L),
    Right(R),
}

default impl<L,R> From<L> for Either<L,R> {
    fn from(l: L) -> Self {
        Either::Left(l)
    }
}
impl<L,R> From<R> for Either<L,R> {
    fn from(r: R) -> Self {
        Either::Right(r)
    }
}

To be completely honest, I wasn't sure this would really work. But I suppose it could be argued that the compiler shouldn't crash.

Instead, this happened:

Compiling playground v0.0.1 (/playground)
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/lib.rs:1:12
  |
1 | #![feature(specialization)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information

error[E0275]: overflow evaluating the requirement `Either<!, _>: From<!>`
  |
  = help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`playground`)
  = note: required because of the requirements on the impl of `From<!>` for `Either<!, _>`
  = note: required because of the requirements on the impl of `From<!>` for `Either<!, _>`
  = note: required because of the requirements on the impl of `From<!>` for `Either<!, _>`
  = note: required because of the requirements on the impl of `From<!>` for `Either<!, _>`
  = note: required because of the requirements on the impl of `From<!>` for `Either<!, _>`
  = note: required because of the requirements on the impl of `From<!>` for `Either<!, _>`
  = note: required because of the requirements on the impl of `From<!>` for `Either<!, _>`
  = note: required because of the requirements on the impl of `From<!>` for `Either<!, _>`
  = note: required because of the requirements on the impl of `From<!>` for `Either<!, _>`
  = note: required because of the requirements on the impl of `From<!>` for `Either<!, _>`
  = note: required because of the requirements on the impl of `From<!>` for `Either<!, _>`
  = note: required because of the requirements on the impl of `From<!>` for `Either<!, _>`
  = note: required because of the requirements on the impl of `From<!>` for `Either<!, _>`
  = note: required because of the requirements on the impl of `From<!>` for `Either<!, _>`
  = note: required because of the requirements on the impl of `From<!>` for `Either<!, _>`
  = note: required because of the requirements on the impl of `From<!>` for `Either<!, _>`
  = note: required because of the requirements on the impl of `From<!>` for `Either<!, _>`

etc etc etc

This happened just now on 2020-09-21 at the Rust playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=005db744fc083053388b84c8b68d1751 .

I know specialization isn't stable, so there are no guarantees, and maybe this is a known issue. But if someone is currently working on stabilizing specialization, maybe they'd be interested in cleaning up the above error message.

Anyway, a great thank you to all the fantastic people who work on making Rust more awesome!

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-specialization`#![feature(specialization)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions