rust/src/test/ui/borrowck
bors fb65d7563c 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?
2018-08-09 22:05:18 +00:00
..
borrowck-box-insensitivity.nll.stderr Fix erroneous error note when using field after move 2018-06-22 18:23:33 -03:00
borrowck-box-insensitivity.rs Be ambiguous when type cannot be properly mentioned 2018-01-02 19:49:38 -08:00
borrowck-box-insensitivity.stderr update tests 2018-03-14 00:53:24 +01:00
borrowck-closures-two-mut.rs remove -Znll -- borrowck=mir implies nll now 2018-04-15 07:13:42 -04:00
borrowck-closures-two-mut.stderr Update tests for new spans for nll errors involving closures 2018-08-03 23:00:27 +01:00
borrowck-escaping-closure-error-1.nll.stderr Update tests for new spans for nll errors involving closures 2018-08-03 23:00:27 +01:00
borrowck-escaping-closure-error-1.rs Remove NOTE/HELP annotations from UI tests 2017-12-14 23:26:39 +03:00
borrowck-escaping-closure-error-1.stderr update tests 2018-03-14 00:53:24 +01:00
borrowck-escaping-closure-error-2.nll.stderr Update tests for new spans for nll errors involving closures 2018-08-03 23:00:27 +01:00
borrowck-escaping-closure-error-2.rs Remove NOTE/HELP annotations from UI tests 2017-12-14 23:26:39 +03:00
borrowck-escaping-closure-error-2.stderr update tests 2018-03-14 00:53:24 +01:00
borrowck-feature-nll-overrides-migrate.edition.stderr Incorporate edition flag testing into tests of -Z borrowck=migrate. 2018-07-26 14:59:00 +02:00
borrowck-feature-nll-overrides-migrate.rs Incorporate edition flag testing into tests of -Z borrowck=migrate. 2018-07-26 14:59:00 +02:00
borrowck-feature-nll-overrides-migrate.zflag.stderr Incorporate edition flag testing into tests of -Z borrowck=migrate. 2018-07-26 14:59:00 +02:00
borrowck-in-static.nll.stderr Add specific message when moving from upvars in a non-FnOnce closure 2018-07-21 18:40:46 +01:00
borrowck-in-static.rs Remove NOTE/HELP annotations from UI tests 2017-12-14 23:26:39 +03:00
borrowck-in-static.stderr update tests 2018-03-14 00:53:24 +01:00
borrowck-migrate-to-nll.edition.stderr Incorporate edition flag testing into tests of -Z borrowck=migrate. 2018-07-26 14:59:00 +02:00
borrowck-migrate-to-nll.rs Incorporate edition flag testing into tests of -Z borrowck=migrate. 2018-07-26 14:59:00 +02:00
borrowck-migrate-to-nll.zflag.stderr Incorporate edition flag testing into tests of -Z borrowck=migrate. 2018-07-26 14:59:00 +02:00
borrowck-move-error-with-note.nll.stderr NLL: On "cannot move out of type" error, print original source before rewrite. 2018-07-31 17:27:29 +02:00
borrowck-move-error-with-note.rs Remove NOTE/HELP annotations from UI tests 2017-12-14 23:26:39 +03:00
borrowck-move-error-with-note.stderr update tests 2018-03-14 00:53:24 +01:00
borrowck-move-out-of-vec-tail.nll.stderr NLL: On "cannot move out of type" error, print original source before rewrite. 2018-07-31 17:27:29 +02:00
borrowck-move-out-of-vec-tail.rs Remove NOTE/HELP annotations from UI tests 2017-12-14 23:26:39 +03:00
borrowck-move-out-of-vec-tail.stderr update tests 2018-03-14 00:53:24 +01:00
borrowck-reinit.rs Update tests for -Zborrowck-mir -> -Zborrowck=mode migration 2017-11-26 16:39:15 +01:00
borrowck-reinit.stderr update tests 2018-03-14 00:53:24 +01:00
borrowck-report-with-custom-diagnostic.nll.stderr rust-lang/rust#51025: improve test robustness so that they work under NLL too. 2018-05-25 13:00:51 +02:00
borrowck-report-with-custom-diagnostic.rs rust-lang/rust#51025: improve test robustness so that they work under NLL too. 2018-05-25 13:00:51 +02:00
borrowck-report-with-custom-diagnostic.stderr rust-lang/rust#51025: improve test robustness so that they work under NLL too. 2018-05-25 13:00:51 +02:00
borrowck-slice-pattern-element-loan.rs fix for issue #8636 2018-07-05 11:34:10 +01:00
borrowck-slice-pattern-element-loan.stderr fix for issue #8636 2018-07-05 11:34:10 +01:00
borrowck-vec-pattern-nesting.nll.stderr NLL: On "cannot move out of type" error, print original source before rewrite. 2018-07-31 17:27:29 +02:00
borrowck-vec-pattern-nesting.rs Drive-by: Make assignment conflict tests in borrowck-vec-pattern-nesting.rs robust for NLL. 2018-06-06 22:42:27 +02:00
borrowck-vec-pattern-nesting.stderr Update the expected error output to reflect changes in this PR. 2018-06-06 22:42:27 +02:00
immutable-arg.rs Modify message to match label 2018-01-10 11:41:12 -08:00
immutable-arg.stderr Update the existing UI tests to reflect diagnostic changes in NLL. 2018-06-19 19:41:48 +02:00
index-mut-help.nll.stderr Add and update tests for IndexMut help message 2018-08-08 00:30:17 +02:00
index-mut-help.rs Add and update tests for IndexMut help message 2018-08-08 00:30:17 +02:00
index-mut-help.stderr Add and update tests for IndexMut help message 2018-08-08 00:30:17 +02:00
issue-7573.nll.stderr Fallback to general error handling in ICE cases. 2018-07-22 12:53:55 +01:00
issue-7573.rs Tweak wording and spans of closure lifetime errors 2018-01-19 13:28:43 -08:00
issue-7573.stderr Update UI tests 2018-02-26 20:24:42 +03:00
issue-41962.rs Fix erroneous error note when using field after move 2018-06-22 18:23:33 -03:00
issue-41962.stderr Update tests that use -Z borrowck=compare or #[feature(nll)] to accmmodate diagnostic change. 2018-07-31 14:36:50 +02:00
issue-45983.ast.stderr An attempt to fix NLL migration mode so that reports region errors when necessary. 2018-08-04 00:12:15 +02:00
issue-45983.migrate.stderr An attempt to fix NLL migration mode so that reports region errors when necessary. 2018-08-04 00:12:15 +02:00
issue-45983.nll.stderr An attempt to fix NLL migration mode so that reports region errors when necessary. 2018-08-04 00:12:15 +02:00
issue-45983.rs An attempt to fix NLL migration mode so that reports region errors when necessary. 2018-08-04 00:12:15 +02:00
issue-51117.nll.stderr change PointerKind::Implicit to a note 2018-05-31 10:17:51 -04:00
issue-51117.rs change PointerKind::Implicit to a note 2018-05-31 10:17:51 -04:00
issue-51117.stderr change PointerKind::Implicit to a note 2018-05-31 10:17:51 -04:00
issue-51348-multi-ref-mut-in-guard.rs Regression test for the bug. 2018-07-26 15:15:19 +02:00
issue-51415.nll.stderr NLL: On "cannot move out of type" error, print original source before rewrite. 2018-07-31 17:27:29 +02:00
issue-51415.rs use pat_ty_adjusted from expr_use_visitor to type of arguments 2018-06-21 14:32:52 -04:00
issue-51415.stderr use pat_ty_adjusted from expr_use_visitor to type of arguments 2018-06-21 14:32:52 -04:00
issue-52713-bug.rs add test case showing how previous attempt was unsound 2018-08-06 09:00:35 -04:00
issue-52713-bug.stderr add test case showing how previous attempt was unsound 2018-08-06 09:00:35 -04:00
issue-52967-edition-2018-needs-two-phase-borrows.rs When we turn on NLL migration in the 2018 edition, we need two-phase borrows too! 2018-08-02 13:51:13 +02:00
mut-borrow-in-loop.nll.stderr consolidate and use find_sub_region_live_at for everything 2018-07-25 06:38:21 +03:00
mut-borrow-in-loop.rs Merge cfail and ui tests into ui tests 2017-11-24 11:32:35 +01:00
mut-borrow-in-loop.stderr update tests 2018-03-14 00:53:24 +01:00
mut-borrow-of-mut-ref.nll.stderr Update tests for new NLL mutability errors 2018-07-20 20:01:15 +01:00
mut-borrow-of-mut-ref.rs Suggest not mutably borrowing a mutable reference 2018-06-01 23:17:10 +02:00
mut-borrow-of-mut-ref.stderr Suggest not mutably borrowing a mutable reference 2018-06-01 23:17:10 +02:00
mut-borrow-outside-loop.nll.stderr Errors are more specific in cases where borrows are used in future iterations of loops. 2018-08-01 17:42:15 +02:00
mut-borrow-outside-loop.rs rust-lang/rust#51025: improve test robustness so that they work under NLL too. 2018-05-25 13:00:51 +02:00
mut-borrow-outside-loop.stderr rust-lang/rust#51025: improve test robustness so that they work under NLL too. 2018-05-25 13:00:51 +02:00
mutability-errors.nll.stderr Update tests for new NLL mutability errors 2018-07-20 20:01:15 +01:00
mutability-errors.rs Update tests for new NLL mutability errors 2018-07-20 20:01:15 +01:00
mutability-errors.stderr Update tests for new NLL mutability errors 2018-07-20 20:01:15 +01:00
promote-ref-mut-in-let-issue-46557.nll.stderr revert #52991 2018-08-06 09:00:08 -04:00
promote-ref-mut-in-let-issue-46557.rs also check let arms and nested patterns for mutable borrows 2018-06-01 10:06:02 -04:00
promote-ref-mut-in-let-issue-46557.stderr also check let arms and nested patterns for mutable borrows 2018-06-01 10:06:02 -04:00
regions-bound-missing-bound-in-impl.rs Also point to free named region on lifetime errors 2018-06-28 11:12:44 -07:00
regions-bound-missing-bound-in-impl.stderr Also point to free named region on lifetime errors 2018-06-28 11:12:44 -07:00
regions-escape-bound-fn-2.nll.stderr Improved closure errors. 2018-07-22 12:49:35 +01:00
regions-escape-bound-fn-2.rs Move diagnostic logic to its own module 2018-01-15 11:12:25 -08:00
regions-escape-bound-fn-2.stderr Update UI tests 2018-02-26 20:24:02 +03:00
regions-escape-bound-fn.nll.stderr Improved closure errors. 2018-07-22 12:49:35 +01:00
regions-escape-bound-fn.rs Move diagnostic logic to its own module 2018-01-15 11:12:25 -08:00
regions-escape-bound-fn.stderr Update UI tests 2018-02-26 20:24:02 +03:00
regions-escape-unboxed-closure.nll.stderr Improved closure errors. 2018-07-22 12:49:35 +01:00
regions-escape-unboxed-closure.rs Move diagnostic logic to its own module 2018-01-15 11:12:25 -08:00
regions-escape-unboxed-closure.stderr Update UI tests 2018-02-26 20:24:02 +03:00
two-phase-method-receivers.rs remove -Znll -- borrowck=mir implies nll now 2018-04-15 07:13:42 -04:00
two-phase-multi-mut.rs Add test from #49736 2018-04-06 15:00:45 -04:00
two-phase-multi-mut.stderr Update tests that use -Z borrowck=compare or #[feature(nll)] to accmmodate diagnostic change. 2018-07-31 14:36:50 +02:00
two-phase-multiple-activations.rs remove -Znll -- borrowck=mir implies nll now 2018-04-15 07:13:42 -04:00
unboxed-closures-move-upvar-from-non-once-ref-closure.nll.stderr Add specific message when moving from upvars in a non-FnOnce closure 2018-07-21 18:40:46 +01:00
unboxed-closures-move-upvar-from-non-once-ref-closure.rs Remove NOTE/HELP annotations from UI tests 2017-12-14 23:26:39 +03:00
unboxed-closures-move-upvar-from-non-once-ref-closure.stderr update tests 2018-03-14 00:53:24 +01:00