]> git.lizzy.rs Git - rust.git/commit
Ignore arguments when looking for `IndexMut` for subsequent `mut` obligation
authorEsteban Küber <esteban@kuber.com.ar>
Sun, 10 May 2020 00:40:04 +0000 (17:40 -0700)
committerEsteban Küber <esteban@kuber.com.ar>
Mon, 11 May 2020 22:45:19 +0000 (15:45 -0700)
commit0dcde02cc7bdd47f48af12e911829390c2864c47
tree6819f4016c4f82ecb114286f369b76fb853bc83f
parent4802f097c86452cd2e09d44e88dbcb8e08266552
Ignore arguments when looking for `IndexMut` for subsequent `mut` obligation

Given code like `v[&field].boo();` where `field: String` and
`.boo(&mut self)`, typeck will have decided that `v` is accessed using
`Index`, but when `boo` adds a new `mut` obligation,
`convert_place_op_to_mutable` is called. When this happens, for *some
reason* the arguments' dereference adjustments are completely ignored
causing an error saying that `IndexMut` is not satisfied:

```
error[E0596]: cannot borrow data in an index of `Indexable` as mutable
  --> src/main.rs:30:5
   |
30 |     v[&field].boo();
   |     ^^^^^^^^^ cannot borrow as mutable
   |
   = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `Indexable`
```

This is not true, but by changing `try_overloaded_place_op` to retry
when given `Needs::MutPlace` without passing the argument types, the
example successfully compiles.

I believe there might be more appropriate ways to deal with this.
src/librustc_typeck/check/method/confirm.rs
src/test/ui/issues/issue-72002.rs [new file with mode: 0644]