1 // Test that we still see borrowck errors of various kinds when using
2 // indexing and autoderef in combination.
4 use std::ops::{Index, IndexMut};
13 impl<'a> Index<&'a String> for Foo {
16 fn index(&self, z: &String) -> &isize {
25 impl<'a> IndexMut<&'a String> for Foo {
26 fn index_mut(&mut self, z: &String) -> &mut isize {
35 fn test1(mut f: Box<Foo>, s: String) {
37 let q = &f[&s]; //~ ERROR cannot borrow
41 fn test2(mut f: Box<Foo>, s: String) {
43 let q = &mut f[&s]; //~ ERROR cannot borrow
51 fn test3(mut f: Box<Bar>, s: String) {
52 let p = &mut f.foo[&s];
53 let q = &mut f.foo[&s]; //~ ERROR cannot borrow
57 fn test4(mut f: Box<Bar>, s: String) {
63 fn test5(mut f: Box<Bar>, s: String) {
65 let q = &mut f.foo[&s]; //~ ERROR cannot borrow
69 fn test6(mut f: Box<Bar>, g: Foo, s: String) {
71 f.foo = g; //~ ERROR cannot assign
75 fn test7(mut f: Box<Bar>, g: Bar, s: String) {
77 *f = g; //~ ERROR cannot assign
81 fn test8(mut f: Box<Bar>, g: Foo, s: String) {
82 let p = &mut f.foo[&s];
83 f.foo = g; //~ ERROR cannot assign
87 fn test9(mut f: Box<Bar>, g: Bar, s: String) {
88 let p = &mut f.foo[&s];
89 *f = g; //~ ERROR cannot assign
96 trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
97 impl<T> Fake for T { }