Autoref happens when you attempt to use method syntax to invoke a function when you have a value, but the function takes &self
or &mut self
-- the method receiver is automatically referenced instead of given by value. For example:
struct Foo;
impl Foo {
pub fn by_value(self) {}
pub fn by_ref(&self) {}
pub fn by_mut(&mut self) {}
}
fn main() {
let foo = Foo;
// Autoref to &mut. These two lines are equivalent.
foo.by_mut();
Foo::by_mut(&mut foo);
// Autoref to &. These two lines are equivalent.
foo.by_ref();
Foo::by_ref(&foo);
// No autoref since self is received by value.
foo.by_value();
}
So, in your case you are doing something similar, but the compiler can't come up with a lifetime for the reference that doesn't cause a borrow-check problem.