]> git.lizzy.rs Git - rust.git/commitdiff
changes to tests
authorNick Cameron <ncameron@mozilla.com>
Wed, 1 Oct 2014 06:31:21 +0000 (19:31 +1300)
committerNick Cameron <ncameron@mozilla.com>
Thu, 30 Oct 2014 02:51:56 +0000 (15:51 +1300)
src/librustc/middle/typeck/check/vtable.rs
src/libstd/io/extensions.rs
src/libstd/io/util.rs
src/test/compile-fail/selftype-traittype.rs [deleted file]
src/test/compile-fail/trait-objects.rs [new file with mode: 0644]
src/test/compile-fail/trait-test-2.rs
src/test/run-pass/by-value-self-objects.rs [deleted file]
src/test/run-pass/issue-11267.rs
src/test/run-pass/issue-15763.rs
src/test/run-pass/trait-cast-generic.rs [deleted file]
src/test/run-pass/trait-default-method-xc.rs

index 4829083f021bf4e04ac3bc4a318db1d5af3e0382..115b224241b209febbfbad005ea4b335bebafe5f 100644 (file)
@@ -196,8 +196,8 @@ fn check_object_safety_of_method(tcx: &ty::ctxt, method: &ty::Method) -> Vec<Str
         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
index a595921fcf72d549a347d9918a2ede003010f6e0..59da797b12633c284d8f78b255791a77bfe9b6cf 100644 (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 @@ fn read(&mut self, buf: &mut [u8]) -> io::IoResult<uint> {
             }
         }
     }
+    impl BytesReader for InitialZeroByteReader {}
 
     struct EofReader;
 
@@ -197,6 +198,7 @@ fn read(&mut self, _: &mut [u8]) -> io::IoResult<uint> {
             Err(io::standard_error(io::EndOfFile))
         }
     }
+    impl BytesReader for EofReader {}
 
     struct ErroringReader;
 
@@ -205,6 +207,7 @@ fn read(&mut self, _: &mut [u8]) -> io::IoResult<uint> {
             Err(io::standard_error(io::InvalidInput))
         }
     }
+    impl BytesReader for ErroringReader {}
 
     struct PartialReader {
         count: int,
index 820ae931f320484a3ef7fa8caf5b60c4618d67fd..5694565b4ea6a98e7a6ab5be9bb0226bbf6b09d6 100644 (file)
@@ -265,7 +265,7 @@ fn read(&mut self, buf: &mut [u8]) -> io::IoResult<uint> {
 
 #[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 (file)
index 44ee500..0000000
+++ /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 <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() {}
diff --git a/src/test/compile-fail/trait-objects.rs b/src/test/compile-fail/trait-objects.rs
new file mode 100644 (file)
index 0000000..88b907a
--- /dev/null
@@ -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
+}
index 3dce0178597cfdda50f123c6a65c6630dbe6a8b0..a24f7710d7b61c88c740c9565cbb7e530dea96b1 100644 (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
 }
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 (file)
index 3a58836..0000000
+++ /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 <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();
-}
-
index 53659a72132ef7b6a0726ee18eaefae158f81cb7..f08805fe49c2c9c7ae74e3e3db39f7de49cccb68 100644 (file)
 
 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())
 }
 
index 6e3599bda149acf5c9621061bc05c960842424bd..0c09e456930c2d83f3d2b6debdfd4f953a6c1dc9 100644 (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);
     }
 }
diff --git a/src/test/run-pass/trait-cast-generic.rs b/src/test/run-pass/trait-cast-generic.rs
deleted file mode 100644 (file)
index 8f0ec5e..0000000
+++ /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 <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;
-}
index f88522facdfdfeb74bae434982fc9a0fdfd0e776..c4880e97c458bef96152d15ddd9df87fdd8b2363 100644 (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));