Skip to content

Confusing error for missing lifetime on a closure written as <'a> |...| #14105

@alexcrichton

Description

@alexcrichton
Member

Formerly:

missing lifetime specifier when none is needed

struct B<T>;

impl B< <'a> ||> {}
$ rustc --crate-type=lib foo.rs 
foo.rs:3:9: 3:16 error: missing lifetime specifier
foo.rs:3 impl B< <'a> ||> {}
                 ^~~~~~~
error: aborting due to previous error

The type parameter should be a self-contained type, I'm not sure why it's asking for a lifetime specifier.

New description

The error message above seems to be contradictory, since the <'a> thing is a lifetime itself, however, the problem is the environment of the closure needs a lifetime, which is written like ||:'a. It would be nice for the error message to guide people towards the correct thing.

Activity

huonw

huonw commented on May 11, 2014

@huonw
Member

The <'a> is the lifetimes of any parameters, the lifetime of the environment is specified by ||:'a.

I'll co-opt this issue for improving the error message, since it's very confusing.

changed the title [-]missing lifetime specifier when none is needed[/-] [+]Confusing error for missing lifetime on a closure written as `<'a> |...|`[/+] on May 11, 2014
alexcrichton

alexcrichton commented on May 11, 2014

@alexcrichton
MemberAuthor

Oops, good point, thanks!

alexcrichton

alexcrichton commented on Feb 2, 2015

@alexcrichton
MemberAuthor

Now that closures look a lot more like traits I think that this has basically solved itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @alexcrichton@huonw

        Issue actions

          Confusing error for missing lifetime on a closure written as `<'a> |...|` · Issue #14105 · rust-lang/rust