Skip to content

UX bug report: Expected foo but found foo. #15142

Closed
@pnathan

Description

@pnathan

Hi,

The following compiler error is not particularly clear or helpful (formatted to show the non-clarity).

error: mismatched types: expected 
`core::option::Option<&'r Job>` but found
`core::option::Option<&'r Job>` (lifetime mismatch)

While I understand there's a mismatch here, it's not really helpful in grasping what has to happen in my code to correct the error. In particular, if I passed type "X" but got "X", I'm not led towards a clear solution.

I've included below a fuller scroll, which is an error I have gotten a lot but don't really grok how to avoid yet.

Basically, I'm confused by the errors here and don't find them clarifying, only that I'm doing something vaguely wrong with lifetimes.

newton.rs:211:5: 213:6 note: consider using an explicit lifetime parameter as shown: fn take_job<'r>(&'r mut self, job: &'r Job)
newton.rs:211     fn take_job<'r>(&'r mut self, job: &'r Job) -> () {
newton.rs:212         self.job = Some(job);
newton.rs:213     }
newton.rs:212:20: 212:29 error: cannot infer an appropriate lifetime due to conflicting requirements
newton.rs:212         self.job = Some(job);
                                 ^~~~~~~~~
newton.rs:212:20: 212:29 error: mismatched types: expected `core::option::Option<&'r Job>` but found `core::option::Option<&Job>` (lifetime mismatch)
newton.rs:212         self.job = Some(job);
                                 ^~~~~~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions