Skip to content

[nll] gluon_base does not compile with NLL #53119

Closed
@nikomatsakis

Description

@nikomatsakis

I reduced a crater run failure of gluon_base v0.8.0 to this standalone snippet:

#![feature(nll)]

use std::ops::Deref;

pub struct TypeFieldIterator<'a, T: 'a> {
    typ: &'a T,
    current: usize,
}

pub enum Type<Id, T> {
    Unit,

    Record(T),
    
    ExtendRow {
        types: Vec<(Id, T)>,
        rest: T,
    },
}

impl<'a, Id: 'a, T> Iterator for TypeFieldIterator<'a, T>
where
    T: Deref<Target = Type<Id, T>>,
{
    type Item = &'a (Id, T);
    
    fn next(&mut self) -> Option<&'a (Id, T)> {
        match **self.typ {
            Type::Unit => None,

            Type::Record(ref row) => {
                self.typ = row;
                self.next()
            }
            
            Type::ExtendRow { ref types, ref rest } => {
                let current = self.current;
                self.current += 1;
                types.get(current).or_else(|| {
                    self.current = 0;
                    self.typ = rest;
                    self.next()
                })
            }            
        }
    }
}

fn main() { }

this compiles without NLL; with NLL it fails with:

error[E0310]: the parameter type `Id` may not live long enough
  --> src/main.rs:39:44
   |
39 |                   types.get(current).or_else(|| {
   |  ____________________________________________^
40 | |                     self.current = 0;
41 | |                     self.typ = rest;
42 | |                     self.next()
43 | |                 })
   | |_________________^
   |
   = help: consider adding an explicit lifetime bound `Id: 'static`...

I think this is some kind of failure from the "closure checking" code.

Metadata

Metadata

Assignees

Labels

NLL-completeWorking towards the "valid code works" goalT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions