Closed
Description
So I have the following code:
struct Article {
proof_reader: ProofReader,
}
struct ProofReader {
name: String,
}
pub trait HaveRelationship<To> {
fn get_relation(&self) -> To;
}
impl HaveRelationship<&ProofReader> for Article {
fn get_relation(&self) -> &ProofReader {
&self.proof_reader
}
}
Which on the stable compiler gives this helpful error message:
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter in generic type due to conflicting requirements
--> src/main.rs:14:5
|
14 | fn get_relation(&self) -> &ProofReader {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 14:5...
--> src/main.rs:14:5
|
14 | / fn get_relation(&self) -> &ProofReader {
15 | | &self.proof_reader
16 | | }
| |_____^
note: ...but the lifetime must also be valid for the lifetime '_ as defined on the impl at 13:23...
--> src/main.rs:13:23
|
13 | impl HaveRelationship<&ProofReader> for Article {
| ^
= note: ...so that the method type is compatible with trait:
expected fn(&Article) -> &ProofReader
found fn(&Article) -> &ProofReader
Yet on the nightly compiler the compiler error does not inform me about lifetimes, but tells me the signature needs to be what it already is:
error: `impl` item signature doesn't match `trait` item signature
--> src/main.rs:14:5
|
10 | fn get_relation(&self) -> To;
| ----------------------------- expected fn(&Article) -> &ProofReader
...
14 | fn get_relation(&self) -> &ProofReader {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found fn(&Article) -> &ProofReader
|
= note: expected `fn(&Article) -> &ProofReader`
found `fn(&Article) -> &ProofReader`
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Lifetimes / regionsCategory: This is a bug.Diagnostics: Confusing error or lint that should be reworked.Diagnostics: An error or lint that needs small tweaks.Medium priorityRelevant to the compiler team, which will review and decide on the PR/issue.Performance or correctness regression from one stable version to another.