-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.