Skip to content

Unclear error message about missing lifetime when wrapping closure references #22760

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

Closed
knz opened this issue Feb 24, 2015 · 2 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions

Comments

@knz
Copy link

knz commented Feb 24, 2015

The following code:

struct A; struct B; 
let id : &Fn(B)->B = &|x|{x}; 
let di : &Fn(A)->&Fn(B)->B = &|discard:A|{id};

produces the following error message, which is utterly non-informative about how to fix the problem:

<anon>:14:76: 14:85 error: missing lifetime specifier [E0106]
<anon>:14         struct A; struct B; let id : &Fn(B)->B = &|x|{x}; let di : &Fn(A)->&Fn(B)->B = &|discard:A|{id};
                                                                                     ^~~~~~~~~
<anon>:14:76: 14:85 help: this function's return type contains a borrowed value, but the signature does not say which one of argument 1's 0 elided lifetimes it is borrowed from
<anon>:14         struct A; struct B; let id : &Fn(B)->B = &|x|{x}; let di : &Fn(A)->&Fn(B)->B = &|discard:A|{id};
                                                                                     ^~~~~~~~~

In particular "which one of argument 1's 0 elided lifetimes it is borrowed from" is particularly confusing.

Version: rustc 1.0.0-dev (2b01a37ec 2015-02-21) (built 2015-02-21)

@steveklabnik steveklabnik added A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions labels Feb 25, 2015
@steveklabnik
Copy link
Member

Triage: runnable example:

struct A; struct B;

fn main() {
    let id: &Fn(B)-> B = &|x| { x }; 
    let di: &Fn(A)-> &Fn(B) -> B = &|_| { id };
}

no change to the diagnostic, however.

@Mark-Simulacrum
Copy link
Member

The original code compiles without any errors, so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions
Projects
None yet
Development

No branches or pull requests

3 participants