Skip to content

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

Closed

Description

@alexcrichton

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

  1. huonw commented on May 11, 2014

    @huonw
    Contributor

    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.

  2. 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
  3. alexcrichton commented on May 11, 2014

    @alexcrichton
    MemberAuthor

    Oops, good point, thanks!

  4. 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

      Issue actions