-
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 lintsA-inferenceArea: Type inferenceArea: Type inferenceC-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.WG-diagnosticsWorking group: DiagnosticsWorking group: Diagnostics

Description
Code (also available on playground):
use std::sync::Mutex;
fn main() {
let a = Mutex::new(7);
let mut a = a.lock().unwrap();
a += 1;
}
Error:
error[E0368]: binary assignment operation `+=` cannot be applied to type `std::sync::MutexGuard<'_, {integer}>`
--> src/main.rs:6:5
|
6 | a += 1;
| -^^^^^
| |
| cannot use `+=` on type `std::sync::MutexGuard<'_, {integer}>`
Okay, but why cannot +=
be applied to Mutexuard<'_, {integer}>
? And what can we do about it? :)
I'd prefer if the error message included something like:
help: consider dereferencing the left-hand side: `*a += 1`
Such a help message could be printed whenever the LHS of an assignment must be dereferenced. The same applies to situations in which we must dereference more than once, e.g **a
.
nyanpasu64 and tm-ahadtm-ahad
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-inferenceArea: Type inferenceArea: Type inferenceC-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.WG-diagnosticsWorking group: DiagnosticsWorking group: Diagnostics