Skip to content

nll: incomprehensible "free region '' does not outlive 'foo" error  #49493

@nikomatsakis

Description

@nikomatsakis

This program ought not to compile, but the error we get is pretty darn incomprehensible (play):

#![feature(nll)]
#![feature(in_band_lifetimes)]
#![allow(warnings)]

struct CookieJar<'data> {
    vec: Vec<String>,
    data: &'data (),
}

impl CookieJar<'data> {
    fn cookie_me(&self) -> Cookie<'data> {
        let next = 22;
        me_want_cookie(next, self)
    }
}

struct Cookie<'jar> {
    jar: &'jar CookieJar<'jar>
}

fn me_want_cookie(next: usize, jar: &'jar CookieJar<'jar>) -> Cookie<'jar> {
    Cookie { jar }
}

fn main() {
}

gives me

error: free region `` does not outlive free region `'data`
  --> src/main.rs:12:13
   |
12 |         let next = 22;
   |             ^^^^

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-NLLArea: Non-lexical lifetimes (NLL)A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions