From c48a1ab158110a35ee22a9fe06dc08d31aa6c56a Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Wed, 1 Oct 2014 19:31:21 +1300 Subject: [PATCH] changes to tests --- src/librustc/middle/typeck/check/vtable.rs | 4 +- src/libstd/io/extensions.rs | 5 +- src/libstd/io/util.rs | 2 +- src/test/compile-fail/selftype-traittype.rs | 20 ----- src/test/compile-fail/trait-objects.rs | 43 +++++++++++ src/test/compile-fail/trait-test-2.rs | 2 +- src/test/run-pass/by-value-self-objects.rs | 77 -------------------- src/test/run-pass/issue-11267.rs | 7 +- src/test/run-pass/issue-15763.rs | 8 +- src/test/run-pass/trait-cast-generic.rs | 30 -------- src/test/run-pass/trait-default-method-xc.rs | 3 - 11 files changed, 60 insertions(+), 141 deletions(-) delete mode 100644 src/test/compile-fail/selftype-traittype.rs create mode 100644 src/test/compile-fail/trait-objects.rs delete mode 100644 src/test/run-pass/by-value-self-objects.rs delete mode 100644 src/test/run-pass/trait-cast-generic.rs diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index 4829083f021..115b224241b 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -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 diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs index a595921fcf7..59da797b126 100644 --- a/src/libstd/io/extensions.rs +++ b/src/libstd/io/extensions.rs @@ -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, diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 820ae931f32..5694565b4ea 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -265,7 +265,7 @@ impl> Reader for IterReader { #[cfg(test)] mod test { - use io::{MemReader, MemWriter, BufReader}; + use io::{MemReader, MemWriter, BufReader, AsRefReader}; use io; use boxed::Box; use super::*; diff --git a/src/test/compile-fail/selftype-traittype.rs b/src/test/compile-fail/selftype-traittype.rs deleted file mode 100644 index 44ee5002dce..00000000000 --- a/src/test/compile-fail/selftype-traittype.rs +++ /dev/null @@ -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 or the MIT license -// , 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, y: Box) -> Box { - x.plus(y) //~ ERROR E0038 -} - -fn main() {} diff --git a/src/test/compile-fail/trait-objects.rs b/src/test/compile-fail/trait-objects.rs new file mode 100644 index 00000000000..88b907a5cb9 --- /dev/null +++ b/src/test/compile-fail/trait-objects.rs @@ -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 or the MIT license +// , 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(&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(&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 +} diff --git a/src/test/compile-fail/trait-test-2.rs b/src/test/compile-fail/trait-test-2.rs index 3dce0178597..a24f7710d7b 100644 --- a/src/test/compile-fail/trait-test-2.rs +++ b/src/test/compile-fail/trait-test-2.rs @@ -16,5 +16,5 @@ impl bar for uint { fn dup(&self) -> uint { *self } fn blah(&self) {} } fn main() { 10i.dup::(); //~ ERROR does not take type parameters 10i.blah::(); //~ ERROR incorrect number of type parameters - (box 10i as Box).dup(); //~ ERROR contains a self-type + (box 10i as Box).dup(); //~ ERROR cannot convert to a trait object } diff --git a/src/test/run-pass/by-value-self-objects.rs b/src/test/run-pass/by-value-self-objects.rs deleted file mode 100644 index 3a588367a97..00000000000 --- a/src/test/run-pass/by-value-self-objects.rs +++ /dev/null @@ -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 or the MIT license -// , 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; - st.foo(5); - println!("bye 2!"); -} - -fn g() { - let s = 2i; - let st = box s as Box; - st.foo(3); - println!("bye 3!"); -} - -fn main() { - f(); - - unsafe { - assert!(destructor_count == 1); - } - - g(); -} - diff --git a/src/test/run-pass/issue-11267.rs b/src/test/run-pass/issue-11267.rs index 53659a72132..f08805fe49c 100644 --- a/src/test/run-pass/issue-11267.rs +++ b/src/test/run-pass/issue-11267.rs @@ -12,11 +12,14 @@ struct Empty; -impl Iterator for Empty { +trait T { + fn next(&mut self) -> Option; +} +impl T for Empty { fn next(&mut self) -> Option { None } } -fn do_something_with(a : &mut Iterator) { +fn do_something_with(a : &mut T) { println!("{}", a.next()) } diff --git a/src/test/run-pass/issue-15763.rs b/src/test/run-pass/issue-15763.rs index 6e3599bda14..0c09e456930 100644 --- a/src/test/run-pass/issue-15763.rs +++ b/src/test/run-pass/issue-15763.rs @@ -60,16 +60,16 @@ fn dd() -> Result { } 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 { + fn ccc(&self) -> Result { Ok(3) } - fn ddd(self) -> Result { + fn ddd(&self) -> Result { return Ok(3); } } diff --git a/src/test/run-pass/trait-cast-generic.rs b/src/test/run-pass/trait-cast-generic.rs deleted file mode 100644 index 8f0ec5ec7a1..00000000000 --- a/src/test/run-pass/trait-cast-generic.rs +++ /dev/null @@ -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 or the MIT license -// , 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 - } -} - -struct Bar { - x: T, -} - -impl Foo for Bar { } - -pub fn main() { - let a = Bar { x: 1u }; - let b = &a as &Foo; -} diff --git a/src/test/run-pass/trait-default-method-xc.rs b/src/test/run-pass/trait-default-method-xc.rs index f88522facdf..c4880e97c45 100644 --- a/src/test/run-pass/trait-default-method-xc.rs +++ b/src/test/run-pass/trait-default-method-xc.rs @@ -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; - assert_eq!(obj.h(), 11); - // Trying out a real one assert!(12i.test_neq(&10i));