-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Not sufficiently useful error message when FnMut is needed instead of Fn #31701
Copy link
Copy link
Closed
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)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.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.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.
Metadata
Metadata
Assignees
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)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.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.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.
Type
Fields
Give feedbackNo fields configured for issues without a type.
This code:
results in the following error messages in stable:
The problem here is that we're using
Fn()instead ofFnMut(), but the phrase "consider changing this closure to take self by mutable reference" is not particularly useful in telling us that that specifically is the problem. That is, the fact that we cannot assign to the captured outer variable is because we are trying to returnBox<Fn() -> usize>instead ofBox<FnMut() -> usize>, but that's not immediately clear from the original error message.I'm not entirely sure how this would be rectified, but at the very least mentioning
FnMutsomewhere would be useful. @eddyb mentioned that this issue was "because a bound/trait object ofFn()was used but onlyFnMut()allows mutable borrows", so I think some variation on that would be reasonably sufficient to clarify the error.