Open
Description
I tried this code:
fn call_by_ref<F, A0, A1>(mut f: F, arg0: A0, arg1: A1)
where
A0: Sized,
A1: Sized,
for<'w> &'w mut F: FnMut(A0, A1),
{
// This doesn't work.
(&mut f)(arg0, arg1);
}
// Workaround
fn call_by_ref_and_hack<F, A0, A1>(mut f: F, arg0: A0, arg1: A1)
where
A0: Sized,
A1: Sized,
for<'w> &'w mut F: FnMut(A0, A1),
{
fn call_once<B0, B1>(f: impl FnOnce(B0, B1), arg0: B0, arg1: B1){
f(arg0, arg1)
}
// This works
call_once(&mut f, arg0, arg1);
}
I expected to see this happen: Both functions should compile and work.
Instead, this happened: Only version with inner function hack works.
Meta
rustc --version --verbose
:
rustc 1.70.0 (90c541806 2023-05-31)
AFAIK, it never worked.