Closed
Description
Running this code on the latest stable (1.38.0) as well as nightly (2019-10-20)
fn foo<F, I>(i: &mut I)
where
F: FnMut(),
I: std::ops::IndexMut<(), Output = F>,
{
i[()](); // fails
(&mut i[()])(); // works
}
gives the error
error[E0596]: cannot borrow data in an index of `I` as mutable
--> src/lib.rs:6:5
|
6 | i[()](); // fails
| ^^^^^ cannot borrow as mutable
|
= help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `I`
which is clearly wrong.
Notably, the same error does not occur if we switch everything to Fn
:
fn foo<F, I>(i: &I)
where
F: Fn(),
I: std::ops::Index<(), Output = F>,
{
i[()](); // works
}