Why does a mutable borrow of a closure through DerefMut not work?

This is a known issue regarding how the function traits are inferred through Deref. As a workaround, you need to explicitly get a mutable reference by doing a mutable reborrow:

let mut t = Foo;
(&mut *t)();

or by calling DerefMut::deref_mut:

let mut t = Foo;
t.deref_mut()();

Leave a Comment