Skip to content

Poorly worded lifetime error message #18758

@mdinger

Description

@mdinger
struct Mine<'a> {
    s: &'a str,
}

impl <'a>Iterator<&'a str> for Mine<'a> {
    fn next(&'a mut self) -> Option<&'a str> {
        Some("hi")
    }
}

impl <'a>Mine<'a> {
    fn new(s: &str) -> Mine {
        Mine { s: "hi" }
    }
}

fn main() {}

Error:

<anon>:6:5: 8:6 error: method `next` has an incompatible type for trait: expected concrete lifetime, found bound lifetime parameter  [E0053]
<anon>:6     fn next(&'a mut self) -> Option<&'a str> {
<anon>:7         Some("hi")
<anon>:8     }
<anon>:6:46: 8:6 note: expected concrete lifetime is the lifetime 'a as defined on the block at 6:45
<anon>:6     fn next(&'a mut self) -> Option<&'a str> {
<anon>:7         Some("hi")
<anon>:8     }
error: aborting due to previous error
playpen: application terminated with error code 101

This should be 2 sentences or something. It's hardly a sentence.

<anon>:6:46: 8:6 note: expected concrete lifetime is the lifetime 'a as defined on the block at 6:45
//                                               ^ Period? Semicolon? Something else?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions