Skip to content

ICE: Expected specialization failed to hold #36804

Closed
@apasel422

Description

@apasel422

While playing around with #36791, I encountered an ICE when attempting to compile the following code with nightly on the playground:

#![feature(specialization)]

pub struct Cloned<I> {
    it: I,
}

impl<'a, I, T: 'a> Iterator for Cloned<I>
    where I: Iterator<Item=&'a T>, T: Clone
{
    type Item = T;

    fn next(&mut self) -> Option<T> {
        self.it.next().cloned()
    }

    fn size_hint(&self) -> (usize, Option<usize>) {
        self.it.size_hint()
    }
}

impl<'a, I, T: 'a> Iterator for Cloned<I>
    where I: Iterator<Item=&'a T>, T: Copy
{
    fn nth(&mut self, n: usize) -> Option<T> {
        self.it.nth(n).cloned()
    }

    fn last(self) -> Option<T> {
        self.it.last().cloned()
    }

    fn count(self) -> usize {
        self.it.count()
    }
}

fn main() {
    let mut called = 0;

    let a = [1, 2, 3, 4];

    Cloned { it: a.iter().map(|x| {
        called += 1;
        x
    }) }.count();

    println!("{}", called);
}

Compiler output:

rustc 1.13.0-nightly (d0623cf7b 2016-09-26)
error: internal compiler error: ../src/librustc/traits/specialize/mod.rs:97: When translating substitutions for specialization, the expected specializaiton failed to hold

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-specializationArea: Trait impl specializationC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions