Skip to content

Lifetime error messages could be improved. #9716

Closed
@orenbenkiki

Description

@orenbenkiki

Here's an example I just got:

src/anthill/execution/kind.rs:124:32: 125:29 error: cannot infer an appropriate lifetime due to conflicting requirements
src/anthill/execution/kind.rs:124                                 dictionary.name_to_kind.find(&name)
src/anthill/execution/kind.rs:125                             };
src/anthill/execution/kind.rs:124:32: 124:55 note: first, the lifetime cannot outlive the expression at 124:32...
src/anthill/execution/kind.rs:124                                 dictionary.name_to_kind.find(&name)
                                                                  ^~~~~~~~~~~~~~~~~~~~~~~
src/anthill/execution/kind.rs:124:32: 124:55 note: ...due to the following expression
src/anthill/execution/kind.rs:124                                 dictionary.name_to_kind.find(&name)
                                                                  ^~~~~~~~~~~~~~~~~~~~~~~
src/anthill/execution/kind.rs:124:32: 125:29 note: but, the lifetime must be valid for the method call at 124:32...
src/anthill/execution/kind.rs:124                                 dictionary.name_to_kind.find(&name)
src/anthill/execution/kind.rs:125                             };
src/anthill/execution/kind.rs:124:32: 124:55 note: ...due to the following expression
src/anthill/execution/kind.rs:124                                 dictionary.name_to_kind.find(&name)
                                                                  ^~~~~~~~~~~~~~~~~~~~~~~

Now, I'm developing some experience with lifetimes so I have some intuition about what I did wrong. And I appreciate the effort that went into this error message! But still, saying "the lifetime can't outlive the expression X in location Y because it must be valid at the function call at exactly the same expression X in the same location Y" - that's not exactly explaining things in a way that is understandable to a newcomer (which I still am).

Perhaps there's a better way to phrase the problem, and possibly eliminate the duplications?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions