]> 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 e8949d4b30befd55320d2672a994b0d14d3343cc..99f396ef8143213af415dbca2a649d0b4e1cd167 100644 (file)
 use std::ops::{Index, IndexMut};
 
 struct Foo {
-    x: int,
-    y: int,
+    x: isize,
+    y: isize,
 }
 
-impl Index<String,int> for Foo {
-    fn index<'a>(&'a self, z: &String) -> &'a int {
-        if z.as_slice() == "x" {
+impl Index<String> for Foo {
+    type Output = isize;
+
+    fn index<'a>(&'a self, z: &String) -> &'a isize {
+        if *z == "x" {
             &self.x
         } else {
             &self.y
@@ -28,9 +30,9 @@ fn index<'a>(&'a self, z: &String) -> &'a int {
     }
 }
 
-impl IndexMut<String,int> for Foo {
-    fn index_mut<'a>(&'a mut self, z: &String) -> &'a mut int {
-        if z.as_slice() == "x" {
+impl IndexMut<String> for Foo {
+    fn index_mut<'a>(&'a mut self, z: &String) -> &'a mut isize {
+        if *z == "x" {
             &mut self.x
         } else {
             &mut self.y
@@ -89,5 +91,3 @@ fn test9(mut f: Box<Bar>, g: Bar, s: String) {
 
 fn main() {
 }
-
-