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
mod test {
use prelude::*;
use io;
- use io::{MemReader, MemWriter};
+ use io::{MemReader, MemWriter, BytesReader};
struct InitialZeroByteReader {
count: int,
}
}
}
+ impl BytesReader for InitialZeroByteReader {}
struct EofReader;
Err(io::standard_error(io::EndOfFile))
}
}
+ impl BytesReader for EofReader {}
struct ErroringReader;
Err(io::standard_error(io::InvalidInput))
}
}
+ impl BytesReader for ErroringReader {}
struct PartialReader {
count: int,
#[cfg(test)]
mod test {
- use io::{MemReader, MemWriter, BufReader};
+ use io::{MemReader, MemWriter, BufReader, AsRefReader};
use io;
use boxed::Box;
use super::*;
+++ /dev/null
-// 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() {}
--- /dev/null
+// 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
+}
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
}
+++ /dev/null
-// 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();
-}
-
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())
}
}
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);
}
}
+++ /dev/null
-// 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;
-}
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));