-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Confusing error message when trying to implement a shared mutable state #55826
Copy link
Copy link
Open
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.
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.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Let's say I am a rust beginner coming from another language, and I want to write a simple multi-threaded program in rust.
So I write this simple function :
One of the selling points of rust is being able to prevent data races, so it should be able to explain in details what is wrong with this function. However, it gives a confusing error message.
It does not compile, and the compiler returns :
And if I look up the detailed error message in the error book (here: https://doc.rust-lang.org/error-index.html#E0373), it also tells me to add a
movein front of the closure.I think this is confusing. Obviously, the right thing to do here is to use a mutex, but this is not mentioned neither in the error message, nor in the error book.
Maybe the error should also say something like
It would be even nicer if the compiler could detect that we are using
xafter the litigious function, and thus not talk aboutmoveat all.