Skip to content

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

Closed
@alexcrichton

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.

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