Skip to content

Rust ICE when using for all binder (panics in MIR) on stable 1.34.0 and nightly 1.35.0 #60274

Closed
@RustyYato

Description

@RustyYato
pub trait Generator<'this> {
    type Yield: 'this;
    
    fn next(&'this mut self) -> Option<Self::Yield>;
}

pub trait FromGenerator<'gen, G: Generator<'gen>> {
    fn from_generator(g: G) -> Self;
}

impl<T, G> FromGenerator<'_, G> for Vec<T>
where G: for<'a> Generator<'a, Yield = T> {
    fn from_generator(mut g: G) -> Self {
        let mut vec = Self::new();

        while let Some(x) = g.next() {
            vec.push(x)
        }

        vec
    }
}

pub struct Iter<I: ?Sized>(I);

impl<'this, I: ?Sized + Iterator> Generator<'this> for Iter<I> where I::Item: 'this {
    type Yield = I::Item;

    fn next(&'this mut self) -> Option<Self::Yield> {
        self.0.next()
    }
}

fn main() {
    let indicies = [];
    Vec::<&u32>::from_generator(Iter(indicies.iter()));
}

While I was trying to make a general Generator impl, I came across this ICE. Note that inlining indicies makes this ICE go away.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-NLLArea: Non-lexical lifetimes (NLL)C-bugCategory: This is a bug.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