librustc: Improve method autoderef/deref/index behavior more, and enable

`IndexMut` on mutable vectors.

This fixes a bug whereby the mutability fixups for method behavior were
not kicking in after autoderef failed to happen at any level. It also
adds support for `Index` to the fixer-upper.

Closes #12825.
This commit is contained in:
Patrick Walton 2014-10-10 15:17:59 -07:00
parent dfd52817ee
commit f7fb38729e
4 changed files with 75 additions and 55 deletions

View file

@ -68,12 +68,10 @@ pub fn main() {
*n -= 3; // Mutable deref + assignment with binary operation.
assert_eq!(n.counts(), (2, 3));
// Mutable deref used for calling a method taking &self.
// N.B. This is required because method lookup hasn't been performed so
// we don't know whether the called method takes mutable self, before
// the dereference itself is type-checked (a chicken-and-egg problem).
// Immutable deref used for calling a method taking &self. (The
// typechecker is smarter now about doing this.)
(*n).to_string();
assert_eq!(n.counts(), (2, 4));
assert_eq!(n.counts(), (3, 3));
// Mutable deref used for calling a method taking &mut self.
(*v).push(2);