diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2013-03-05 17:49:50 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2013-03-06 11:02:19 -0500 |
| commit | 6d764cc361b2e82f6ffead7bb7ddea18adf31481 (patch) | |
| tree | 2847021a9128d699f6e618128d40a88024b782cb /src/test | |
| parent | 6267339d6869a27b95f13c578a235204a1562697 (diff) | |
| download | rust-6d764cc361b2e82f6ffead7bb7ddea18adf31481.tar.gz rust-6d764cc361b2e82f6ffead7bb7ddea18adf31481.zip | |
Make object types not implement associated trait. Fixes #5087.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/object-does-not-impl-trait.rs (renamed from src/test/run-pass/autoderef-method-on-trait-monomorphized.rs) | 21 | ||||
| -rw-r--r-- | src/test/compile-fail/regions-trait-3.rs | 12 | ||||
| -rw-r--r-- | src/test/compile-fail/selftype-astparam.rs | 25 | ||||
| -rw-r--r-- | src/test/compile-fail/trait-cast.rs | 21 | ||||
| -rw-r--r-- | src/test/run-pass/class-cast-to-trait-cross-crate-2.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/class-cast-to-trait-multiple-types.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/class-separate-impl.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/explicit-self-objects-ext-1.rs | 39 | ||||
| -rw-r--r-- | src/test/run-pass/explicit-self-objects-ext-2.rs | 39 | ||||
| -rw-r--r-- | src/test/run-pass/explicit-self-objects-ext-3.rs | 39 | ||||
| -rw-r--r-- | src/test/run-pass/explicit-self-objects-ext-4.rs | 39 | ||||
| -rw-r--r-- | src/test/run-pass/issue-2611.rs | 8 | ||||
| -rw-r--r-- | src/test/run-pass/issue-3305.rs | 26 |
13 files changed, 23 insertions, 252 deletions
diff --git a/src/test/run-pass/autoderef-method-on-trait-monomorphized.rs b/src/test/compile-fail/object-does-not-impl-trait.rs index bfde19993e9..886b849dbef 100644 --- a/src/test/run-pass/autoderef-method-on-trait-monomorphized.rs +++ b/src/test/compile-fail/object-does-not-impl-trait.rs @@ -8,19 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -trait double { - fn double() -> uint; -} +// Test that an object type `@Foo` is not considered to implement the +// trait `Foo`. Issue #5087. -impl double for uint { - fn double() -> uint { self * 2u } -} - -fn is_equal<D:double>(x: @D, exp: uint) { - assert x.double() == exp; -} - -pub fn main() { - let x = @(@3u as @double); - is_equal(x, 6); -} +trait Foo {} +fn take_foo<F:Foo>(f: F) {} +fn take_object(f: @Foo) { take_foo(f); } //~ ERROR failed to find an implementation of trait +fn main() {} diff --git a/src/test/compile-fail/regions-trait-3.rs b/src/test/compile-fail/regions-trait-3.rs index 0ddaf25710c..a10c239617e 100644 --- a/src/test/compile-fail/regions-trait-3.rs +++ b/src/test/compile-fail/regions-trait-3.rs @@ -16,8 +16,16 @@ fn make_gc1(gc: get_ctxt/&a) -> get_ctxt/&b { return gc; //~ ERROR mismatched types: expected `@get_ctxt/&b` but found `@get_ctxt/&a` } -fn make_gc2(gc: get_ctxt/&a) -> get_ctxt/&b { - return @gc as get_ctxt; //~ ERROR cannot infer an appropriate lifetime +struct Foo { + r: &'self uint +} + +impl get_ctxt/&self for Foo/&self { + fn get_ctxt() -> &self/uint { self.r } +} + +fn make_gc2(foo: Foo/&a) -> get_ctxt/&b { + return @foo as get_ctxt; //~ ERROR cannot infer an appropriate lifetime } fn main() { diff --git a/src/test/compile-fail/selftype-astparam.rs b/src/test/compile-fail/selftype-astparam.rs deleted file mode 100644 index 08b6c0f71fe..00000000000 --- a/src/test/compile-fail/selftype-astparam.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -trait add { - fn plus(++x: Self) -> Self; -} - -impl add for int { - fn plus(++x: int) -> int { self + x } -} - -fn do_add<A:add>(x: A, y: A) -> A { x.plus(y) } - -fn main() { - let x = @3 as @add; - let y = @4 as @add; - do_add(x, y); //~ ERROR a boxed trait with self types may not be passed as a bounded type -} diff --git a/src/test/compile-fail/trait-cast.rs b/src/test/compile-fail/trait-cast.rs deleted file mode 100644 index d0738be09c7..00000000000 --- a/src/test/compile-fail/trait-cast.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -trait foo<T> { } - -fn bar(x: foo<uint>) -> foo<int> { - return (@x as foo::<int>); - //~^ ERROR mismatched types: expected `@foo<int>` but found `@foo<uint>` - //~^^ ERROR mismatched types: expected `@foo<int>` but found `@foo<uint>` - // This is unfortunate -- new handling of parens means the error message - // gets printed twice -} - -fn main() {} diff --git a/src/test/run-pass/class-cast-to-trait-cross-crate-2.rs b/src/test/run-pass/class-cast-to-trait-cross-crate-2.rs index 1db3d4b38d7..53c50d7fca0 100644 --- a/src/test/run-pass/class-cast-to-trait-cross-crate-2.rs +++ b/src/test/run-pass/class-cast-to-trait-cross-crate-2.rs @@ -14,7 +14,7 @@ extern mod cci_class_cast; use core::to_str::ToStr; use cci_class_cast::kitty::*; -fn print_out<T:ToStr>(thing: T, expected: ~str) { +fn print_out(thing: @ToStr, expected: ~str) { let actual = thing.to_str(); debug!("%s", actual); assert(actual == expected); diff --git a/src/test/run-pass/class-cast-to-trait-multiple-types.rs b/src/test/run-pass/class-cast-to-trait-multiple-types.rs index 5cf68174075..39466bb8c16 100644 --- a/src/test/run-pass/class-cast-to-trait-multiple-types.rs +++ b/src/test/run-pass/class-cast-to-trait-multiple-types.rs @@ -79,7 +79,7 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat { } -fn annoy_neighbors<T:noisy>(critter: T) { +fn annoy_neighbors(critter: @noisy) { for uint::range(0u, 10u) |i| { critter.speak(); } } diff --git a/src/test/run-pass/class-separate-impl.rs b/src/test/run-pass/class-separate-impl.rs index b232be32550..eb0d8de7eab 100644 --- a/src/test/run-pass/class-separate-impl.rs +++ b/src/test/run-pass/class-separate-impl.rs @@ -56,7 +56,7 @@ impl ToStr for cat { pure fn to_str(&self) -> ~str { copy self.name } } -fn print_out<T:ToStr>(thing: T, expected: ~str) { +fn print_out(thing: @ToStr, expected: ~str) { let actual = thing.to_str(); debug!("%s", actual); assert(actual == expected); diff --git a/src/test/run-pass/explicit-self-objects-ext-1.rs b/src/test/run-pass/explicit-self-objects-ext-1.rs deleted file mode 100644 index 92f745d7d53..00000000000 --- a/src/test/run-pass/explicit-self-objects-ext-1.rs +++ /dev/null @@ -1,39 +0,0 @@ -pub trait Reader { - // FIXME (#2004): Seekable really should be orthogonal. - - /// Read up to len bytes (or EOF) and put them into bytes (which - /// must be at least len bytes long). Return number of bytes read. - // FIXME (#2982): This should probably return an error. - fn read(&self, bytes: &mut [u8], len: uint) -> uint; -} - -pub trait ReaderUtil { - - /// Read len bytes into a new vec. - fn read_bytes(&self, len: uint); -} - -impl<T:Reader> ReaderUtil for T { - - fn read_bytes(&self, len: uint) { - let mut count = self.read(&mut [0], len); - } - -} - -struct S { - x: int, - y: int -} - -impl Reader for S { - fn read(&self, bytes: &mut [u8], len: uint) -> uint { - 0 - } -} - -pub fn main() { - let x = S { x: 1, y: 2 }; - let x = @x as @Reader; - x.read_bytes(0); -} diff --git a/src/test/run-pass/explicit-self-objects-ext-2.rs b/src/test/run-pass/explicit-self-objects-ext-2.rs deleted file mode 100644 index 92f745d7d53..00000000000 --- a/src/test/run-pass/explicit-self-objects-ext-2.rs +++ /dev/null @@ -1,39 +0,0 @@ -pub trait Reader { - // FIXME (#2004): Seekable really should be orthogonal. - - /// Read up to len bytes (or EOF) and put them into bytes (which - /// must be at least len bytes long). Return number of bytes read. - // FIXME (#2982): This should probably return an error. - fn read(&self, bytes: &mut [u8], len: uint) -> uint; -} - -pub trait ReaderUtil { - - /// Read len bytes into a new vec. - fn read_bytes(&self, len: uint); -} - -impl<T:Reader> ReaderUtil for T { - - fn read_bytes(&self, len: uint) { - let mut count = self.read(&mut [0], len); - } - -} - -struct S { - x: int, - y: int -} - -impl Reader for S { - fn read(&self, bytes: &mut [u8], len: uint) -> uint { - 0 - } -} - -pub fn main() { - let x = S { x: 1, y: 2 }; - let x = @x as @Reader; - x.read_bytes(0); -} diff --git a/src/test/run-pass/explicit-self-objects-ext-3.rs b/src/test/run-pass/explicit-self-objects-ext-3.rs deleted file mode 100644 index 2cfd327dc4e..00000000000 --- a/src/test/run-pass/explicit-self-objects-ext-3.rs +++ /dev/null @@ -1,39 +0,0 @@ -pub trait Reader { - // FIXME (#2004): Seekable really should be orthogonal. - - /// Read up to len bytes (or EOF) and put them into bytes (which - /// must be at least len bytes long). Return number of bytes read. - // FIXME (#2982): This should probably return an error. - fn read(&self, bytes: &mut [u8], len: uint) -> uint; -} - -pub trait ReaderUtil { - - /// Read len bytes into a new vec. - fn read_bytes(len: uint); -} - -impl<T:Reader> ReaderUtil for T { - - fn read_bytes(len: uint) { - let mut count = self.read(&mut [0], len); - } - -} - -struct S { - x: int, - y: int -} - -impl Reader for S { - fn read(&self, bytes: &mut [u8], len: uint) -> uint { - 0 - } -} - -pub fn main() { - let x = S { x: 1, y: 2 }; - let x = @x as @Reader; - x.read_bytes(0); -} diff --git a/src/test/run-pass/explicit-self-objects-ext-4.rs b/src/test/run-pass/explicit-self-objects-ext-4.rs deleted file mode 100644 index 3945be77904..00000000000 --- a/src/test/run-pass/explicit-self-objects-ext-4.rs +++ /dev/null @@ -1,39 +0,0 @@ -pub trait Reader { - // FIXME (#2004): Seekable really should be orthogonal. - - /// Read up to len bytes (or EOF) and put them into bytes (which - /// must be at least len bytes long). Return number of bytes read. - // FIXME (#2982): This should probably return an error. - fn read(bytes: &mut [u8], len: uint) -> uint; -} - -pub trait ReaderUtil { - - /// Read len bytes into a new vec. - fn read_bytes(len: uint); -} - -impl<T:Reader> ReaderUtil for T { - - fn read_bytes(len: uint) { - let mut count = self.read(&mut [0], len); - } - -} - -struct S { - x: int, - y: int -} - -impl Reader for S { - fn read(bytes: &mut [u8], len: uint) -> uint { - 0 - } -} - -pub fn main() { - let x = S { x: 1, y: 2 }; - let x = @x as @Reader; - x.read_bytes(0); -} diff --git a/src/test/run-pass/issue-2611.rs b/src/test/run-pass/issue-2611.rs index 7b3247fafc7..83cedc0fe50 100644 --- a/src/test/run-pass/issue-2611.rs +++ b/src/test/run-pass/issue-2611.rs @@ -11,12 +11,12 @@ use core::iter::BaseIter; trait FlatMapToVec<A> { - fn flat_map_to_vec<B, IB:BaseIter<B>>(op: fn(&A) -> IB) -> ~[B]; + fn flat_map_to_vec<B, IB:BaseIter<B>>(&self, op: fn(&A) -> IB) -> ~[B]; } -impl<A:Copy> FlatMapToVec<A> for BaseIter<A> { - fn flat_map_to_vec<B, IB:BaseIter<B>>(op: fn(&A) -> IB) -> ~[B] { - iter::flat_map_to_vec(&self, op) +impl<A:Copy> FlatMapToVec<A> for ~[A] { + fn flat_map_to_vec<B, IB:BaseIter<B>>(&self, op: fn(&A) -> IB) -> ~[B] { + iter::flat_map_to_vec(self, op) } } diff --git a/src/test/run-pass/issue-3305.rs b/src/test/run-pass/issue-3305.rs deleted file mode 100644 index bfde19993e9..00000000000 --- a/src/test/run-pass/issue-3305.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -trait double { - fn double() -> uint; -} - -impl double for uint { - fn double() -> uint { self * 2u } -} - -fn is_equal<D:double>(x: @D, exp: uint) { - assert x.double() == exp; -} - -pub fn main() { - let x = @(@3u as @double); - is_equal(x, 6); -} |
