I meet a problem about lifetime, I simplified the code as follows
trait TraitCannotChange {
fn bar(&mut self);
}
struct SomeStruct<'a> {
...
v: &'a [f64],
}
impl <'a> SomeStruct <'a> {
fn foo(&'a mut self) {
...
}
}
impl <'a> TraitCannotChange for SomeStruct<'a> {
fn bar(&mut self) {
self.foo();
}
}
compilation error:
cannot infer an appropriate lifetime for autoref due to conflicting requirements
note: ...so that the types are compatible
--> src\main.rs:82:14
|
82 | self.foo();
| ^^^
= note: expected `&mut SomeStruct<'_>`
found `&mut SomeStruct<'a>`
in this demo case, if I add 'a in trait and the '&'a mut self' parameter of fn bar(), It will compile successfully.
But the trait can not be changed because it is a dependency of many other codes. How can I solve this problem without changing definition of the trait. Please help, Thanks.