librustc: Remove implicit self from the language, except for old-style drop blocks.
This commit is contained in:
parent
a410652bc9
commit
8fa66e8e07
133 changed files with 339 additions and 395 deletions
|
|
@ -9,6 +9,6 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait me {
|
||||
fn me() -> uint;
|
||||
fn me(&self) -> uint;
|
||||
}
|
||||
impl me for uint { fn me() -> uint { self } }
|
||||
impl me for uint { fn me(&self) -> uint { self } }
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ pub mod kitties {
|
|||
}
|
||||
|
||||
pub impl cat {
|
||||
fn speak() {}
|
||||
fn speak(&self) {}
|
||||
}
|
||||
|
||||
pub fn cat(in_x : uint, in_y : int) -> cat {
|
||||
|
|
|
|||
|
|
@ -11,12 +11,12 @@
|
|||
#[link(name="cci_impl_lib", vers="0.0")];
|
||||
|
||||
trait uint_helpers {
|
||||
fn to(v: uint, f: &fn(uint));
|
||||
fn to(self, v: uint, f: &fn(uint));
|
||||
}
|
||||
|
||||
impl uint_helpers for uint {
|
||||
#[inline]
|
||||
fn to(v: uint, f: &fn(uint)) {
|
||||
fn to(self, v: uint, f: &fn(uint)) {
|
||||
let mut i = self;
|
||||
while i < v {
|
||||
f(i);
|
||||
|
|
|
|||
|
|
@ -16,11 +16,11 @@ pub mod name_pool {
|
|||
pub type name_pool = ();
|
||||
|
||||
pub trait add {
|
||||
fn add(s: ~str);
|
||||
fn add(&self, s: ~str);
|
||||
}
|
||||
|
||||
impl add for name_pool {
|
||||
fn add(s: ~str) {
|
||||
fn add(&self, s: ~str) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -31,11 +31,11 @@ pub mod rust {
|
|||
pub type rt = @();
|
||||
|
||||
pub trait cx {
|
||||
fn cx();
|
||||
fn cx(&self);
|
||||
}
|
||||
|
||||
impl cx for rt {
|
||||
fn cx() {
|
||||
fn cx(&self) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@
|
|||
type t1 = uint;
|
||||
|
||||
trait foo {
|
||||
fn foo();
|
||||
fn foo(&self);
|
||||
}
|
||||
|
||||
impl foo for ~str {
|
||||
fn foo() {}
|
||||
fn foo(&self) {}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,5 +56,5 @@ fn context_res() -> context_res {
|
|||
pub type context = arc_destruct<context_res>;
|
||||
|
||||
pub impl context {
|
||||
fn socket() { }
|
||||
fn socket(&self) { }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,13 +12,13 @@
|
|||
pub struct S(());
|
||||
|
||||
pub impl S {
|
||||
fn foo() { }
|
||||
fn foo(&self) { }
|
||||
}
|
||||
|
||||
pub trait T {
|
||||
fn bar();
|
||||
fn bar(&self);
|
||||
}
|
||||
|
||||
impl T for S {
|
||||
fn bar() { }
|
||||
fn bar(&self) { }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait x {
|
||||
fn use_x<T>();
|
||||
fn use_x<T>(&self);
|
||||
}
|
||||
struct y(());
|
||||
impl x for y {
|
||||
fn use_x<T>() {
|
||||
fn use_x<T>(&self) {
|
||||
struct foo { //~ ERROR quux
|
||||
i: ()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,14 +8,14 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
pub trait Foo { fn f() -> int; }
|
||||
pub trait Bar { fn g() -> int; }
|
||||
pub trait Baz { fn h() -> int; }
|
||||
pub trait Foo { fn f(&self) -> int; }
|
||||
pub trait Bar { fn g(&self) -> int; }
|
||||
pub trait Baz { fn h(&self) -> int; }
|
||||
|
||||
pub 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 } }
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
trait Foo { fn f() -> int; }
|
||||
trait Bar { fn g() -> int; }
|
||||
trait Baz { fn h() -> int; }
|
||||
trait Foo { fn f(&self) -> int; }
|
||||
trait Bar { fn g(&self) -> int; }
|
||||
trait Baz { fn h(&self) -> int; }
|
||||
|
||||
trait Quux: Foo + Bar + Baz { }
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
|
||||
pub trait Foo {
|
||||
fn f() -> int;
|
||||
fn f(&self) -> int;
|
||||
}
|
||||
|
||||
pub struct A {
|
||||
|
|
@ -18,5 +18,5 @@ pub struct A {
|
|||
}
|
||||
|
||||
impl Foo for A {
|
||||
fn f() -> int { 10 }
|
||||
fn f(&self) -> int { 10 }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,15 +9,15 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait foo {
|
||||
fn foo() -> int;
|
||||
fn foo(&self) -> int;
|
||||
}
|
||||
|
||||
impl foo for ~[uint] {
|
||||
fn foo() -> int {1} //~ NOTE candidate #1 is `__extensions__::foo`
|
||||
fn foo(&self) -> int {1} //~ NOTE candidate #1 is `__extensions__::foo`
|
||||
}
|
||||
|
||||
impl foo for ~[int] {
|
||||
fn foo() -> int {2} //~ NOTE candidate #2 is `__extensions__::foo`
|
||||
fn foo(&self) -> int {2} //~ NOTE candidate #2 is `__extensions__::foo`
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ struct cat {
|
|||
|
||||
pub impl cat {
|
||||
|
||||
fn speak() { self.meows += 1u; }
|
||||
fn speak(&self) { self.meows += 1u; }
|
||||
}
|
||||
|
||||
fn cat(in_x : uint, in_y : int) -> cat {
|
||||
|
|
|
|||
|
|
@ -15,11 +15,11 @@ struct Foo {
|
|||
}
|
||||
|
||||
trait Stuff {
|
||||
fn printme();
|
||||
fn printme(self);
|
||||
}
|
||||
|
||||
impl Stuff for &'self mut Foo {
|
||||
fn printme() {
|
||||
fn printme(self) {
|
||||
io::println(fmt!("%d", self.x));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@ fn foo<T>() {
|
|||
}
|
||||
|
||||
trait bar {
|
||||
fn bar<T:Copy>();
|
||||
fn bar<T:Copy>(&self);
|
||||
}
|
||||
|
||||
impl bar for uint {
|
||||
fn bar<T:Copy>() {
|
||||
fn bar<T:Copy>(&self) {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
struct X(Either<(uint,uint),extern fn()>);
|
||||
|
||||
pub impl &'self X {
|
||||
fn with(blk: &fn(x: &Either<(uint,uint),extern fn()>)) {
|
||||
fn with(self, blk: &fn(x: &Either<(uint,uint),extern fn()>)) {
|
||||
blk(&**self)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ impl ops::Add<int,int> for Point {
|
|||
}
|
||||
|
||||
pub impl Point {
|
||||
fn times(z: int) -> int {
|
||||
fn times(&self, z: int) -> int {
|
||||
self.x * self.y * z
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,18 +11,18 @@
|
|||
struct point { x: int, y: int }
|
||||
|
||||
trait methods {
|
||||
fn impurem();
|
||||
fn blockm(f: &fn());
|
||||
pure fn purem();
|
||||
fn impurem(&self);
|
||||
fn blockm(&self, f: &fn());
|
||||
pure fn purem(&self);
|
||||
}
|
||||
|
||||
impl methods for point {
|
||||
fn impurem() {
|
||||
fn impurem(&self) {
|
||||
}
|
||||
|
||||
fn blockm(f: &fn()) { f() }
|
||||
fn blockm(&self, f: &fn()) { f() }
|
||||
|
||||
pure fn purem() {
|
||||
pure fn purem(&self) {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait noisy {
|
||||
fn speak();
|
||||
fn speak(&self);
|
||||
}
|
||||
|
||||
struct cat {
|
||||
|
|
@ -21,7 +21,7 @@ struct cat {
|
|||
|
||||
pub impl cat {
|
||||
|
||||
fn eat() -> bool {
|
||||
fn eat(&self) -> bool {
|
||||
if self.how_hungry > 0 {
|
||||
error!("OM NOM NOM");
|
||||
self.how_hungry -= 2;
|
||||
|
|
@ -35,12 +35,12 @@ pub impl cat {
|
|||
}
|
||||
|
||||
impl noisy for cat {
|
||||
fn speak() { self.meow(); }
|
||||
fn speak(&self) { self.meow(); }
|
||||
|
||||
}
|
||||
|
||||
priv impl cat {
|
||||
fn meow() {
|
||||
fn meow(&self) {
|
||||
error!("Meow");
|
||||
self.meows += 1;
|
||||
if self.meows % 5 == 0 {
|
||||
|
|
@ -49,7 +49,7 @@ priv impl cat {
|
|||
}
|
||||
}
|
||||
|
||||
fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
|
||||
fn cat(&self, in_x : uint, in_y : int, in_name: ~str) -> cat {
|
||||
cat {
|
||||
meows: in_x,
|
||||
how_hungry: in_y,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
// error-pattern:missing method `eat`
|
||||
trait animal {
|
||||
fn eat();
|
||||
fn eat(&self);
|
||||
}
|
||||
|
||||
struct cat {
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ struct cat {
|
|||
}
|
||||
|
||||
priv impl cat {
|
||||
fn sleep() { loop{} }
|
||||
fn meow() {
|
||||
fn sleep(&self) { loop{} }
|
||||
fn meow(&self) {
|
||||
error!("Meow");
|
||||
meows += 1u; //~ ERROR unresolved name
|
||||
sleep(); //~ ERROR unresolved name
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ struct Foo {
|
|||
}
|
||||
|
||||
trait Bar : Drop {
|
||||
fn blah();
|
||||
fn blah(&self);
|
||||
}
|
||||
|
||||
impl Drop for Foo {
|
||||
|
|
@ -23,7 +23,7 @@ impl Drop for Foo {
|
|||
}
|
||||
|
||||
impl Bar for Foo {
|
||||
fn blah() {
|
||||
fn blah(&self) {
|
||||
self.finalize(); //~ ERROR explicit call to destructor
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,17 +12,17 @@
|
|||
// issue 2258
|
||||
|
||||
trait to_opt {
|
||||
fn to_option() -> Option<Self>;
|
||||
fn to_option(&self) -> Option<Self>;
|
||||
}
|
||||
|
||||
impl to_opt for uint {
|
||||
fn to_option() -> Option<uint> {
|
||||
fn to_option(&self) -> Option<uint> {
|
||||
Some(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy> to_opt for Option<T> {
|
||||
fn to_option() -> Option<Option<T>> {
|
||||
fn to_option(&self) -> Option<Option<T>> {
|
||||
Some(self)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait vec_monad<A> {
|
||||
fn bind<B>(f: &fn(A) -> ~[B]);
|
||||
fn bind<B>(&self, f: &fn(A) -> ~[B]);
|
||||
}
|
||||
|
||||
impl<A> vec_monad<A> for ~[A] {
|
||||
fn bind<B>(f: &fn(A) -> ~[B]) {
|
||||
fn bind<B>(&self, f: &fn(A) -> ~[B]) {
|
||||
let mut r = fail!();
|
||||
for self.each |elt| { r += f(*elt); }
|
||||
//~^ WARNING unreachable expression
|
||||
|
|
|
|||
|
|
@ -11,12 +11,12 @@
|
|||
enum chan { }
|
||||
|
||||
trait channel<T> {
|
||||
fn send(v: T);
|
||||
fn send(&self, v: T);
|
||||
}
|
||||
|
||||
// `chan` is not a trait, it's an enum
|
||||
impl chan for int { //~ ERROR can only implement trait types
|
||||
fn send(v: int) { fail!() }
|
||||
fn send(&self, v: int) { fail!() }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
// an impl against a trait
|
||||
|
||||
trait A {
|
||||
fn b<C:Copy,D>(x: C) -> C;
|
||||
fn b<C:Copy,D>(&self, x: C) -> C;
|
||||
}
|
||||
|
||||
struct E {
|
||||
|
|
@ -21,7 +21,7 @@ struct E {
|
|||
|
||||
impl A for E {
|
||||
// n.b. The error message is awful -- see #3404
|
||||
fn b<F:Copy,G>(_x: G) -> G { fail!() } //~ ERROR method `b` has an incompatible type
|
||||
fn b<F:Copy,G>(&self, _x: G) -> G { fail!() } //~ ERROR method `b` has an incompatible type
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ extern mod std;
|
|||
fn siphash<T>() {
|
||||
|
||||
trait t {
|
||||
fn g(x: T) -> T; //~ ERROR attempt to use a type argument out of scope
|
||||
fn g(&self, x: T) -> T; //~ ERROR attempt to use a type argument out of scope
|
||||
//~^ ERROR attempt to use a type argument out of scope
|
||||
//~^^ ERROR use of undeclared type name `T`
|
||||
//~^^^ ERROR use of undeclared type name `T`
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@
|
|||
extern mod std;
|
||||
|
||||
trait siphash {
|
||||
fn result() -> u64;
|
||||
fn reset();
|
||||
fn result(&self) -> u64;
|
||||
fn reset(&self);
|
||||
}
|
||||
|
||||
fn siphash(k0 : u64, k1 : u64) -> siphash {
|
||||
|
|
@ -21,7 +21,7 @@ fn siphash(k0 : u64, k1 : u64) -> siphash {
|
|||
v1: u64,
|
||||
}
|
||||
|
||||
fn mk_result(st : SipState) -> u64 {
|
||||
fn mk_result(&self, st : SipState) -> u64 {
|
||||
|
||||
let v0 = st.v0,
|
||||
v1 = st.v1;
|
||||
|
|
@ -29,13 +29,13 @@ fn siphash(k0 : u64, k1 : u64) -> siphash {
|
|||
}
|
||||
|
||||
impl siphash for SipState {
|
||||
fn reset() {
|
||||
fn reset(&self) {
|
||||
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture
|
||||
//~^ ERROR unresolved name: `k0`.
|
||||
self.v1 = k1 ^ 0x646f72616e646f6d; //~ ERROR attempted dynamic environment-capture
|
||||
//~^ ERROR unresolved name: `k1`.
|
||||
}
|
||||
fn result() -> u64 { return mk_result(self); }
|
||||
fn result(&self) -> u64 { return mk_result(self); }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
extern mod std;
|
||||
|
||||
trait SipHash {
|
||||
fn reset();
|
||||
fn reset(&self);
|
||||
}
|
||||
|
||||
fn siphash(k0 : u64) -> SipHash {
|
||||
|
|
@ -20,7 +20,7 @@ fn siphash(k0 : u64) -> SipHash {
|
|||
}
|
||||
|
||||
impl SipHash for SipState {
|
||||
fn reset() {
|
||||
fn reset(&self) {
|
||||
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture
|
||||
//~^ ERROR unresolved name: `k0`.
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@
|
|||
|
||||
struct P { child: Option<@mut P> }
|
||||
trait PTrait {
|
||||
fn getChildOption() -> Option<@P>;
|
||||
fn getChildOption(&self) -> Option<@P>;
|
||||
}
|
||||
|
||||
impl PTrait for P {
|
||||
fn getChildOption() -> Option<@P> {
|
||||
fn getChildOption(&self) -> Option<@P> {
|
||||
const childVal: @P = self.child.get(); //~ ERROR attempt to use a non-constant value in a constant
|
||||
fail!();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ mod my_mod {
|
|||
MyStruct {priv_field: 4}
|
||||
}
|
||||
pub impl MyStruct {
|
||||
priv fn happyfun() {}
|
||||
priv fn happyfun(&self) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
trait repeat<A> { fn get() -> A; }
|
||||
trait repeat<A> { fn get(&self) -> A; }
|
||||
|
||||
impl<A:Copy> repeat<A> for @A {
|
||||
fn get() -> A { *self }
|
||||
fn get(&self) -> A { *self }
|
||||
}
|
||||
|
||||
fn repeater<A:Copy>(v: @A) -> @repeat<A> {
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@
|
|||
// be parameterized by a region due to the &self/int constraint.
|
||||
|
||||
trait foo {
|
||||
fn foo(i: &'self int) -> int;
|
||||
fn foo(&self, i: &'self int) -> int;
|
||||
}
|
||||
|
||||
impl<T:Copy> foo<'self> for T {
|
||||
fn foo(i: &'self int) -> int {*i}
|
||||
fn foo(&self, i: &'self int) -> int {*i}
|
||||
}
|
||||
|
||||
fn to_foo<T:Copy>(t: T) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
trait foo { fn foo(); }
|
||||
trait foo { fn foo(&self); }
|
||||
|
||||
fn to_foo<T:Copy + foo>(t: T) -> @foo {
|
||||
@t as @foo //~ ERROR value may contain borrowed pointers; use `&static` bound
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
#[forbid(deprecated_self)]
|
||||
mod a {
|
||||
trait T {
|
||||
fn f(); //~ ERROR this method form is deprecated
|
||||
}
|
||||
|
||||
struct S {
|
||||
x: int
|
||||
}
|
||||
|
||||
impl T for S {
|
||||
fn f() { //~ ERROR this method form is deprecated
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -15,7 +15,7 @@ use core::hashmap::linear::LinearMap;
|
|||
|
||||
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>`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ struct cat {
|
|||
}
|
||||
|
||||
pub impl cat {
|
||||
fn eat() {
|
||||
fn eat(&self) {
|
||||
self.how_hungry -= 5;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ mod a {
|
|||
}
|
||||
|
||||
pub impl Foo {
|
||||
priv fn foo() {}
|
||||
priv fn foo(&self) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ mod kitties {
|
|||
}
|
||||
|
||||
pub impl cat {
|
||||
priv fn nap() { uint::range(1u, 10000u, |_i| false)}
|
||||
priv fn nap(&self) { uint::range(1u, 10000u, |_i| false)}
|
||||
}
|
||||
|
||||
pub fn cat(in_x : uint, in_y : int) -> cat {
|
||||
|
|
|
|||
|
|
@ -19,11 +19,11 @@ pure fn modify_in_box(sum: @mut S) {
|
|||
}
|
||||
|
||||
trait modify_in_box_rec {
|
||||
pure fn modify_in_box_rec(sum: @mut S);
|
||||
pure fn modify_in_box_rec(&self, sum: @mut S);
|
||||
}
|
||||
|
||||
impl modify_in_box_rec for int {
|
||||
pure fn modify_in_box_rec(sum: @mut S) {
|
||||
pure fn modify_in_box_rec(&self, sum: @mut S) {
|
||||
sum.f = self; //~ ERROR assigning to mutable field prohibited in pure context
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
struct an_enum(&'self int);
|
||||
trait a_trait {
|
||||
fn foo() -> &'self int;
|
||||
fn foo(&self) -> &'self int;
|
||||
}
|
||||
struct a_class { x:&'self int }
|
||||
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait deref {
|
||||
fn get() -> int;
|
||||
fn get(self) -> int;
|
||||
}
|
||||
|
||||
impl deref for &'self int {
|
||||
fn get() -> int {
|
||||
fn get(self) -> int {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,12 +19,12 @@ struct c<'self> {
|
|||
}
|
||||
|
||||
trait set_f<'self> {
|
||||
fn set_f_ok(b: @b<'self>);
|
||||
fn set_f_bad(b: @b);
|
||||
fn set_f_ok(&self, b: @b<'self>);
|
||||
fn set_f_bad(&self, b: @b);
|
||||
}
|
||||
|
||||
impl<'self> set_f<'self> for c<'self> {
|
||||
fn set_f_ok(b: @b<'self>) {
|
||||
fn set_f_ok(&self, b: @b<'self>) {
|
||||
self.f = b;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@
|
|||
// refers to self.
|
||||
|
||||
trait foo<'self> {
|
||||
fn self_int() -> &'self int;
|
||||
fn self_int(&self) -> &'self int;
|
||||
|
||||
fn any_int() -> ∫
|
||||
fn any_int(&self) -> ∫
|
||||
}
|
||||
|
||||
struct with_foo<'self> {
|
||||
|
|
@ -34,7 +34,7 @@ impl<'self> set_foo_foo for with_foo<'self> {
|
|||
// Bar is not region parameterized.
|
||||
|
||||
trait bar {
|
||||
fn any_int() -> ∫
|
||||
fn any_int(&self) -> ∫
|
||||
}
|
||||
|
||||
struct with_bar {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ struct ctxt { v: uint }
|
|||
|
||||
trait get_ctxt {
|
||||
// Here the `&` is bound in the method definition:
|
||||
fn get_ctxt() -> &ctxt;
|
||||
fn get_ctxt(&self) -> &ctxt;
|
||||
}
|
||||
|
||||
struct has_ctxt { c: &'self ctxt }
|
||||
|
|
@ -21,7 +21,7 @@ impl get_ctxt for has_ctxt<'self> {
|
|||
|
||||
// Here an error occurs because we used `&self` but
|
||||
// the definition used `&`:
|
||||
fn get_ctxt() -> &'self ctxt { //~ ERROR method `get_ctxt` has an incompatible type
|
||||
fn get_ctxt(&self) -> &'self ctxt { //~ ERROR method `get_ctxt` has an incompatible type
|
||||
self.c
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@
|
|||
struct ctxt { v: uint }
|
||||
|
||||
trait get_ctxt<'self> {
|
||||
fn get_ctxt() -> &'self ctxt;
|
||||
fn get_ctxt(&self) -> &'self ctxt;
|
||||
}
|
||||
|
||||
struct has_ctxt<'self> { c: &'self ctxt }
|
||||
|
||||
impl<'self> get_ctxt<'self> for has_ctxt<'self> {
|
||||
fn get_ctxt() -> &self/ctxt { self.c }
|
||||
fn get_ctxt(&self) -> &self/ctxt { self.c }
|
||||
}
|
||||
|
||||
fn make_gc() -> @get_ctxt {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait get_ctxt {
|
||||
fn get_ctxt() -> &self/uint;
|
||||
fn get_ctxt(&self) -> &self/uint;
|
||||
}
|
||||
|
||||
fn make_gc1(gc: @get_ctxt/&a) -> @get_ctxt/&b {
|
||||
|
|
@ -21,7 +21,7 @@ struct Foo {
|
|||
}
|
||||
|
||||
impl get_ctxt/&self for Foo/&self {
|
||||
fn get_ctxt() -> &self/uint { self.r }
|
||||
fn get_ctxt(&self) -> &self/uint { self.r }
|
||||
}
|
||||
|
||||
fn make_gc2(foo: Foo/&a) -> @get_ctxt/&b {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait add {
|
||||
fn plus(x: Self) -> Self;
|
||||
fn plus(&self, x: Self) -> Self;
|
||||
}
|
||||
|
||||
fn do_add(x: add, y: add) -> add {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ trait foo {
|
|||
}
|
||||
|
||||
impl foo for int {
|
||||
fn bar() {} //~ ERROR method `bar` is declared as static in its trait, but not in its impl
|
||||
fn bar(&self) {} //~ ERROR method `bar` is declared as static in its trait, but not in its impl
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait box_trait<T> {
|
||||
fn get() -> T;
|
||||
fn set(t: T);
|
||||
fn get(&self) -> T;
|
||||
fn set(&self, t: T);
|
||||
}
|
||||
|
||||
struct box<T> {
|
||||
|
|
@ -20,8 +20,8 @@ struct box<T> {
|
|||
struct box_impl<T>(box<T>);
|
||||
|
||||
impl<T:Copy> box_trait<T> for box_impl<T> {
|
||||
fn get() -> T { return self.f; }
|
||||
fn set(t: T) { self.f = t; }
|
||||
fn get(&self) -> T { return self.f; }
|
||||
fn set(&self, t: T) { self.f = t; }
|
||||
}
|
||||
|
||||
fn set_box_trait<T>(b: @box_trait<@const T>, v: @const T) {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
trait A { }
|
||||
|
||||
impl A for int {
|
||||
fn foo() { } //~ ERROR method `foo` is not a member of trait `A`
|
||||
fn foo(&self) { } //~ ERROR method `foo` is not a member of trait `A`
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait foo {
|
||||
fn bar(x: uint) -> Self;
|
||||
fn bar(&self, x: uint) -> Self;
|
||||
}
|
||||
impl foo for int {
|
||||
fn bar() -> int {
|
||||
fn bar(&self) -> int {
|
||||
//~^ ERROR method `bar` has 0 parameters but the trait has 1
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
// error-pattern: implement a trait or new type instead
|
||||
pub impl <T> Option<T> {
|
||||
fn foo() { }
|
||||
fn foo(&self) { }
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
trait bar { fn dup() -> Self; fn blah<X>(); }
|
||||
impl bar for int { fn dup() -> int { self } fn blah<X>() {} }
|
||||
impl bar for uint { fn dup() -> uint { self } fn blah<X>() {} }
|
||||
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>() {} }
|
||||
|
||||
fn main() {
|
||||
10i.dup::<int>(); //~ ERROR does not take type parameters
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
trait foo { fn foo(); }
|
||||
trait foo { fn foo(&self); }
|
||||
|
||||
impl int for uint { fn foo() {} } //~ ERROR trait
|
||||
impl int for uint { fn foo(&self) {} } //~ ERROR trait
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -9,15 +9,15 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait TraitA {
|
||||
fn method_a() -> int;
|
||||
fn method_a(&self) -> int;
|
||||
}
|
||||
|
||||
trait TraitB {
|
||||
fn gimme_an_a<A:TraitA>(a: A) -> int;
|
||||
fn gimme_an_a<A:TraitA>(&self, a: A) -> int;
|
||||
}
|
||||
|
||||
impl TraitB for int {
|
||||
fn gimme_an_a<A:TraitA>(a: A) -> int {
|
||||
fn gimme_an_a<A:TraitA>(&self, a: A) -> int {
|
||||
a.method_a() + self
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,11 +15,11 @@ fn failfn() {
|
|||
}
|
||||
|
||||
trait i {
|
||||
fn foo();
|
||||
fn foo(&self);
|
||||
}
|
||||
|
||||
impl i for ~int {
|
||||
fn foo() { }
|
||||
fn foo(&self) { }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@
|
|||
// it.
|
||||
|
||||
trait iterable<A> {
|
||||
fn iterate(blk: &fn(x: &A) -> bool);
|
||||
fn iterate(&self, blk: &fn(x: &A) -> bool);
|
||||
}
|
||||
|
||||
impl<A> iterable<A> for &self/[A] {
|
||||
fn iterate(f: &fn(x: &A) -> bool) {
|
||||
fn iterate(&self, f: &fn(x: &A) -> bool) {
|
||||
for vec::each(self) |e| {
|
||||
if !f(e) { break; }
|
||||
}
|
||||
|
|
@ -25,7 +25,7 @@ impl<A> iterable<A> for &self/[A] {
|
|||
}
|
||||
|
||||
impl<A> iterable<A> for ~[A] {
|
||||
fn iterate(f: &fn(x: &A) -> bool) {
|
||||
fn iterate(&self, f: &fn(x: &A) -> bool) {
|
||||
for vec::each(self) |e| {
|
||||
if !f(e) { break; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@ struct Foo {
|
|||
}
|
||||
|
||||
trait Stuff {
|
||||
fn printme();
|
||||
fn printme(self);
|
||||
}
|
||||
|
||||
impl Stuff for &self/Foo {
|
||||
fn printme() {
|
||||
fn printme(self) {
|
||||
io::println(fmt!("%d", self.x));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait double {
|
||||
fn double() -> uint;
|
||||
fn double(&self) -> uint;
|
||||
}
|
||||
|
||||
impl double for uint {
|
||||
fn double() -> uint { self * 2u }
|
||||
fn double(&self) -> uint { *self * 2u }
|
||||
}
|
||||
|
||||
struct foo(uint);
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait double {
|
||||
fn double() -> uint;
|
||||
fn double(self) -> uint;
|
||||
}
|
||||
|
||||
impl double for uint {
|
||||
fn double() -> uint { self * 2u }
|
||||
fn double(self) -> uint { self * 2u }
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
|
|
|||
|
|
@ -9,15 +9,15 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait double {
|
||||
fn double() -> uint;
|
||||
fn double(self) -> uint;
|
||||
}
|
||||
|
||||
impl double for uint {
|
||||
fn double() -> uint { self }
|
||||
fn double(self) -> uint { self }
|
||||
}
|
||||
|
||||
impl double for @uint {
|
||||
fn double() -> uint { *self * 2u }
|
||||
fn double(self) -> uint { *self * 2u }
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait double {
|
||||
fn double() -> uint;
|
||||
fn double(self) -> uint;
|
||||
}
|
||||
|
||||
impl double for @@uint {
|
||||
fn double() -> uint { **self * 2u }
|
||||
fn double(self) -> uint { **self * 2u }
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait double {
|
||||
fn double() -> uint;
|
||||
fn double(self) -> uint;
|
||||
}
|
||||
|
||||
impl double for uint {
|
||||
fn double() -> uint { self * 2u }
|
||||
fn double(self) -> uint { self * 2u }
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait double {
|
||||
fn double() -> uint;
|
||||
fn double(self) -> uint;
|
||||
}
|
||||
|
||||
impl double for uint {
|
||||
fn double() -> uint { self * 2u }
|
||||
fn double(self) -> uint { self * 2u }
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
|
|
|||
|
|
@ -15,11 +15,11 @@ struct baz_ {baz: int}
|
|||
type baz = @mut baz_;
|
||||
|
||||
trait frob {
|
||||
fn frob();
|
||||
fn frob(&self);
|
||||
}
|
||||
|
||||
impl frob for foo {
|
||||
fn frob() {
|
||||
fn frob(&self) {
|
||||
really_impure(self.bar);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait Foo {
|
||||
fn foo();
|
||||
fn foo(self);
|
||||
}
|
||||
|
||||
impl Foo for int {
|
||||
fn foo() {
|
||||
fn foo(self) {
|
||||
io::println("Hello world!");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait noisy {
|
||||
fn speak() -> int;
|
||||
fn speak(&self) -> int;
|
||||
}
|
||||
|
||||
struct dog {
|
||||
|
|
@ -19,7 +19,7 @@ struct dog {
|
|||
}
|
||||
|
||||
pub impl dog {
|
||||
priv fn bark() -> int {
|
||||
priv fn bark(&self) -> int {
|
||||
debug!("Woof %u %d", *self.barks, *self.volume);
|
||||
*self.barks += 1u;
|
||||
if *self.barks % 3u == 0u {
|
||||
|
|
@ -34,7 +34,7 @@ pub impl dog {
|
|||
}
|
||||
|
||||
impl noisy for dog {
|
||||
fn speak() -> int { self.bark() }
|
||||
fn speak(&self) -> int { self.bark() }
|
||||
}
|
||||
|
||||
fn dog() -> dog {
|
||||
|
|
@ -52,15 +52,15 @@ struct cat {
|
|||
}
|
||||
|
||||
impl noisy for cat {
|
||||
fn speak() -> int { self.meow() as int }
|
||||
fn speak(&self) -> int { self.meow() as int }
|
||||
}
|
||||
|
||||
pub impl cat {
|
||||
fn meow_count() -> uint { *self.meows }
|
||||
fn meow_count(&self) -> uint { *self.meows }
|
||||
}
|
||||
|
||||
priv impl cat {
|
||||
fn meow() -> uint {
|
||||
fn meow(&self) -> uint {
|
||||
debug!("Meow");
|
||||
*self.meows += 1u;
|
||||
if *self.meows % 5u == 0u {
|
||||
|
|
|
|||
|
|
@ -22,10 +22,10 @@ mod kitty {
|
|||
}
|
||||
|
||||
pub impl cat {
|
||||
fn get_name() -> ~str { copy self.name }
|
||||
fn get_name(&self) -> ~str { copy self.name }
|
||||
}
|
||||
|
||||
pub fn cat(in_name: ~str) -> cat {
|
||||
pub fn cat(&self, in_name: ~str) -> cat {
|
||||
cat {
|
||||
name: in_name,
|
||||
meows: 0u
|
||||
|
|
|
|||
|
|
@ -137,25 +137,25 @@ mod test_methods {
|
|||
|
||||
impl Fooable for Foo {
|
||||
#[cfg(bogus)]
|
||||
static fn what() { }
|
||||
static fn what(&self) { }
|
||||
|
||||
static fn what() { }
|
||||
static fn what(&self) { }
|
||||
|
||||
#[cfg(bogus)]
|
||||
fn the() { }
|
||||
fn the(&self) { }
|
||||
|
||||
fn the() { }
|
||||
fn the(&self) { }
|
||||
}
|
||||
|
||||
trait Fooable {
|
||||
#[cfg(bogus)]
|
||||
static fn what();
|
||||
static fn what(&self);
|
||||
|
||||
static fn what();
|
||||
static fn what(&self);
|
||||
|
||||
#[cfg(bogus)]
|
||||
fn the();
|
||||
fn the(&self);
|
||||
|
||||
fn the();
|
||||
fn the(&self);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@
|
|||
#[allow(default_methods)];
|
||||
|
||||
trait Foo {
|
||||
fn f() {
|
||||
fn f(&self) {
|
||||
io::println("Hello!");
|
||||
self.g();
|
||||
}
|
||||
fn g();
|
||||
fn g(&self);
|
||||
}
|
||||
|
||||
struct A {
|
||||
|
|
@ -23,7 +23,7 @@ struct A {
|
|||
}
|
||||
|
||||
impl Foo for A {
|
||||
fn g() {
|
||||
fn g(&self) {
|
||||
io::println("Goodbye!");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@
|
|||
|
||||
|
||||
trait thing<A> {
|
||||
fn foo() -> Option<A>;
|
||||
fn foo(&self) -> Option<A>;
|
||||
}
|
||||
impl<A> thing<A> for int {
|
||||
fn foo() -> Option<A> { None }
|
||||
fn foo(&self) -> Option<A> { None }
|
||||
}
|
||||
fn foo_func<A, B: thing<A>>(x: B) -> Option<A> { x.foo() }
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait Foo<T> {
|
||||
fn get() -> T;
|
||||
fn get(&self) -> T;
|
||||
}
|
||||
|
||||
struct S {
|
||||
|
|
@ -17,7 +17,7 @@ struct S {
|
|||
}
|
||||
|
||||
impl Foo<int> for S {
|
||||
fn get() -> int {
|
||||
fn get(&self) -> int {
|
||||
self.x
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ enum option_<T> {
|
|||
}
|
||||
|
||||
pub impl<T> option_<T> {
|
||||
fn foo() -> bool { true }
|
||||
fn foo(&self) -> bool { true }
|
||||
}
|
||||
|
||||
enum option__ {
|
||||
|
|
@ -23,7 +23,7 @@ enum option__ {
|
|||
}
|
||||
|
||||
pub impl option__ {
|
||||
fn foo() -> bool { true }
|
||||
fn foo(&self) -> bool { true }
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait foo {
|
||||
fn foo() -> uint;
|
||||
fn foo(&self) -> uint;
|
||||
}
|
||||
|
||||
impl<T> foo for ~[const T] {
|
||||
fn foo() -> uint { vec::len(self) }
|
||||
fn foo(&self) -> uint { vec::len(self) }
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait Send {
|
||||
fn f();
|
||||
fn f(&self);
|
||||
}
|
||||
|
||||
fn f<T:Send>(t: T) {
|
||||
t.f();
|
||||
t.f(&self);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
|
|
|||
|
|
@ -9,14 +9,14 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait c lam<A:Copy> {
|
||||
fn chowder(y: A);
|
||||
fn chowder(&self, y: A);
|
||||
}
|
||||
struct foo<A> {
|
||||
x: A,
|
||||
}
|
||||
|
||||
impl<A:Copy> clam<A> for foo<A> {
|
||||
fn chowder(y: A) {
|
||||
fn chowder(&self, y: A) {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ struct foo<A> {
|
|||
}
|
||||
|
||||
pub impl<A:Copy> foo<A> {
|
||||
fn bar<B,C:clam<A>>(c: C) -> B {
|
||||
fn bar<B,C:clam<A>>(&self, c: C) -> B {
|
||||
fail!();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
trait clam<A> { }
|
||||
trait foo<A> {
|
||||
fn bar<B,C:clam<A>>(c: C) -> B;
|
||||
fn bar<B,C:clam<A>>(&self, c: C) -> B;
|
||||
}
|
||||
|
||||
pub fn main() { }
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ trait clam<A> { }
|
|||
struct foo(int);
|
||||
|
||||
pub impl foo {
|
||||
fn bar<B,C:clam<B>>(c: C) -> B { fail!(); }
|
||||
fn bar<B,C:clam<B>>(&self, c: C) -> B { fail!(); }
|
||||
}
|
||||
|
||||
pub fn main() { }
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ struct c1<T> {
|
|||
}
|
||||
|
||||
pub impl<T:Copy> c1<T> {
|
||||
fn f1(x: int) {
|
||||
fn f1(&self, x: int) {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ fn c1<T:Copy>(x: T) -> c1<T> {
|
|||
}
|
||||
|
||||
pub impl<T:Copy> c1<T> {
|
||||
fn f2(x: int) {
|
||||
fn f2(&self, x: int) {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ struct c1<T> {
|
|||
}
|
||||
|
||||
pub impl<T:Copy> c1<T> {
|
||||
fn f1(x: T) {}
|
||||
fn f1(&self, x: T) {}
|
||||
}
|
||||
|
||||
fn c1<T:Copy>(x: T) -> c1<T> {
|
||||
|
|
@ -23,7 +23,7 @@ fn c1<T:Copy>(x: T) -> c1<T> {
|
|||
}
|
||||
|
||||
pub impl<T:Copy> c1<T> {
|
||||
fn f2(x: T) {}
|
||||
fn f2(&self, x: T) {}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -18,8 +18,7 @@ impl Drop for socket {
|
|||
}
|
||||
|
||||
pub impl socket {
|
||||
|
||||
fn set_identity() {
|
||||
fn set_identity(&self) {
|
||||
do closure {
|
||||
setsockopt_bytes(copy self.sock)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ struct font {
|
|||
}
|
||||
|
||||
pub impl font/&self {
|
||||
fn buf() -> &self/~[u8] {
|
||||
fn buf(&self) -> &self/~[u8] {
|
||||
self.fontbuf
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
trait hax { }
|
||||
impl<A> hax for A { }
|
||||
|
||||
fn perform_hax<T:&static>(x: @T) -> hax {
|
||||
fn perform_hax<T:&static>(x: @T) -> @hax {
|
||||
@x as @hax
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@
|
|||
type t = bool;
|
||||
|
||||
trait it {
|
||||
fn f();
|
||||
fn f(&self);
|
||||
}
|
||||
|
||||
impl it for t {
|
||||
fn f() { }
|
||||
fn f(&self) { }
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait bar<T> {
|
||||
fn get_bar() -> T;
|
||||
fn get_bar(&self) -> T;
|
||||
}
|
||||
|
||||
fn foo<T, U: bar<T>>(b: U) -> T {
|
||||
|
|
@ -21,7 +21,7 @@ struct cbar {
|
|||
}
|
||||
|
||||
impl bar<int> for cbar {
|
||||
fn get_bar() -> int {
|
||||
fn get_bar(&self) -> int {
|
||||
self.x
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@
|
|||
extern mod std;
|
||||
|
||||
trait methods {
|
||||
fn to_bytes() -> ~[u8];
|
||||
fn to_bytes(&self) -> ~[u8];
|
||||
}
|
||||
|
||||
impl methods for () {
|
||||
fn to_bytes() -> ~[u8] {
|
||||
fn to_bytes(&self) -> ~[u8] {
|
||||
vec::from_elem(0, 0)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@
|
|||
|
||||
#[allow(default_methods)]
|
||||
trait Canvas {
|
||||
fn add_point(point: &int);
|
||||
fn add_points(shapes: &[int]) {
|
||||
fn add_point(&self, point: &int);
|
||||
fn add_points(&self, shapes: &[int]) {
|
||||
for shapes.each |pt| {
|
||||
self.add_point(pt)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,14 +11,14 @@
|
|||
#[allow(default_methods)];
|
||||
|
||||
trait Foo {
|
||||
fn a() -> int;
|
||||
fn b() -> int {
|
||||
fn a(&self) -> int;
|
||||
fn b(&self) -> int {
|
||||
self.a() + 2
|
||||
}
|
||||
}
|
||||
|
||||
impl Foo for int {
|
||||
fn a() -> int {
|
||||
fn a(&self) -> int {
|
||||
3
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ pub enum Shape {
|
|||
}
|
||||
|
||||
pub impl Shape {
|
||||
pub fn area(sh: Shape) -> float {
|
||||
pub fn area(&self, sh: Shape) -> float {
|
||||
match sh {
|
||||
Circle(_, size) => float::consts::pi * size * size,
|
||||
Rectangle(Point {x, y}, Point {x: x2, y: y2}) => (x2 - x) * (y2 - y)
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
trait repeat<A> { fn get() -> A; }
|
||||
trait repeat<A> { fn get(&self) -> A; }
|
||||
|
||||
impl<A:Copy> repeat<A> for @A {
|
||||
fn get() -> A { *self }
|
||||
fn get(&self) -> A { *self }
|
||||
}
|
||||
|
||||
fn repeater<A:Copy>(v: @A) -> @repeat<A> {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait Product {
|
||||
fn product() -> int;
|
||||
fn product(&self) -> int;
|
||||
}
|
||||
|
||||
struct Foo {
|
||||
|
|
@ -18,13 +18,13 @@ struct Foo {
|
|||
}
|
||||
|
||||
pub impl Foo {
|
||||
fn sum() -> int {
|
||||
fn sum(&self) -> int {
|
||||
self.x + self.y
|
||||
}
|
||||
}
|
||||
|
||||
impl Product for Foo {
|
||||
fn product() -> int {
|
||||
fn product(&self) -> int {
|
||||
self.x * self.y
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,20 +13,20 @@
|
|||
#[frobable]
|
||||
trait frobable {
|
||||
#[frob_attr]
|
||||
fn frob();
|
||||
fn frob(&self);
|
||||
#[defrob_attr]
|
||||
fn defrob();
|
||||
fn defrob(&self);
|
||||
}
|
||||
|
||||
#[int_frobable]
|
||||
impl frobable for int {
|
||||
#[frob_attr1]
|
||||
fn frob() {
|
||||
fn frob(&self) {
|
||||
#[frob_attr2];
|
||||
}
|
||||
|
||||
#[defrob_attr1]
|
||||
fn defrob() {
|
||||
fn defrob(&self) {
|
||||
#[defrob_attr2];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@
|
|||
// xfail-fast
|
||||
|
||||
trait vec_monad<A> {
|
||||
fn bind<B:Copy>(f: &fn(&A) -> ~[B]) -> ~[B];
|
||||
fn bind<B:Copy>(&self, f: &fn(&A) -> ~[B]) -> ~[B];
|
||||
}
|
||||
|
||||
impl<A> vec_monad<A> for ~[A] {
|
||||
fn bind<B:Copy>(f: &fn(&A) -> ~[B]) -> ~[B] {
|
||||
fn bind<B:Copy>(&self, f: &fn(&A) -> ~[B]) -> ~[B] {
|
||||
let mut r = ~[];
|
||||
for self.each |elt| { r += f(elt); }
|
||||
r
|
||||
|
|
@ -23,11 +23,11 @@ impl<A> vec_monad<A> for ~[A] {
|
|||
}
|
||||
|
||||
trait option_monad<A> {
|
||||
fn bind<B>(f: &fn(&A) -> Option<B>) -> Option<B>;
|
||||
fn bind<B>(&self, f: &fn(&A) -> Option<B>) -> Option<B>;
|
||||
}
|
||||
|
||||
impl<A> option_monad<A> for Option<A> {
|
||||
fn bind<B>(f: &fn(&A) -> Option<B>) -> Option<B> {
|
||||
fn bind<B>(&self, f: &fn(&A) -> Option<B>) -> Option<B> {
|
||||
match self {
|
||||
Some(ref a) => { f(a) }
|
||||
None => { None }
|
||||
|
|
|
|||
|
|
@ -17,11 +17,11 @@ fn mk_nil<C:ty_ops>(cx: C) -> uint {
|
|||
}
|
||||
|
||||
trait ty_ops {
|
||||
fn mk() -> uint;
|
||||
fn mk(&self) -> uint;
|
||||
}
|
||||
|
||||
impl ty_ops for () {
|
||||
fn mk() -> uint { 22u }
|
||||
fn mk(&self) -> uint { 22u }
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
|
|
|||
|
|
@ -14,17 +14,17 @@ trait Serializer {
|
|||
}
|
||||
|
||||
trait Serializable {
|
||||
fn serialize<S:Serializer>(s: S);
|
||||
fn serialize<S:Serializer>(&self, s: S);
|
||||
}
|
||||
|
||||
impl Serializable for int {
|
||||
fn serialize<S:Serializer>(_s: S) { }
|
||||
fn serialize<S:Serializer>(&self, _s: S) { }
|
||||
}
|
||||
|
||||
struct F<A> { a: A }
|
||||
|
||||
impl<A:Copy + Serializable> Serializable for F<A> {
|
||||
fn serialize<S:Serializer>(s: S) {
|
||||
fn serialize<S:Serializer>(&self, s: S) {
|
||||
self.a.serialize(s);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ pub fn main() {
|
|||
}
|
||||
|
||||
pub impl b {
|
||||
fn do_stuff() -> int { return 37; }
|
||||
fn do_stuff(&self) -> int { return 37; }
|
||||
}
|
||||
|
||||
fn b(i:int) -> b {
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait get {
|
||||
fn get() -> int;
|
||||
fn get(self) -> int;
|
||||
}
|
||||
|
||||
// Note: impl on a slice
|
||||
impl get for &'self int {
|
||||
fn get() -> int {
|
||||
fn get(self) -> int {
|
||||
return *self;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@
|
|||
// except according to those terms.
|
||||
|
||||
trait sum {
|
||||
fn sum() -> int;
|
||||
fn sum(self) -> int;
|
||||
}
|
||||
|
||||
// Note: impl on a slice
|
||||
impl sum for &'self [int] {
|
||||
fn sum() -> int {
|
||||
fn sum(self) -> int {
|
||||
let mut sum = 0;
|
||||
for vec::each(self) |e| { sum += *e; }
|
||||
return sum;
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue