Consider example:
trait Bar {
fn bar(&self, r: &mut Re);
}
struct Re<'a> {
data: &'a u16,
}
struct Foo;
impl Bar for Foo {
fn bar<'a, 'b>(&'a self, r: &'b mut Re<'a>){}
}
(Playground)
Errors:
Compiling playground v0.0.1 (/playground)
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter 'a in generic type due to conflicting requirements
--> src/lib.rs:12:5
|
12 | fn bar<'a, 'b>(&'a self, r: &'b mut Re<'a>){}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 12:5...
--> src/lib.rs:12:5
|
12 | fn bar<'a, 'b>(&'a self, r: &'b mut Re<'a>){}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...but the lifetime must also be valid for the anonymous lifetime #3 defined on the method body at 12:5...
--> src/lib.rs:12:5
|
12 | fn bar<'a, 'b>(&'a self, r: &'b mut Re<'a>){}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: ...so that the method type is compatible with trait:
expected fn(&Foo, &mut Re<'_>)
found fn(&Foo, &mut Re<'_>)
error: aborting due to previous error
For more information about this error, try `rustc --explain E0495`.
error: could not compile `playground`.
To learn more, run the command again with --verbose.
All 3 notes of this error message is confusing:
note1, note2: Message not point where are the anonymous lifetime #1 and the anonymous lifetime #3. Also it's not obviously why there are two different anonymous lifetimes at one place (at 12:5).
=note3: Expected result looks totally equal to founded. So it's not obviously why it considered as different.
It is difficult to figure out what was going on.
May be some change of this message needed.
Consider example:
(Playground)
Errors:
All 3 notes of this error message is confusing:
note1, note2: Message not point where are the anonymous lifetime #1 and the anonymous lifetime #3. Also it's not obviously why there are two different anonymous lifetimes at one place (at 12:5).
=note3: Expected result looks totally equal to founded. So it's not obviously why it considered as different.
It is difficult to figure out what was going on.
May be some change of this message needed.