Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
alexcrichton opened this issue May 11, 2014 · 3 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions

Comments

@alexcrichton
Copy link
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.

@huonw
Copy link
Member

huonw commented May 11, 2014

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.

@huonw huonw changed the title missing lifetime specifier when none is needed Confusing error for missing lifetime on a closure written as <'a> |...| May 11, 2014
@alexcrichton
Copy link
Member Author

Oops, good point, thanks!

@alexcrichton
Copy link
Member Author

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

flip1995 pushed a commit to flip1995/rust that referenced this issue Feb 6, 2025
…-lang#14105)

Fix rust-lang#14096

changelog: [`redundant_closure_for_method_calls`]: repeat generic args
in suggestion
# for free to join this conversation on GitHub. Already have an account? # 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

2 participants