-
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.
Description
The following code works fine in cpp:
std::map<int, int> m;
m[0] = 0;
In Rust however, you are getting an error:
let mut f :HashMap<u8, u8> = HashMap::new();
f[&0] = 0;
error[E0594]: cannot assign to immutable indexed content
--> src/main.rs:4:2
|
4 | f[&0] = 0;
| ^^^^^^^^^ cannot borrow as mutable
The error doesn't really tell you what is indexed immutably. IMO it should explain that hashmaps have the insert function instead and maybe even should suggest it.
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.