diff options
| author | bors <bors@rust-lang.org> | 2018-08-09 22:05:18 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-08-09 22:05:18 +0000 |
| commit | fb65d7563c93509c343a98e5cccf8e5ab4506924 (patch) | |
| tree | 2694839888f65ed4f411cd8701def0275c2ca280 /src/test/incremental/thinlto | |
| parent | 8958ed672298148841b3b8d6371ce301e1cbbac1 (diff) | |
| parent | 24abef3689840ec2ad0bb6ccdbc7cbcfb3844a82 (diff) | |
| download | rust-fb65d7563c93509c343a98e5cccf8e5ab4506924.tar.gz rust-fb65d7563c93509c343a98e5cccf8e5ab4506924.zip | |
Auto merge of #52788 - LukasKalbertodt:improve-index-mut-error, r=estebank
Add help message for missing `IndexMut` impl
Code:
```rust
let mut map = HashMap::new();
map.insert("peter", 23);
map["peter"] = 27;
```
Before:
```
error[E0594]: cannot assign to immutable indexed content
--> src/main.rs:7:5
|
7 | map["peter"] = 27;
| ^^^^^^^^^^^^^^^^^ cannot borrow as mutable
```
With this change (just the `help` was added):
```
error[E0594]: cannot assign to immutable indexed content
--> index-error.rs:7:5
|
7 | map["peter"] = 27;
| ^^^^^^^^^^^^^^^^^ cannot borrow as mutable
|
= help: trait `IndexMut` is required to modify indexed content, but it is not implemented for std::collections::HashMap<&str, i32>
```
---
Yesterday I did some pair programming with a Rust-beginner. We created a type and implemented `Index` for it. Trying to modify the value returned by the index operation returns in a rather vague error that was not very clear for the Rust beginner. So I tried to improve the situation.
## Notes/questions for reviewers:
- Is the formulation OK like that? I'm fine with changing it.
- Can we be absolutely sure that `IndexMut` is actually not implemented in the case my `help` message is added? I'm fairly sure myself, but there could be some cases I didn't think of. Also, I don't know the compiler very well, so I don't know what exactly certain enum variants are used for.
- It would be nice to test if `IndexMut` is in fact not implemented for the type, but I couldn't figure out how to check that. If you think that additional check would be beneficial, could you tell me how to check if a trait is implemented?
- Do you think I should change the error message instead of only adding an additional help message?
Diffstat (limited to 'src/test/incremental/thinlto')
0 files changed, 0 insertions, 0 deletions
