Skip to content
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

Confusing and incorrect lifetime diagnostic message #21642

Closed
rtkrruvinskiy opened this issue Jan 26, 2015 · 3 comments
Closed

Confusing and incorrect lifetime diagnostic message #21642

rtkrruvinskiy opened this issue Jan 26, 2015 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions

Comments

@rtkrruvinskiy
Copy link

Trying to compile the code at this playpen gives the following error:

<anon>:18:20: 18:26 error: cannot infer an appropriate lifetime due to conflicting requirements
<anon>:18         match iter.next() {
                             ^~~~~~
<anon>:17:5: 25:6 help: consider using an explicit lifetime parameter as shown: fn lookup(&self, mut iter: Box<Iterator<Item = Key<'b>>>) -> bool

There are a couple of issues here from my perspective:

  1. The function signature suggested by the compiler cannot actually compile since it uses an undefined lifetime.
  2. It's really unclear to me what the "conflicting requirements" are that the error message alludes to. Intuitively, I would have thought that the code should work as long as the lifetime of the iterator item is as long as the scope of the lookup method. In other words, my expectation would be that I can test whether a key is a member of the container without the lifetime of the instance of the key used for testing having to be as long as the lifetime of the container. However, that appears not to be the case, which seems counter-intuitive and limiting (since there doesn't appear to be an actual safety issue as far as I can see). It would be helpful to have scenarios like this discussed somewhere in the documentation. If such discussion already exists and I have overlooked it, my apologies.
@huonw huonw added A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions labels Jan 26, 2015
@steveklabnik
Copy link
Member

This now complains with the same error, but on the split() call instead.

@leoyvens
Copy link
Contributor

leoyvens commented Jan 29, 2017

Triage:

  1. No longer occurs because explicit lifetime suggestions where removed.
  2. The conflicting requirements are now much better explained.

This is fixed.

@steveklabnik
Copy link
Member

Closing then! Thanks @leodasvacas (cc #37057 )

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

4 participants