Skip to content

Commit 9aadbad

Browse files
author
Jorge Aparicio
committed
fix rpass/cfail tests
1 parent 6fc9257 commit 9aadbad

11 files changed

+80
-21
lines changed

src/test/compile-fail/borrowck-overloaded-index-2.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(associated_types)]
12+
1113
use std::ops::Index;
1214

1315
struct MyVec<T> {
1416
data: Vec<T>,
1517
}
1618

17-
impl<T> Index<uint, T> for MyVec<T> {
19+
impl<T> Index<uint> for MyVec<T> {
20+
type Output = T;
21+
1822
fn index(&self, &i: &uint) -> &T {
1923
&self.data[i]
2024
}

src/test/compile-fail/borrowck-overloaded-index-autoderef.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@
1111
// Test that we still see borrowck errors of various kinds when using
1212
// indexing and autoderef in combination.
1313

14+
#![feature(associated_types)]
15+
1416
use std::ops::{Index, IndexMut};
1517

1618
struct Foo {
1719
x: int,
1820
y: int,
1921
}
2022

21-
impl Index<String,int> for Foo {
23+
impl Index<String> for Foo {
24+
type Output = int;
25+
2226
fn index<'a>(&'a self, z: &String) -> &'a int {
2327
if z.as_slice() == "x" {
2428
&self.x
@@ -28,7 +32,9 @@ impl Index<String,int> for Foo {
2832
}
2933
}
3034

31-
impl IndexMut<String,int> for Foo {
35+
impl IndexMut<String> for Foo {
36+
type Output = int;
37+
3238
fn index_mut<'a>(&'a mut self, z: &String) -> &'a mut int {
3339
if z.as_slice() == "x" {
3440
&mut self.x

src/test/compile-fail/borrowck-overloaded-index.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(associated_types)]
12+
1113
use std::ops::{Index, IndexMut};
1214

1315
struct Foo {
1416
x: int,
1517
y: int,
1618
}
1719

18-
impl Index<String,int> for Foo {
20+
impl Index<String> for Foo {
21+
type Output = int;
22+
1923
fn index<'a>(&'a self, z: &String) -> &'a int {
2024
if z.as_slice() == "x" {
2125
&self.x
@@ -25,7 +29,9 @@ impl Index<String,int> for Foo {
2529
}
2630
}
2731

28-
impl IndexMut<String,int> for Foo {
32+
impl IndexMut<String> for Foo {
33+
type Output = int;
34+
2935
fn index_mut<'a>(&'a mut self, z: &String) -> &'a mut int {
3036
if z.as_slice() == "x" {
3137
&mut self.x
@@ -39,7 +45,9 @@ struct Bar {
3945
x: int,
4046
}
4147

42-
impl Index<int,int> for Bar {
48+
impl Index<int> for Bar {
49+
type Output = int;
50+
4351
fn index<'a>(&'a self, z: &int) -> &'a int {
4452
&self.x
4553
}

src/test/compile-fail/dst-index.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@
1111
// Test that overloaded index expressions with DST result types
1212
// can't be used as rvalues
1313

14+
#![feature(associated_types)]
15+
1416
use std::ops::Index;
1517
use std::fmt::Show;
1618

1719
struct S;
1820

1921
impl Copy for S {}
2022

21-
impl Index<uint, str> for S {
23+
impl Index<uint> for S {
24+
type Output = str;
25+
2226
fn index<'a>(&'a self, _: &uint) -> &'a str {
2327
"hello"
2428
}
@@ -28,7 +32,9 @@ struct T;
2832

2933
impl Copy for T {}
3034

31-
impl Index<uint, Show + 'static> for T {
35+
impl Index<uint> for T {
36+
type Output = Show + 'static;
37+
3238
fn index<'a>(&'a self, idx: &uint) -> &'a (Show + 'static) {
3339
static x: uint = 42;
3440
&x

src/test/run-pass/dst-index.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,26 @@
1111
// Test that overloaded index expressions with DST result types
1212
// work and don't ICE.
1313

14+
#![feature(associated_types)]
15+
1416
use std::ops::Index;
1517
use std::fmt::Show;
1618

1719
struct S;
1820

19-
impl Index<uint, str> for S {
21+
impl Index<uint> for S {
22+
type Output = str;
23+
2024
fn index<'a>(&'a self, _: &uint) -> &'a str {
2125
"hello"
2226
}
2327
}
2428

2529
struct T;
2630

27-
impl Index<uint, Show + 'static> for T {
31+
impl Index<uint> for T {
32+
type Output = Show + 'static;
33+
2834
fn index<'a>(&'a self, idx: &uint) -> &'a (Show + 'static) {
2935
static x: uint = 42;
3036
&x

src/test/run-pass/issue-15734.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
// If `Index` used an associated type for its output, this test would
1212
// work more smoothly.
13-
#![feature(old_orphan_check)]
13+
14+
#![feature(associated_types, old_orphan_check)]
1415

1516
use std::ops::Index;
1617

@@ -25,21 +26,27 @@ impl<T> Mat<T> {
2526
}
2627
}
2728

28-
impl<T> Index<(uint, uint), T> for Mat<T> {
29+
impl<T> Index<(uint, uint)> for Mat<T> {
30+
type Output = T;
31+
2932
fn index<'a>(&'a self, &(row, col): &(uint, uint)) -> &'a T {
3033
&self.data[row * self.cols + col]
3134
}
3235
}
3336

34-
impl<'a, T> Index<(uint, uint), T> for &'a Mat<T> {
37+
impl<'a, T> Index<(uint, uint)> for &'a Mat<T> {
38+
type Output = T;
39+
3540
fn index<'b>(&'b self, index: &(uint, uint)) -> &'b T {
3641
(*self).index(index)
3742
}
3843
}
3944

4045
struct Row<M> { mat: M, row: uint, }
4146

42-
impl<T, M: Index<(uint, uint), T>> Index<uint, T> for Row<M> {
47+
impl<T, M: Index<(uint, uint), Output=T>> Index<uint> for Row<M> {
48+
type Output = T;
49+
4350
fn index<'a>(&'a self, col: &uint) -> &'a T {
4451
&self.mat[(self.row, *col)]
4552
}

src/test/run-pass/operator-overloading.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ impl ops::Not for Point {
5151
}
5252
}
5353

54-
impl ops::Index<bool,int> for Point {
54+
impl ops::Index<bool> for Point {
55+
type Output = int;
56+
5557
fn index(&self, x: &bool) -> &int {
5658
if *x {
5759
&self.x

src/test/run-pass/overloaded-index-assoc-list.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
// Test overloading of the `[]` operator. In particular test that it
1212
// takes its argument *by reference*.
1313

14+
#![feature(associated_types)]
15+
1416
use std::ops::Index;
1517

1618
struct AssociationList<K,V> {
@@ -28,7 +30,9 @@ impl<K,V> AssociationList<K,V> {
2830
}
2931
}
3032

31-
impl<K: PartialEq + std::fmt::Show, V:Clone> Index<K,V> for AssociationList<K,V> {
33+
impl<K: PartialEq + std::fmt::Show, V:Clone> Index<K> for AssociationList<K,V> {
34+
type Output = V;
35+
3236
fn index<'a>(&'a self, index: &K) -> &'a V {
3337
for pair in self.pairs.iter() {
3438
if pair.key == *index {

src/test/run-pass/overloaded-index-autoderef.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@
1010

1111
// Test overloaded indexing combined with autoderef.
1212

13+
#![feature(associated_types)]
14+
1315
use std::ops::{Index, IndexMut};
1416

1517
struct Foo {
1618
x: int,
1719
y: int,
1820
}
1921

20-
impl Index<int,int> for Foo {
22+
impl Index<int> for Foo {
23+
type Output = int;
24+
2125
fn index(&self, z: &int) -> &int {
2226
if *z == 0 {
2327
&self.x
@@ -27,7 +31,9 @@ impl Index<int,int> for Foo {
2731
}
2832
}
2933

30-
impl IndexMut<int,int> for Foo {
34+
impl IndexMut<int> for Foo {
35+
type Output = int;
36+
3137
fn index_mut(&mut self, z: &int) -> &mut int {
3238
if *z == 0 {
3339
&mut self.x

src/test/run-pass/overloaded-index-in-field.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
// Test using overloaded indexing when the "map" is stored in a
1212
// field. This caused problems at some point.
1313

14+
#![feature(associated_types)]
15+
1416
use std::ops::Index;
1517

1618
struct Foo {
@@ -22,7 +24,9 @@ struct Bar {
2224
foo: Foo
2325
}
2426

25-
impl Index<int,int> for Foo {
27+
impl Index<int> for Foo {
28+
type Output = int;
29+
2630
fn index(&self, z: &int) -> &int {
2731
if *z == 0 {
2832
&self.x

src/test/run-pass/overloaded-index.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(associated_types)]
12+
1113
use std::ops::{Index, IndexMut};
1214

1315
struct Foo {
1416
x: int,
1517
y: int,
1618
}
1719

18-
impl Index<int,int> for Foo {
20+
impl Index<int> for Foo {
21+
type Output = int;
22+
1923
fn index(&self, z: &int) -> &int {
2024
if *z == 0 {
2125
&self.x
@@ -25,7 +29,9 @@ impl Index<int,int> for Foo {
2529
}
2630
}
2731

28-
impl IndexMut<int,int> for Foo {
32+
impl IndexMut<int> for Foo {
33+
type Output = int;
34+
2935
fn index_mut(&mut self, z: &int) -> &mut int {
3036
if *z == 0 {
3137
&mut self.x

0 commit comments

Comments
 (0)