1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Test that we still see borrowck errors of various kinds when using
12 // indexing and autoderef in combination.
14 #![feature(associated_types)]
16 use std::ops::{Index, IndexMut};
23 impl Index<String> for Foo {
26 fn index<'a>(&'a self, z: &String) -> &'a int {
27 if z.as_slice() == "x" {
35 impl IndexMut<String> for Foo {
38 fn index_mut<'a>(&'a mut self, z: &String) -> &'a mut int {
39 if z.as_slice() == "x" {
47 fn test1(mut f: Box<Foo>, s: String) {
49 let _q = &f[s]; //~ ERROR cannot borrow
52 fn test2(mut f: Box<Foo>, s: String) {
54 let _q = &mut f[s]; //~ ERROR cannot borrow
61 fn test3(mut f: Box<Bar>, s: String) {
62 let _p = &mut f.foo[s];
63 let _q = &mut f.foo[s]; //~ ERROR cannot borrow
66 fn test4(mut f: Box<Bar>, s: String) {
71 fn test5(mut f: Box<Bar>, s: String) {
73 let _q = &mut f.foo[s]; //~ ERROR cannot borrow
76 fn test6(mut f: Box<Bar>, g: Foo, s: String) {
78 f.foo = g; //~ ERROR cannot assign
81 fn test7(mut f: Box<Bar>, g: Bar, s: String) {
83 *f = g; //~ ERROR cannot assign
86 fn test8(mut f: Box<Bar>, g: Foo, s: String) {
87 let _p = &mut f.foo[s];
88 f.foo = g; //~ ERROR cannot assign
91 fn test9(mut f: Box<Bar>, g: Bar, s: String) {
92 let _p = &mut f.foo[s];
93 *f = g; //~ ERROR cannot assign