Make object types not implement associated trait. Fixes #5087.

This commit is contained in:
Niko Matsakis 2013-03-05 17:49:50 -05:00
parent 6267339d68
commit 6d764cc361
21 changed files with 65 additions and 339 deletions

View file

@ -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() {}

View file

@ -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() {

View file

@ -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
}

View file

@ -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() {}

View file

@ -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);

View file

@ -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(); }
}

View file

@ -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);

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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)
}
}

View file

@ -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);
}