出错示例,使用了 &'a mut self ,应修正为 &mut self
if you drop the 'a named lifetime in mutate_internal, what you get is a fresh (anonymous) lifetime parameter, not 'a. I.e. you get something equivalent to:
fn mutate_internal<'b>(&'b mut self) {} this means that self is borrowed until mutate_internal is done, but no longer than that. That's why the second call to mutate_internal compiles.
By contrast, with fn mutate_internal(&'a mut self) {} you're telling the compiler that self will be borrowed as long as 'a (which is the entire lifetime of Foo). That's why the second mutate_internal can't be called
评论区
写评论赞。