Skip to content

Error messages about lifetimes for mutable Iterator are cryptic. #30257

Open
@vi

Description

@vi

Example: http://is.gd/8dVXWc

<anon>:42:14: 42:33 error: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements
<anon>:42         Some(&mut self.cont.item)
                       ^~~~~~~~~~~~~~~~~~~
<anon>:39:5: 43:6 help: consider using an explicit lifetime parameter as shown: fn next(&'a mut self) -> Option<&'a mut V>
<anon>:39     fn next(&mut self) -> Option<&'a mut V> {
<anon>:40         if self.emitted { return None }
<anon>:41         self.emitted = true;
<anon>:42         Some(&mut self.cont.item)
<anon>:43     }
error: aborting due to previous error
playpen: application terminated with error code 101

Compilation failed.

@bluss gave me a helpful link on IRC, stating that is a classic thing.

I think for every "classic" problem there should be a lint giving a link to some article about the problem.

In this case the link can be emitted for any lifetimes problem when mutable references and Iterator trait involved together.

For reference: link to changed version that does compile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions