提交 58f248d9 编写于 作者: P Patrick Walton

test: Fix tests. rs=tests

上级 aa4c19b6
......@@ -1181,8 +1181,8 @@ Traits are implemented for specific types through separate [implementations](#im
# type BoundingBox = int;
trait Shape {
fn draw(Surface);
fn bounding_box() -> BoundingBox;
fn draw(&self, Surface);
fn bounding_box(&self) -> BoundingBox;
}
~~~~
......@@ -1195,9 +1195,9 @@ These appear after the trait name, using the same syntax used in [generic functi
~~~~
trait Seq<T> {
fn len() -> uint;
fn elt_at(n: uint) -> T;
fn iter(&fn(T));
fn len(&self) -> uint;
fn elt_at(&self, n: uint) -> T;
fn iter(&self, &fn(T));
}
~~~~
......@@ -1209,7 +1209,7 @@ For example:
~~~~
# type Surface = int;
# trait Shape { fn draw(Surface); }
# trait Shape { fn draw(&self, Surface); }
fn draw_twice<T: Shape>(surface: Surface, sh: T) {
sh.draw(surface);
......@@ -1271,8 +1271,8 @@ methods of the supertrait may be called on values of subtrait-bound type paramet
Refering to the previous example of `trait Circle : Shape`:
~~~
# trait Shape { fn area() -> float; }
# trait Circle : Shape { fn radius() -> float; }
# trait Shape { fn area(&self) -> float; }
# trait Circle : Shape { fn radius(&self) -> float; }
fn radius_times_area<T: Circle>(c: T) -> float {
// `c` is both a Circle and a Shape
c.radius() * c.area()
......@@ -1282,10 +1282,10 @@ fn radius_times_area<T: Circle>(c: T) -> float {
Likewise, supertrait methods may also be called on trait objects.
~~~ {.xfail-test}
# trait Shape { fn area() -> float; }
# trait Circle : Shape { fn radius() -> float; }
# impl Shape for int { fn area() -> float { 0.0 } }
# impl Circle for int { fn radius() -> float { 0.0 } }
# trait Shape { fn area(&self) -> float; }
# trait Circle : Shape { fn radius(&self) -> float; }
# impl Shape for int { fn area(&self) -> float { 0.0 } }
# impl Circle for int { fn radius(&self) -> float { 0.0 } }
# let mycircle = 0;
let mycircle: Circle = @mycircle as @Circle;
......@@ -1302,7 +1302,7 @@ Implementations are defined with the keyword `impl`.
# struct Point {x: float, y: float};
# type Surface = int;
# struct BoundingBox {x: float, y: float, width: float, height: float};
# trait Shape { fn draw(Surface); fn bounding_box() -> BoundingBox; }
# trait Shape { fn draw(&self, Surface); fn bounding_box(&self) -> BoundingBox; }
# fn do_draw_circle(s: Surface, c: Circle) { }
struct Circle {
......@@ -1311,8 +1311,8 @@ struct Circle {
}
impl Shape for Circle {
fn draw(s: Surface) { do_draw_circle(s, self); }
fn bounding_box() -> BoundingBox {
fn draw(&self, s: Surface) { do_draw_circle(s, *self); }
fn bounding_box(&self) -> BoundingBox {
let r = self.radius;
BoundingBox{x: self.center.x - r, y: self.center.y - r,
width: 2.0 * r, height: 2.0 * r}
......@@ -2678,11 +2678,11 @@ An example of an object type:
~~~~~~~~
trait Printable {
fn to_str() -> ~str;
fn to_str(&self) -> ~str;
}
impl Printable for int {
fn to_str() -> ~str { int::to_str(self) }
fn to_str(&self) -> ~str { int::to_str(*self) }
}
fn print(a: @Printable) {
......@@ -2721,11 +2721,11 @@ example, in:
~~~~~~~~
trait Printable {
fn make_string() -> ~str;
fn make_string(&self) -> ~str;
}
impl Printable for ~str {
fn make_string() -> ~str { copy self }
fn make_string(&self) -> ~str { copy *self }
}
~~~~~~~~
......
......@@ -10,7 +10,7 @@
use libc::{c_void};
#[cfg(unix)]
use libc::{c_uint, c_int};
use libc::{c_uint, c_ulong, c_int};
#[cfg(unix)]
use ptr::null;
#[cfg(windows)]
......@@ -34,7 +34,12 @@ pub unsafe fn get(key: Key) -> *mut c_void {
unsafe { pthread_getspecific(key) }
}
#[cfg(unix)]
#[cfg(target_os="macos")]
#[allow(non_camel_case_types)] // foreign type
type pthread_key_t = c_ulong;
#[cfg(target_os="linux")]
#[cfg(target_os="freebsd")]
#[allow(non_camel_case_types)] // foreign type
type pthread_key_t = c_uint;
......
......@@ -312,7 +312,7 @@ mod test {
@~"fn foo (x : int) { x; }",
~[],
new_parse_sess(None));
check_equal(to_json_str(@tts as Encodable::<std::json::Encoder>),
check_equal(to_json_str(@tts as @Encodable<std::json::Encoder>),
~"[[\"tt_tok\",[,[\"IDENT\",[\"fn\",false]]]],\
[\"tt_tok\",[,[\"IDENT\",[\"foo\",false]]]],\
[\"tt_delim\",[[[\"tt_tok\",[,[\"LPAREN\",[]]]],\
......
......@@ -22,7 +22,6 @@
#[allow(vecs_implicitly_copyable)];
#[allow(non_camel_case_types)];
#[allow(deprecated_mode)];
#[deny(deprecated_self)];
#[no_core];
......
......@@ -11,4 +11,4 @@
trait me {
fn me(&self) -> uint;
}
impl me for uint { fn me(&self) -> uint { self } }
impl me for uint { fn me(&self) -> uint { *self } }
......@@ -13,8 +13,8 @@
extern mod ambig_impl_2_lib;
use ambig_impl_2_lib::me;
trait me {
fn me() -> uint;
fn me(&self) -> uint;
}
impl me for uint { fn me() -> uint { self } } //~ NOTE is `__extensions__::me`
impl me for uint { fn me(&self) -> uint { *self } } //~ NOTE is `__extensions__::me`
fn main() { 1u.me(); } //~ ERROR multiple applicable methods in scope
//~^ NOTE is `ambig_impl_2_lib::__extensions__::me`
......@@ -8,8 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait A { fn foo(); }
trait B { fn foo(); }
trait A { fn foo(&self); }
trait B { fn foo(&self); }
fn foo<T:A + B>(t: T) {
t.foo(); //~ ERROR multiple applicable methods in scope
......
......@@ -10,8 +10,8 @@
struct X(Either<(uint,uint),extern fn()>);
pub impl &'self X {
fn with(self, blk: &fn(x: &Either<(uint,uint),extern fn()>)) {
pub impl X {
fn with(&self, blk: &fn(x: &Either<(uint,uint),extern fn()>)) {
blk(&**self)
}
}
......
......@@ -49,7 +49,7 @@ fn meow(&self) {
}
}
fn cat(&self, in_x : uint, in_y : int, in_name: ~str) -> cat {
fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
cat {
meows: in_x,
how_hungry: in_y,
......
......@@ -17,13 +17,13 @@ trait to_opt {
impl to_opt for uint {
fn to_option(&self) -> Option<uint> {
Some(self)
Some(*self)
}
}
impl<T:Copy> to_opt for Option<T> {
fn to_option(&self) -> Option<Option<T>> {
Some(self)
Some(*self)
}
}
......
......@@ -13,11 +13,11 @@ struct parser {
}
trait parse {
fn parse() -> ~[int];
fn parse(&self) -> ~[int];
}
impl parse for parser {
fn parse() -> ~[int] {
fn parse(&self) -> ~[int] {
self.tokens //~ ERROR moving out of immutable field
}
}
......
......@@ -21,7 +21,7 @@ struct SipState {
v1: u64,
}
fn mk_result(&self, st : SipState) -> u64 {
fn mk_result(st : SipState) -> u64 {
let v0 = st.v0,
v1 = st.v1;
......
......@@ -11,12 +11,12 @@
trait repeat<A> { fn get(&self) -> A; }
impl<A:Copy> repeat<A> for @A {
fn get(&self) -> A { *self }
fn get(&self) -> A { **self }
}
fn repeater<A:Copy>(v: @A) -> @repeat<A> {
// Note: owned kind is not necessary as A appears in the trait type
@v as @repeat::<A> // No
@v as @repeat<A> // No
}
fn main() {
......
// xfail-test
// xfail'd because to_foo() doesn't work.
// 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.
......@@ -15,7 +18,7 @@ trait foo {
fn foo(&self, i: &'self int) -> int;
}
impl<T:Copy> foo<'self> for T {
impl<T:Copy> foo for T {
fn foo(&self, i: &'self int) -> int {*i}
}
......
......@@ -15,7 +15,7 @@
fn main() {
let x: @Map<~str, ~str> = @LinearMap::new::<~str, ~str>() as
@(Map::<~str, ~str>);
@Map<~str, ~str>;
let y: @Map<uint, ~str> = @x;
//~^ ERROR mismatched types: expected `@core::container::Map<uint,~str>`
}
......@@ -24,7 +24,7 @@ trait modify_in_box_rec {
impl modify_in_box_rec for int {
pure fn modify_in_box_rec(&self, sum: @mut S) {
sum.f = self; //~ ERROR assigning to mutable field prohibited in pure context
sum.f = *self; //~ ERROR assigning to mutable field prohibited in pure context
}
}
......
......@@ -13,19 +13,12 @@
// checked.
struct an_enum(&'self int);
trait a_trait {
fn foo(&self) -> &'self int;
}
struct a_class { x:&'self int }
fn a_fn1(e: an_enum<'a>) -> an_enum<'b> {
return e; //~ ERROR mismatched types: expected `an_enum/&b` but found `an_enum/&a`
}
fn a_fn2(e: @a_trait<'a>) -> @a_trait<'b> {
return e; //~ ERROR mismatched types: expected `@a_trait/&b` but found `@a_trait/&a`
}
fn a_fn3(e: a_class<'a>) -> a_class<'b> {
return e; //~ ERROR mismatched types: expected `a_class/&b` but found `a_class/&a`
}
......
......@@ -18,17 +18,17 @@ struct c<'self> {
f: @b<'self>
}
trait set_f<'self> {
trait set_f {
fn set_f_ok(&self, b: @b<'self>);
fn set_f_bad(&self, b: @b);
}
impl<'self> set_f<'self> for c<'self> {
impl<'self> set_f for c<'self> {
fn set_f_ok(&self, b: @b<'self>) {
self.f = b;
}
fn set_f_bad(b: @b) {
fn set_f_bad(&self, b: @b) {
self.f = b; //~ ERROR mismatched types: expected `@@&self/int` but found `@@&int`
}
}
......
// xfail-test
// xfail'd due to problems with by value self.
// 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.
......@@ -12,9 +15,9 @@
// refers to self.
trait foo<'self> {
fn self_int(&self) -> &'self int;
fn self_int(self) -> &'self int;
fn any_int(&self) -> &int;
fn any_int(self) -> &int;
}
struct with_foo<'self> {
......
......@@ -10,22 +10,22 @@
struct ctxt { v: uint }
trait get_ctxt<'self> {
trait get_ctxt {
fn get_ctxt(&self) -> &'self ctxt;
}
struct has_ctxt<'self> { c: &'self ctxt }
impl<'self> get_ctxt<'self> for has_ctxt<'self> {
impl<'self> get_ctxt for has_ctxt<'self> {
fn get_ctxt(&self) -> &self/ctxt { self.c }
}
fn make_gc() -> @get_ctxt {
let ctxt = ctxt { v: 22u };
let hc = has_ctxt { c: &ctxt }; //~ ERROR illegal borrow
let hc = has_ctxt { c: &ctxt };
return @hc as @get_ctxt;
}
fn main() {
make_gc().get_ctxt().v;
make_gc().get_ctxt().v; //~ ERROR illegal borrow
}
// xfail-test
// xfail'd due to problems with by-value self.
// 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.
......@@ -9,7 +12,7 @@
// except according to those terms.
trait get_ctxt {
fn get_ctxt(&self) -> &self/uint;
fn get_ctxt(self) -> &self/uint;
}
fn make_gc1(gc: @get_ctxt/&a) -> @get_ctxt/&b {
......@@ -20,8 +23,8 @@ struct Foo {
r: &'self uint
}
impl get_ctxt/&self for Foo/&self {
fn get_ctxt(&self) -> &self/uint { self.r }
impl get_ctxt for Foo<'self> {
fn get_ctxt(&self) -> &'self uint { self.r }
}
fn make_gc2(foo: Foo/&a) -> @get_ctxt/&b {
......
......@@ -34,7 +34,7 @@ fn set_box_impl<T>(b: box_impl<@const T>, v: @const T) {
fn main() {
let b = box_impl::<@int>(box::<@int> {f: @3});
set_box_trait(@b as @box_trait::<@int>, @mut 5);
set_box_trait(@b as @box_trait<@int>, @mut 5);
//~^ ERROR values differ in mutability
set_box_impl(b, @mut 5);
//~^ ERROR values differ in mutability
......
......@@ -14,7 +14,7 @@ trait foo {
impl foo for int {
fn bar(&self) -> int {
//~^ ERROR method `bar` has 0 parameters but the trait has 1
self
*self
}
}
......
......@@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait bar { fn dup(&self) -> Self; fn blah<X>(); }
impl bar for int { fn dup(&self) -> int { self } fn blah<X>() {} }
impl bar for uint { fn dup(&self) -> uint { self } fn blah<X>() {} }
trait bar { fn dup(&self) -> Self; fn blah<X>(&self); }
impl bar for int { fn dup(&self) -> int { *self } fn blah<X>(&self) {} }
impl bar for uint { fn dup(&self) -> uint { *self } fn blah<X>(&self) {} }
fn main() {
10i.dup::<int>(); //~ ERROR does not take type parameters
......
......@@ -18,7 +18,7 @@ trait TraitB {
impl TraitB for int {
fn gimme_an_a<A:TraitA>(&self, a: A) -> int {
a.method_a() + self
a.method_a() + *self
}
}
......
// xfail-test
// xfail'd because of a problem with by-value self.
// 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.
......
......@@ -25,7 +25,7 @@ pub impl cat {
fn get_name(&self) -> ~str { copy self.name }
}
pub fn cat(&self, in_name: ~str) -> cat {
pub fn cat(in_name: ~str) -> cat {
cat {
name: in_name,
meows: 0u
......
......@@ -13,7 +13,7 @@ trait foo {
}
impl<T> foo for ~[const T] {
fn foo(&self) -> uint { vec::len(self) }
fn foo(&self) -> uint { vec::len(*self) }
}
pub fn main() {
......
......@@ -13,7 +13,7 @@ trait Send {
}
fn f<T:Send>(t: T) {
t.f(&self);
t.f();
}
pub fn main() {
......
......@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait c lam<A:Copy> {
trait clam<A:Copy> {
fn chowder(&self, y: A);
}
struct foo<A> {
......@@ -33,6 +33,6 @@ fn f<A:Copy>(x: @clam<A>, a: A) {
pub fn main() {
let c = foo(42);
let d: @clam<int> = @c as @clam::<int>;
let d: @clam<int> = @c as @clam<int>;
f(d, c.x);
}
......@@ -11,12 +11,12 @@
trait repeat<A> { fn get(&self) -> A; }
impl<A:Copy> repeat<A> for @A {
fn get(&self) -> A { *self }
fn get(&self) -> A { **self }
}
fn repeater<A:Copy>(v: @A) -> @repeat<A> {
// Note: owned kind is not necessary as A appears in the trait type
@v as @repeat::<A> // No
@v as @repeat<A> // No
}
pub fn main() {
......
......@@ -28,9 +28,9 @@ trait option_monad<A> {
impl<A> option_monad<A> for Option<A> {
fn bind<B>(&self, f: &fn(&A) -> Option<B>) -> Option<B> {
match self {
Some(ref a) => { f(a) }
None => { None }
match *self {
Some(ref a) => { f(a) }
None => { None }
}
}
}
......
// xfail-test
// xfail'd due to segfaults with by-value self.
// 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.
......@@ -15,7 +18,7 @@ trait get {
// Note: impl on a slice
impl get for &'self int {
fn get(self) -> int {
return *self;
return **self;
}
}
......
......@@ -487,7 +487,7 @@ fn get<T>(&self, f: &fn(T)) {
fn visit_inner(&self, inner: *TyDesc) -> bool {
unsafe {
let u = my_visitor(*self);
let u = my_visitor(**self);
let v = ptr_visit_adaptor::<my_visitor>(Inner {inner: u});
visit_tydesc(inner, @v as @TyVisitor);
true
......
......@@ -16,7 +16,7 @@ trait get_chowder<'self> {
fn get_chowder(&self) -> &'self int;
}
impl<'self> get_chowder<'self> for Clam<'self> {
impl<'self> get_chowder for Clam<'self> {
fn get_chowder(&self) -> &'self int { return self.chowder; }
}
......
......@@ -16,7 +16,7 @@ trait get_ctxt {
struct HasCtxt { c: &'self Ctxt }
impl get_ctxt<'self> for HasCtxt<'self> {
impl get_ctxt for HasCtxt<'self> {
fn get_ctxt(&self) -> &self/Ctxt {
self.c
}
......
......@@ -16,7 +16,7 @@ pub trait plus {
mod a {
use plus;
impl plus for uint { fn plus(&self) -> int { self as int + 20 } }
impl plus for uint { fn plus(&self) -> int { *self as int + 20 } }
}
mod b {
......@@ -25,15 +25,15 @@ impl plus for ~str { fn plus(&self) -> int { 200 } }
}
trait uint_utils {
fn str(self) -> ~str;
fn multi(self, f: &fn(uint));
fn str(&self) -> ~str;
fn multi(&self, f: &fn(uint));
}
impl uint_utils for uint {
fn str(self) -> ~str { uint::to_str(self) }
fn multi(self, f: &fn(uint)) {
fn str(&self) -> ~str { uint::to_str(*self) }
fn multi(&self, f: &fn(uint)) {
let mut c = 0u;
while c < self { f(c); c += 1u; }
while c < *self { f(c); c += 1u; }
}
}
......@@ -44,7 +44,7 @@ trait vec_utils<T> {
}
impl<T> vec_utils<T> for ~[T] {
fn length_(&self) -> uint { vec::len(self) }
fn length_(&self) -> uint { vec::len(*self) }
fn iter_(&self, f: &fn(&T)) { for self.each |x| { f(x); } }
fn map_<U:Copy>(&self, f: &fn(&T) -> U) -> ~[U] {
let mut r = ~[];
......
......@@ -14,10 +14,10 @@ trait to_str {
fn to_str(&self) -> ~str;
}
impl to_str for int {
fn to_str(&self) -> ~str { int::to_str(self) }
fn to_str(&self) -> ~str { int::to_str(*self) }
}
impl to_str for ~str {
fn to_str(&self) -> ~str { copy self }
fn to_str(&self) -> ~str { copy *self }
}
impl to_str for () {
fn to_str(&self) -> ~str { ~"()" }
......
......@@ -17,9 +17,9 @@
struct A { x: int }
impl Foo for A { fn f() -> int { 10 } }
impl Bar for A { fn g() -> int { 20 } }
impl Baz for A { fn h() -> int { 30 } }
impl Foo for A { fn f(&self) -> int { 10 } }
impl Bar for A { fn g(&self) -> int { 20 } }
impl Baz for A { fn h(&self) -> int { 30 } }
fn f<T:Quux>(a: &T) {
fail_unless!(a.f() == 10);
......
......@@ -16,11 +16,11 @@
use aux::Foo;
trait Bar : Foo {
fn g() -> int;
fn g(&self) -> int;
}
impl Bar for aux::A {
fn g() -> int { self.f() }
fn g(&self) -> int { self.f() }
}
pub fn main() {
......
......@@ -21,12 +21,12 @@ trait to_str {
}
impl to_str for int {
fn to_str(&self) -> ~str { int::to_str(self) }
fn to_str(&self) -> ~str { int::to_str(*self) }
}
impl<T:to_str> to_str for ~[T] {
fn to_str(&self) -> ~str {
~"[" + str::connect(vec::map(self, |e| e.to_str() ), ~", ") + ~"]"
~"[" + str::connect(vec::map(*self, |e| e.to_str() ), ~", ") + ~"]"
}
}
......
......@@ -18,7 +18,7 @@ enum Color { cyan, magenta, yellow, black }
impl Equal for Color {
fn isEq(&self, a: Color) -> bool {
match (self, a) {
match (*self, a) {
(cyan, cyan) => { true }
(magenta, magenta) => { true }
(yellow, yellow) => { true }
......@@ -35,7 +35,7 @@ enum ColorTree {
impl Equal for ColorTree {
fn isEq(&self, a: ColorTree) -> bool {
match (self, a) {
match (*self, a) {
(leaf(x), leaf(y)) => { x.isEq(y) }
(branch(l1, r1), branch(l2, r2)) => {
(*l1).isEq(*l2) && (*r1).isEq(*r2)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册