< 返回版块

枪炮与玫瑰 发表于 2018-06-13 11:04

出错示例,使用了 &'a mut self ,应修正为 &mut self

出错play地址

国外论坛详解

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

评论区

写评论
Mike 2018-06-13 11:10

赞。

1 共 1 条评论, 1 页