]> git.lizzy.rs Git - rust.git/blobdiff - src/test/compile-fail/borrowck-overloaded-index-autoderef.rs
make `IndexMut` a super trait over `Index`
[rust.git] / src / test / compile-fail / borrowck-overloaded-index-autoderef.rs
index e7bd7cdf0b79de2be624f24f04589d85aea334f1..99f396ef8143213af415dbca2a649d0b4e1cd167 100644 (file)
 // Test that we still see borrowck errors of various kinds when using
 // indexing and autoderef in combination.
 
-#![feature(associated_types)]
-
 use std::ops::{Index, IndexMut};
 
 struct Foo {
-    x: int,
-    y: int,
+    x: isize,
+    y: isize,
 }
 
 impl Index<String> for Foo {
-    type Output = int;
+    type Output = isize;
 
-    fn index<'a>(&'a self, z: &String) -> &'a int {
-        if z.as_slice() == "x" {
+    fn index<'a>(&'a self, z: &String) -> &'a isize {
+        if *z == "x" {
             &self.x
         } else {
             &self.y
@@ -33,10 +31,8 @@ fn index<'a>(&'a self, z: &String) -> &'a int {
 }
 
 impl IndexMut<String> for Foo {
-    type Output = int;
-
-    fn index_mut<'a>(&'a mut self, z: &String) -> &'a mut int {
-        if z.as_slice() == "x" {
+    fn index_mut<'a>(&'a mut self, z: &String) -> &'a mut isize {
+        if *z == "x" {
             &mut self.x
         } else {
             &mut self.y
@@ -95,5 +91,3 @@ fn test9(mut f: Box<Bar>, g: Bar, s: String) {
 
 fn main() {
 }
-
-