fn test(f: Box<FnMut()>) {
let _f = move || {
f()
};
}
error[E0596]: cannot borrow immutable `Box` content `**f` as mutable
--> src/main.rs:3:9
|
3 | f()
| ^ cannot borrow as mutable
This error message seems a bit weird, because the problem isn't that box content isn't mutable, but the box itself is immutable. Changing the line 2 to let mut f: … fixes the issue. Notice that the same error message is shown if we construct f within the function.
I think the error message should be improved to look similar to the following (not sure on the phrasing of the error itself):
error[E0596]: cannot borrow immutable argument `Box` as mutable
--> src/main.rs:2:5
|
1 | fn test(f: Box<FnMut()>) {
| - consider changing this to `mut f`
2 | let _f = move || {
3 | f()
| ^ cannot borrow mutably
This error message seems a bit weird, because the problem isn't that box content isn't mutable, but the box itself is immutable. Changing the line 2 to
let mut f: …fixes the issue. Notice that the same error message is shown if we constructfwithin the function.I think the error message should be improved to look similar to the following (not sure on the phrasing of the error itself):