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: never type as default associated type #51506

Closed
malbarbo opened this issue Jun 11, 2018 · 4 comments · Fixed by #73646
Closed

ICE: never type as default associated type #51506

malbarbo opened this issue Jun 11, 2018 · 4 comments · Fixed by #73646
Labels
A-specialization Area: Trait impl specialization A-trait-system Area: Trait system 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-never_type `#![feature(never_type)]` 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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@malbarbo
Copy link
Contributor

malbarbo commented Jun 11, 2018

This code generates an ICE

#![feature(never_type, specialization)]
#![allow(incomplete_features)]

use std::iter::{self, Empty};

trait Trait {
    type Out: Iterator<Item = u32>;

    fn f(&self) -> Option<Self::Out>;
}

impl<T> Trait for T {
    default type Out = !;

    default fn f(&self) -> Option<Self::Out> {
        None
    }
}

struct X;

impl Trait for X {
    type Out = Empty<u32>;

    fn f(&self) -> Option<Self::Out> {
        Some(iter::empty())
    }
}

fn f<T: Trait>(a: T) {
    if let Some(iter) = a.f() {
        println!("Some");
        for x in iter {
            println!("x = {}", x);
        }
    }
}

pub fn main() {
    f(10);
}

with this message.

error: internal compiler error: librustc/traits/codegen/mod.rs:169: Encountered errors `[FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<! as std::iter::Iterator>)),depth=1),Unimplemented)]` resolving bounds after type-checking

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

Replacing 1.f() by X.f() makes the code to compile and run fine, which is strange because ! does not implements Iterator .

By removing the specialization the compiler refuses to compile the code with the error:

error[E0277]: the trait bound `!: std::iter::Iterator` is not satisfied
  --> src/main.rs:10:9
   |
10 | impl<T> Trait for T {
   |         ^^^^^ `!` is not an iterator; maybe try calling `.iter()` or a similar method
   |
   = help: the trait `std::iter::Iterator` is not implemented for `!`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
@memoryruins memoryruins added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Sep 11, 2018
@jonas-schievink jonas-schievink added A-specialization Area: Trait impl specialization C-bug Category: This is a bug. F-never_type `#![feature(never_type)]` F-specialization `#![feature(specialization)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. requires-nightly This issue requires a nightly compiler in some way. A-trait-system Area: Trait system labels Aug 6, 2019
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Oct 15, 2019
@JohnTitor
Copy link
Member

The ICE has been fixed in the latest nightly, marked as E-needstest

@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 Nov 13, 2019
@malbarbo
Copy link
Contributor Author

Thanks @JohnTitor. Indeed, the example compiles fine in nightly (4f03f4a 2019-11-12), however, replacing the main function by these two

fn f<T: Trait>(a: T) {
    if let Some(iter) = a.f() {
        println!("Some");
        for x in iter {
            println!("x = {}", x);
        }
    }
}

pub fn main() {
    f(10);
}

generates the same ICE.

@JohnTitor
Copy link
Member

@malbarbo ah, thanks for the update! I confirmed it (playground)

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

Triage: the ICE doesn't occur anymore 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 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 A-trait-system Area: Trait system 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-never_type `#![feature(never_type)]` 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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants