diff --git a/src/test/compile-fail/borrowck-overloaded-index-2.rs b/src/test/compile-fail/borrowck-overloaded-index-2.rs index 01afe405d5e..87e647d16dd 100644 --- a/src/test/compile-fail/borrowck-overloaded-index-2.rs +++ b/src/test/compile-fail/borrowck-overloaded-index-2.rs @@ -8,13 +8,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_types)] + use std::ops::Index; struct MyVec { data: Vec, } -impl Index for MyVec { +impl Index for MyVec { + type Output = T; + fn index(&self, &i: &uint) -> &T { &self.data[i] } diff --git a/src/test/compile-fail/borrowck-overloaded-index-autoderef.rs b/src/test/compile-fail/borrowck-overloaded-index-autoderef.rs index e8949d4b30b..e7bd7cdf0b7 100644 --- a/src/test/compile-fail/borrowck-overloaded-index-autoderef.rs +++ b/src/test/compile-fail/borrowck-overloaded-index-autoderef.rs @@ -11,6 +11,8 @@ // 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 { @@ -18,7 +20,9 @@ struct Foo { y: int, } -impl Index for Foo { +impl Index for Foo { + type Output = int; + fn index<'a>(&'a self, z: &String) -> &'a int { if z.as_slice() == "x" { &self.x @@ -28,7 +32,9 @@ impl Index for Foo { } } -impl IndexMut for Foo { +impl IndexMut for Foo { + type Output = int; + fn index_mut<'a>(&'a mut self, z: &String) -> &'a mut int { if z.as_slice() == "x" { &mut self.x diff --git a/src/test/compile-fail/borrowck-overloaded-index.rs b/src/test/compile-fail/borrowck-overloaded-index.rs index 933d0f15e4e..532f32ce770 100644 --- a/src/test/compile-fail/borrowck-overloaded-index.rs +++ b/src/test/compile-fail/borrowck-overloaded-index.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_types)] + use std::ops::{Index, IndexMut}; struct Foo { @@ -15,7 +17,9 @@ struct Foo { y: int, } -impl Index for Foo { +impl Index for Foo { + type Output = int; + fn index<'a>(&'a self, z: &String) -> &'a int { if z.as_slice() == "x" { &self.x @@ -25,7 +29,9 @@ impl Index for Foo { } } -impl IndexMut for Foo { +impl IndexMut for Foo { + type Output = int; + fn index_mut<'a>(&'a mut self, z: &String) -> &'a mut int { if z.as_slice() == "x" { &mut self.x @@ -39,7 +45,9 @@ struct Bar { x: int, } -impl Index for Bar { +impl Index for Bar { + type Output = int; + fn index<'a>(&'a self, z: &int) -> &'a int { &self.x } diff --git a/src/test/compile-fail/dst-index.rs b/src/test/compile-fail/dst-index.rs index af97c864dc8..06d20c3361b 100644 --- a/src/test/compile-fail/dst-index.rs +++ b/src/test/compile-fail/dst-index.rs @@ -11,6 +11,8 @@ // Test that overloaded index expressions with DST result types // can't be used as rvalues +#![feature(associated_types)] + use std::ops::Index; use std::fmt::Show; @@ -18,7 +20,9 @@ struct S; impl Copy for S {} -impl Index for S { +impl Index for S { + type Output = str; + fn index<'a>(&'a self, _: &uint) -> &'a str { "hello" } @@ -28,7 +32,9 @@ struct T; impl Copy for T {} -impl Index for T { +impl Index for T { + type Output = Show + 'static; + fn index<'a>(&'a self, idx: &uint) -> &'a (Show + 'static) { static x: uint = 42; &x diff --git a/src/test/run-pass/dst-index.rs b/src/test/run-pass/dst-index.rs index eaf7131e1d8..6a69bfc248f 100644 --- a/src/test/run-pass/dst-index.rs +++ b/src/test/run-pass/dst-index.rs @@ -11,12 +11,16 @@ // Test that overloaded index expressions with DST result types // work and don't ICE. +#![feature(associated_types)] + use std::ops::Index; use std::fmt::Show; struct S; -impl Index for S { +impl Index for S { + type Output = str; + fn index<'a>(&'a self, _: &uint) -> &'a str { "hello" } @@ -24,7 +28,9 @@ impl Index for S { struct T; -impl Index for T { +impl Index for T { + type Output = Show + 'static; + fn index<'a>(&'a self, idx: &uint) -> &'a (Show + 'static) { static x: uint = 42; &x diff --git a/src/test/run-pass/issue-15734.rs b/src/test/run-pass/issue-15734.rs index e99b1dc5bef..f261098f538 100644 --- a/src/test/run-pass/issue-15734.rs +++ b/src/test/run-pass/issue-15734.rs @@ -10,7 +10,8 @@ // If `Index` used an associated type for its output, this test would // work more smoothly. -#![feature(old_orphan_check)] + +#![feature(associated_types, old_orphan_check)] use std::ops::Index; @@ -25,13 +26,17 @@ impl Mat { } } -impl Index<(uint, uint), T> for Mat { +impl Index<(uint, uint)> for Mat { + type Output = T; + fn index<'a>(&'a self, &(row, col): &(uint, uint)) -> &'a T { &self.data[row * self.cols + col] } } -impl<'a, T> Index<(uint, uint), T> for &'a Mat { +impl<'a, T> Index<(uint, uint)> for &'a Mat { + type Output = T; + fn index<'b>(&'b self, index: &(uint, uint)) -> &'b T { (*self).index(index) } @@ -39,7 +44,9 @@ impl<'a, T> Index<(uint, uint), T> for &'a Mat { struct Row { mat: M, row: uint, } -impl> Index for Row { +impl> Index for Row { + type Output = T; + fn index<'a>(&'a self, col: &uint) -> &'a T { &self.mat[(self.row, *col)] } diff --git a/src/test/run-pass/operator-overloading.rs b/src/test/run-pass/operator-overloading.rs index 58c433e570e..41e7586f1e3 100644 --- a/src/test/run-pass/operator-overloading.rs +++ b/src/test/run-pass/operator-overloading.rs @@ -51,7 +51,9 @@ impl ops::Not for Point { } } -impl ops::Index for Point { +impl ops::Index for Point { + type Output = int; + fn index(&self, x: &bool) -> &int { if *x { &self.x diff --git a/src/test/run-pass/overloaded-index-assoc-list.rs b/src/test/run-pass/overloaded-index-assoc-list.rs index 0347f8a29df..77bb981cfd9 100644 --- a/src/test/run-pass/overloaded-index-assoc-list.rs +++ b/src/test/run-pass/overloaded-index-assoc-list.rs @@ -11,6 +11,8 @@ // Test overloading of the `[]` operator. In particular test that it // takes its argument *by reference*. +#![feature(associated_types)] + use std::ops::Index; struct AssociationList { @@ -28,7 +30,9 @@ impl AssociationList { } } -impl Index for AssociationList { +impl Index for AssociationList { + type Output = V; + fn index<'a>(&'a self, index: &K) -> &'a V { for pair in self.pairs.iter() { if pair.key == *index { diff --git a/src/test/run-pass/overloaded-index-autoderef.rs b/src/test/run-pass/overloaded-index-autoderef.rs index dcb0c40c608..d141234287d 100644 --- a/src/test/run-pass/overloaded-index-autoderef.rs +++ b/src/test/run-pass/overloaded-index-autoderef.rs @@ -10,6 +10,8 @@ // Test overloaded indexing combined with autoderef. +#![feature(associated_types)] + use std::ops::{Index, IndexMut}; struct Foo { @@ -17,7 +19,9 @@ struct Foo { y: int, } -impl Index for Foo { +impl Index for Foo { + type Output = int; + fn index(&self, z: &int) -> &int { if *z == 0 { &self.x @@ -27,7 +31,9 @@ impl Index for Foo { } } -impl IndexMut for Foo { +impl IndexMut for Foo { + type Output = int; + fn index_mut(&mut self, z: &int) -> &mut int { if *z == 0 { &mut self.x diff --git a/src/test/run-pass/overloaded-index-in-field.rs b/src/test/run-pass/overloaded-index-in-field.rs index 1c06ed64fc7..9c6afc0912d 100644 --- a/src/test/run-pass/overloaded-index-in-field.rs +++ b/src/test/run-pass/overloaded-index-in-field.rs @@ -11,6 +11,8 @@ // Test using overloaded indexing when the "map" is stored in a // field. This caused problems at some point. +#![feature(associated_types)] + use std::ops::Index; struct Foo { @@ -22,7 +24,9 @@ struct Bar { foo: Foo } -impl Index for Foo { +impl Index for Foo { + type Output = int; + fn index(&self, z: &int) -> &int { if *z == 0 { &self.x diff --git a/src/test/run-pass/overloaded-index.rs b/src/test/run-pass/overloaded-index.rs index fdf7e7e2cbb..fe09b47cf0a 100644 --- a/src/test/run-pass/overloaded-index.rs +++ b/src/test/run-pass/overloaded-index.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(associated_types)] + use std::ops::{Index, IndexMut}; struct Foo { @@ -15,7 +17,9 @@ struct Foo { y: int, } -impl Index for Foo { +impl Index for Foo { + type Output = int; + fn index(&self, z: &int) -> &int { if *z == 0 { &self.x @@ -25,7 +29,9 @@ impl Index for Foo { } } -impl IndexMut for Foo { +impl IndexMut for Foo { + type Output = int; + fn index_mut(&mut self, z: &int) -> &mut int { if *z == 0 { &mut self.x