Closed
Description
I have this function:
use git2::Reference;
fn resolve_symbolic_reference(&self, reference: Option<Reference>) -> Option<Reference> {
return reference;
// here's more logic, this is just shortened for clarity
}
Here's the source of the struct.
And I get this from compiler:
error[E0308]: mismatched types
--> src/backend.rs:71:16
|
71 | return reference;
| ^^^^^^^^^ lifetime mismatch
|
= note: expected type `std::option::Option<git2::Reference<'_>>`
found type `std::option::Option<git2::Reference<'_>>`
note: the anonymous lifetime #2 defined on the body at 70:92...
--> src/backend.rs:70:93
|
70 | fn resolve_symbolic_reference(&self, reference: Option<Reference>) -> Option<Reference> {
| ^
note: ...does not necessarily outlive the anonymous lifetime #1 defined on the body at 70:92
--> src/backend.rs:70:93
|
70 | fn resolve_symbolic_reference(&self, reference: Option<Reference>) -> Option<Reference> {
| ^
error: aborting due to previous error
First of all: I don't understand what's wrong with my code: isn't the lifetime of the function argument problem of the caller of my function?
Second: the compiler's error message is not helpful, especially:
= note: expected type `std::option::Option<git2::Reference<'_>>`
found type `std::option::Option<git2::Reference<'_>>`
I run rust unstable installed via rustup:
$ rustc 1.17.0-nightly (0aeb9c129 2017-03-15)
binary: rustc
commit-hash: 0aeb9c12979e6da753701a798d04105b6b1a8c28
commit-date: 2017-03-15
host: x86_64-unknown-linux-gnu
release: 1.17.0-nightly
LLVM version: 3.9
I have also reported this to the library's upstream.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Lifetimes / regionsArea: Suggestions generated by the compiler applied by `cargo fix`Category: An issue proposing an enhancement or a PR with one.Diagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: An error or lint that needs small tweaks.Relevant to the compiler team, which will review and decide on the PR/issue.