changes to tests

This commit is contained in:
Nick Cameron 2014-10-01 19:31:21 +13:00
parent 1d500cfd74
commit c48a1ab158
11 changed files with 60 additions and 141 deletions

View File

@ -196,8 +196,8 @@ pub fn check_object_safety(tcx: &ty::ctxt, object_trait: &ty::TyTrait, span: Spa
let check_for_self_ty = |ty| {
if ty::type_has_self(ty) {
Some(format!(
"cannot call a method (`{}`) whose type (`{}`) contains \
a self-type through a trait object",
"cannot call a method (`{}`) whose type contains \
a self-type (`{}`) through a trait object",
method_name, ty_to_string(tcx, ty)))
} else {
None

View File

@ -172,7 +172,7 @@ pub fn u64_from_be_bytes(data: &[u8], start: uint, size: uint) -> u64 {
mod test {
use prelude::*;
use io;
use io::{MemReader, MemWriter};
use io::{MemReader, MemWriter, BytesReader};
struct InitialZeroByteReader {
count: int,
@ -189,6 +189,7 @@ mod test {
}
}
}
impl BytesReader for InitialZeroByteReader {}
struct EofReader;
@ -197,6 +198,7 @@ mod test {
Err(io::standard_error(io::EndOfFile))
}
}
impl BytesReader for EofReader {}
struct ErroringReader;
@ -205,6 +207,7 @@ mod test {
Err(io::standard_error(io::InvalidInput))
}
}
impl BytesReader for ErroringReader {}
struct PartialReader {
count: int,

View File

@ -265,7 +265,7 @@ impl<T: Iterator<u8>> Reader for IterReader<T> {
#[cfg(test)]
mod test {
use io::{MemReader, MemWriter, BufReader};
use io::{MemReader, MemWriter, BufReader, AsRefReader};
use io;
use boxed::Box;
use super::*;

View File

@ -1,20 +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(&self, x: Self) -> Self;
}
fn do_add(x: Box<add+'static>, y: Box<add+'static>) -> Box<add+'static> {
x.plus(y) //~ ERROR E0038
}
fn main() {}

View File

@ -0,0 +1,43 @@
// Copyright 2014 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 {
fn foo(self);
}
trait Bar {
fn bar(&self, x: &Self);
}
trait Baz {
fn baz<T>(&self, x: &T);
}
impl Foo for int {
fn foo(self) {}
}
impl Bar for int {
fn bar(&self, _x: &int) {}
}
impl Baz for int {
fn baz<T>(&self, _x: &T) {}
}
fn main() {
let _: &Foo = &42i; //~ ERROR cannot convert to a trait object
let _: &Bar = &42i; //~ ERROR cannot convert to a trait object
let _: &Baz = &42i; //~ ERROR cannot convert to a trait object
let _ = &42i as &Foo; //~ ERROR cannot convert to a trait object
let _ = &42i as &Bar; //~ ERROR cannot convert to a trait object
let _ = &42i as &Baz; //~ ERROR cannot convert to a trait object
}

View File

@ -16,5 +16,5 @@ impl bar for uint { fn dup(&self) -> uint { *self } fn blah<X>(&self) {} }
fn main() {
10i.dup::<int>(); //~ ERROR does not take type parameters
10i.blah::<int, int>(); //~ ERROR incorrect number of type parameters
(box 10i as Box<bar>).dup(); //~ ERROR contains a self-type
(box 10i as Box<bar>).dup(); //~ ERROR cannot convert to a trait object
}

View File

@ -1,77 +0,0 @@
// Copyright 2014 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.
static mut destructor_count: uint = 0;
trait Foo {
fn foo(self, x: int);
}
struct S {
x: int,
y: int,
z: int,
s: String,
}
impl Foo for S {
fn foo(self, x: int) {
assert!(self.x == 2);
assert!(self.y == 3);
assert!(self.z == 4);
assert!(self.s.as_slice() == "hello");
assert!(x == 5);
}
}
impl Drop for S {
fn drop(&mut self) {
println!("bye 1!");
unsafe {
destructor_count += 1;
}
}
}
impl Foo for int {
fn foo(self, x: int) {
println!("{}", x * x);
}
}
fn f() {
let s = S {
x: 2,
y: 3,
z: 4,
s: "hello".to_string(),
};
let st = box s as Box<Foo>;
st.foo(5);
println!("bye 2!");
}
fn g() {
let s = 2i;
let st = box s as Box<Foo>;
st.foo(3);
println!("bye 3!");
}
fn main() {
f();
unsafe {
assert!(destructor_count == 1);
}
g();
}

View File

@ -12,11 +12,14 @@
struct Empty;
impl Iterator<int> for Empty {
trait T<U> {
fn next(&mut self) -> Option<U>;
}
impl T<int> for Empty {
fn next(&mut self) -> Option<int> { None }
}
fn do_something_with(a : &mut Iterator<int>) {
fn do_something_with(a : &mut T<int>) {
println!("{}", a.next())
}

View File

@ -60,16 +60,16 @@ fn dd() -> Result<int, int> {
}
trait A {
fn aaa(self) -> int {
fn aaa(&self) -> int {
3
}
fn bbb(self) -> int {
fn bbb(&self) -> int {
return 3;
}
fn ccc(self) -> Result<int, int> {
fn ccc(&self) -> Result<int, int> {
Ok(3)
}
fn ddd(self) -> Result<int, int> {
fn ddd(&self) -> Result<int, int> {
return Ok(3);
}
}

View File

@ -1,30 +0,0 @@
// Copyright 2014 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.
// Testing casting of a generic Struct to a Trait with a generic method.
// This is test for issue 10955.
#![allow(unused_variable)]
trait Foo {
fn f<A>(a: A) -> A {
a
}
}
struct Bar<T> {
x: T,
}
impl<T> Foo for Bar<T> { }
pub fn main() {
let a = Bar { x: 1u };
let b = &a as &Foo;
}

View File

@ -72,9 +72,6 @@ pub fn main() {
assert_eq!(g(0i, 3.14f64, 1i), (3.14f64, 1i));
assert_eq!(g(false, 3.14f64, 1i), (3.14, 1));
let obj = box 0i as Box<A>;
assert_eq!(obj.h(), 11);
// Trying out a real one
assert!(12i.test_neq(&10i));