1
Fork 0

librustc: Remove implicit self from the language, except for old-style drop blocks.

This commit is contained in:
Patrick Walton 2013-03-12 19:32:14 -07:00
parent a410652bc9
commit 8fa66e8e07
133 changed files with 339 additions and 395 deletions

View file

@ -1135,7 +1135,7 @@ can sometimes make code awkward and parenthesis-filled.
~~~ ~~~
# struct Point { x: float, y: float } # struct Point { x: float, y: float }
# enum Shape { Rectangle(Point, Point) } # enum Shape { Rectangle(Point, Point) }
# impl Shape { fn area() -> int { 0 } } # impl Shape { fn area(&self) -> int { 0 } }
let start = @Point { x: 10f, y: 20f }; let start = @Point { x: 10f, y: 20f };
let end = ~Point { x: (*start).x + 100f, y: (*start).y + 100f }; let end = ~Point { x: (*start).x + 100f, y: (*start).y + 100f };
let rect = &Rectangle(*start, *end); let rect = &Rectangle(*start, *end);
@ -1149,7 +1149,7 @@ dot), so in most cases, explicitly dereferencing the receiver is not necessary.
~~~ ~~~
# struct Point { x: float, y: float } # struct Point { x: float, y: float }
# enum Shape { Rectangle(Point, Point) } # enum Shape { Rectangle(Point, Point) }
# impl Shape { fn area() -> int { 0 } } # impl Shape { fn area(&self) -> int { 0 } }
let start = @Point { x: 10f, y: 20f }; let start = @Point { x: 10f, y: 20f };
let end = ~Point { x: start.x + 100f, y: start.y + 100f }; let end = ~Point { x: start.x + 100f, y: start.y + 100f };
let rect = &Rectangle(*start, *end); let rect = &Rectangle(*start, *end);

View file

@ -75,7 +75,6 @@ pub enum lint {
non_camel_case_types, non_camel_case_types,
type_limits, type_limits,
default_methods, default_methods,
deprecated_self,
deprecated_mutable_fields, deprecated_mutable_fields,
deprecated_drop, deprecated_drop,
foreign_mode, foreign_mode,
@ -246,13 +245,6 @@ pub fn get_lint_dict() -> LintDict {
default: deny default: deny
}), }),
(@~"deprecated_self",
@LintSpec {
lint: deprecated_self,
desc: "warn about deprecated uses of `self`",
default: warn
}),
(@~"deprecated_mutable_fields", (@~"deprecated_mutable_fields",
@LintSpec { @LintSpec {
lint: deprecated_mutable_fields, lint: deprecated_mutable_fields,
@ -497,7 +489,6 @@ fn check_item(i: @ast::item, cx: ty::ctxt) {
check_item_deprecated_modes(cx, i); check_item_deprecated_modes(cx, i);
check_item_type_limits(cx, i); check_item_type_limits(cx, i);
check_item_default_methods(cx, i); check_item_default_methods(cx, i);
check_item_deprecated_self(cx, i);
check_item_deprecated_mutable_fields(cx, i); check_item_deprecated_mutable_fields(cx, i);
check_item_deprecated_drop(cx, i); check_item_deprecated_drop(cx, i);
} }
@ -677,46 +668,6 @@ fn check_item_default_methods(cx: ty::ctxt, item: @ast::item) {
} }
} }
fn check_item_deprecated_self(cx: ty::ctxt, item: @ast::item) {
fn maybe_warn(cx: ty::ctxt,
item: @ast::item,
self_ty: ast::self_ty) {
match self_ty.node {
ast::sty_by_ref => {
cx.sess.span_lint(
deprecated_self,
item.id,
item.id,
self_ty.span,
~"this method form is deprecated; use an explicit `self` \
parameter or mark the method as static");
}
_ => {}
}
}
match /*bad*/copy item.node {
ast::item_trait(_, _, methods) => {
for methods.each |method| {
match /*bad*/copy *method {
ast::required(ty_method) => {
maybe_warn(cx, item, ty_method.self_ty);
}
ast::provided(method) => {
maybe_warn(cx, item, method.self_ty);
}
}
}
}
ast::item_impl(_, _, _, methods) => {
for methods.each |method| {
maybe_warn(cx, item, method.self_ty);
}
}
_ => {}
}
}
fn check_item_deprecated_mutable_fields(cx: ty::ctxt, item: @ast::item) { fn check_item_deprecated_mutable_fields(cx: ty::ctxt, item: @ast::item) {
match item.node { match item.node {
ast::item_struct(struct_def, _) => { ast::item_struct(struct_def, _) => {

View file

@ -56,6 +56,7 @@ pub enum ObsoleteSyntax {
ObsoleteBareFnType, ObsoleteBareFnType,
ObsoleteNewtypeEnum, ObsoleteNewtypeEnum,
ObsoleteMode, ObsoleteMode,
ObsoleteImplicitSelf,
} }
impl to_bytes::IterBytes for ObsoleteSyntax { impl to_bytes::IterBytes for ObsoleteSyntax {
@ -181,6 +182,11 @@ pub impl Parser {
"obsolete argument mode", "obsolete argument mode",
"replace `-` or `++` mode with `+`" "replace `-` or `++` mode with `+`"
), ),
ObsoleteImplicitSelf => (
"implicit self",
"use an explicit `self` declaration or declare the method as \
static"
),
}; };
self.report(sp, kind, kind_str, desc); self.report(sp, kind, kind_str, desc);

View file

@ -78,7 +78,7 @@ use parse::obsolete::{ObsoleteMutVector, ObsoleteTraitImplVisibility};
use parse::obsolete::{ObsoleteRecordType, ObsoleteRecordPattern}; use parse::obsolete::{ObsoleteRecordType, ObsoleteRecordPattern};
use parse::obsolete::{ObsoleteAssertion, ObsoletePostFnTySigil}; use parse::obsolete::{ObsoleteAssertion, ObsoletePostFnTySigil};
use parse::obsolete::{ObsoleteBareFnType, ObsoleteNewtypeEnum}; use parse::obsolete::{ObsoleteBareFnType, ObsoleteNewtypeEnum};
use parse::obsolete::{ObsoleteMode}; use parse::obsolete::{ObsoleteMode, ObsoleteImplicitSelf};
use parse::prec::{as_prec, token_to_binop}; use parse::prec::{as_prec, token_to_binop};
use parse::token::{can_begin_expr, is_ident, is_ident_or_path}; use parse::token::{can_begin_expr, is_ident, is_ident_or_path};
use parse::token::{is_plain_ident, INTERPOLATED, special_idents}; use parse::token::{is_plain_ident, INTERPOLATED, special_idents};
@ -471,6 +471,10 @@ pub impl Parser {
// XXX: Wrong. Shouldn't allow both static and self_ty // XXX: Wrong. Shouldn't allow both static and self_ty
let self_ty = if is_static { static_sty } else { self_ty }; let self_ty = if is_static { static_sty } else { self_ty };
if self_ty.node == sty_by_ref {
self.obsolete(self_ty.span, ObsoleteImplicitSelf);
}
let hi = p.last_span.hi; let hi = p.last_span.hi;
debug!("parse_trait_methods(): trait method signature ends in \ debug!("parse_trait_methods(): trait method signature ends in \
`%s`", `%s`",
@ -2981,6 +2985,10 @@ pub impl Parser {
// XXX: interaction between staticness, self_ty is broken now // XXX: interaction between staticness, self_ty is broken now
let self_ty = if is_static { static_sty} else { self_ty }; let self_ty = if is_static { static_sty} else { self_ty };
if self_ty.node == sty_by_ref {
self.obsolete(self_ty.span, ObsoleteImplicitSelf);
}
let (inner_attrs, body) = self.parse_inner_attrs_and_block(true); let (inner_attrs, body) = self.parse_inner_attrs_and_block(true);
let hi = body.span.hi; let hi = body.span.hi;
let attrs = vec::append(attrs, inner_attrs); let attrs = vec::append(attrs, inner_attrs);

View file

@ -9,6 +9,6 @@
// except according to those terms. // except according to those terms.
trait me { 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 } }

View file

@ -17,7 +17,7 @@ pub mod kitties {
} }
pub impl cat { pub impl cat {
fn speak() {} fn speak(&self) {}
} }
pub fn cat(in_x : uint, in_y : int) -> cat { pub fn cat(in_x : uint, in_y : int) -> cat {

View file

@ -11,12 +11,12 @@
#[link(name="cci_impl_lib", vers="0.0")]; #[link(name="cci_impl_lib", vers="0.0")];
trait uint_helpers { trait uint_helpers {
fn to(v: uint, f: &fn(uint)); fn to(self, v: uint, f: &fn(uint));
} }
impl uint_helpers for uint { impl uint_helpers for uint {
#[inline] #[inline]
fn to(v: uint, f: &fn(uint)) { fn to(self, v: uint, f: &fn(uint)) {
let mut i = self; let mut i = self;
while i < v { while i < v {
f(i); f(i);

View file

@ -16,11 +16,11 @@ pub mod name_pool {
pub type name_pool = (); pub type name_pool = ();
pub trait add { pub trait add {
fn add(s: ~str); fn add(&self, s: ~str);
} }
impl add for name_pool { 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 type rt = @();
pub trait cx { pub trait cx {
fn cx(); fn cx(&self);
} }
impl cx for rt { impl cx for rt {
fn cx() { fn cx(&self) {
} }
} }
} }

View file

@ -14,10 +14,10 @@
type t1 = uint; type t1 = uint;
trait foo { trait foo {
fn foo(); fn foo(&self);
} }
impl foo for ~str { impl foo for ~str {
fn foo() {} fn foo(&self) {}
} }

View file

@ -56,5 +56,5 @@ fn context_res() -> context_res {
pub type context = arc_destruct<context_res>; pub type context = arc_destruct<context_res>;
pub impl context { pub impl context {
fn socket() { } fn socket(&self) { }
} }

View file

@ -12,13 +12,13 @@
pub struct S(()); pub struct S(());
pub impl S { pub impl S {
fn foo() { } fn foo(&self) { }
} }
pub trait T { pub trait T {
fn bar(); fn bar(&self);
} }
impl T for S { impl T for S {
fn bar() { } fn bar(&self) { }
} }

View file

@ -9,11 +9,11 @@
// except according to those terms. // except according to those terms.
trait x { trait x {
fn use_x<T>(); fn use_x<T>(&self);
} }
struct y(()); struct y(());
impl x for y { impl x for y {
fn use_x<T>() { fn use_x<T>(&self) {
struct foo { //~ ERROR quux struct foo { //~ ERROR quux
i: () i: ()
} }

View file

@ -8,14 +8,14 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
pub trait Foo { fn f() -> int; } pub trait Foo { fn f(&self) -> int; }
pub trait Bar { fn g() -> int; } pub trait Bar { fn g(&self) -> int; }
pub trait Baz { fn h() -> int; } pub trait Baz { fn h(&self) -> int; }
pub struct A { x: int } pub struct A { x: int }
impl Foo for A { fn f() -> int { 10 } } impl Foo for A { fn f(&self) -> int { 10 } }
impl Bar for A { fn g() -> int { 20 } } impl Bar for A { fn g(&self) -> int { 20 } }
impl Baz for A { fn h() -> int { 30 } } impl Baz for A { fn h(&self) -> int { 30 } }

View file

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
trait Foo { fn f() -> int; } trait Foo { fn f(&self) -> int; }
trait Bar { fn g() -> int; } trait Bar { fn g(&self) -> int; }
trait Baz { fn h() -> int; } trait Baz { fn h(&self) -> int; }
trait Quux: Foo + Bar + Baz { } trait Quux: Foo + Bar + Baz { }

View file

@ -10,7 +10,7 @@
pub trait Foo { pub trait Foo {
fn f() -> int; fn f(&self) -> int;
} }
pub struct A { pub struct A {
@ -18,5 +18,5 @@ pub struct A {
} }
impl Foo for A { impl Foo for A {
fn f() -> int { 10 } fn f(&self) -> int { 10 }
} }

View file

@ -9,15 +9,15 @@
// except according to those terms. // except according to those terms.
trait foo { trait foo {
fn foo() -> int; fn foo(&self) -> int;
} }
impl foo for ~[uint] { 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] { 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() { fn main() {

View file

@ -16,7 +16,7 @@ struct cat {
pub impl cat { pub impl cat {
fn speak() { self.meows += 1u; } fn speak(&self) { self.meows += 1u; }
} }
fn cat(in_x : uint, in_y : int) -> cat { fn cat(in_x : uint, in_y : int) -> cat {

View file

@ -15,11 +15,11 @@ struct Foo {
} }
trait Stuff { trait Stuff {
fn printme(); fn printme(self);
} }
impl Stuff for &'self mut Foo { impl Stuff for &'self mut Foo {
fn printme() { fn printme(self) {
io::println(fmt!("%d", self.x)); io::println(fmt!("%d", self.x));
} }
} }

View file

@ -13,11 +13,11 @@ fn foo<T>() {
} }
trait bar { trait bar {
fn bar<T:Copy>(); fn bar<T:Copy>(&self);
} }
impl bar for uint { impl bar for uint {
fn bar<T:Copy>() { fn bar<T:Copy>(&self) {
} }
} }

View file

@ -11,7 +11,7 @@
struct X(Either<(uint,uint),extern fn()>); struct X(Either<(uint,uint),extern fn()>);
pub impl &'self X { 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) blk(&**self)
} }
} }

View file

@ -20,7 +20,7 @@ impl ops::Add<int,int> for Point {
} }
pub impl Point { pub impl Point {
fn times(z: int) -> int { fn times(&self, z: int) -> int {
self.x * self.y * z self.x * self.y * z
} }
} }

View file

@ -11,18 +11,18 @@
struct point { x: int, y: int } struct point { x: int, y: int }
trait methods { trait methods {
fn impurem(); fn impurem(&self);
fn blockm(f: &fn()); fn blockm(&self, f: &fn());
pure fn purem(); pure fn purem(&self);
} }
impl methods for point { 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) {
} }
} }

View file

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
trait noisy { trait noisy {
fn speak(); fn speak(&self);
} }
struct cat { struct cat {
@ -21,7 +21,7 @@ struct cat {
pub impl cat { pub impl cat {
fn eat() -> bool { fn eat(&self) -> bool {
if self.how_hungry > 0 { if self.how_hungry > 0 {
error!("OM NOM NOM"); error!("OM NOM NOM");
self.how_hungry -= 2; self.how_hungry -= 2;
@ -35,12 +35,12 @@ pub impl cat {
} }
impl noisy for cat { impl noisy for cat {
fn speak() { self.meow(); } fn speak(&self) { self.meow(); }
} }
priv impl cat { priv impl cat {
fn meow() { fn meow(&self) {
error!("Meow"); error!("Meow");
self.meows += 1; self.meows += 1;
if self.meows % 5 == 0 { 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 { cat {
meows: in_x, meows: in_x,
how_hungry: in_y, how_hungry: in_y,

View file

@ -10,7 +10,7 @@
// error-pattern:missing method `eat` // error-pattern:missing method `eat`
trait animal { trait animal {
fn eat(); fn eat(&self);
} }
struct cat { struct cat {

View file

@ -13,8 +13,8 @@ struct cat {
} }
priv impl cat { priv impl cat {
fn sleep() { loop{} } fn sleep(&self) { loop{} }
fn meow() { fn meow(&self) {
error!("Meow"); error!("Meow");
meows += 1u; //~ ERROR unresolved name meows += 1u; //~ ERROR unresolved name
sleep(); //~ ERROR unresolved name sleep(); //~ ERROR unresolved name

View file

@ -13,7 +13,7 @@ struct Foo {
} }
trait Bar : Drop { trait Bar : Drop {
fn blah(); fn blah(&self);
} }
impl Drop for Foo { impl Drop for Foo {
@ -23,7 +23,7 @@ impl Drop for Foo {
} }
impl Bar for Foo { impl Bar for Foo {
fn blah() { fn blah(&self) {
self.finalize(); //~ ERROR explicit call to destructor self.finalize(); //~ ERROR explicit call to destructor
} }
} }

View file

@ -12,17 +12,17 @@
// issue 2258 // issue 2258
trait to_opt { trait to_opt {
fn to_option() -> Option<Self>; fn to_option(&self) -> Option<Self>;
} }
impl to_opt for uint { impl to_opt for uint {
fn to_option() -> Option<uint> { fn to_option(&self) -> Option<uint> {
Some(self) Some(self)
} }
} }
impl<T:Copy> to_opt for Option<T> { impl<T:Copy> to_opt for Option<T> {
fn to_option() -> Option<Option<T>> { fn to_option(&self) -> Option<Option<T>> {
Some(self) Some(self)
} }
} }

View file

@ -9,11 +9,11 @@
// except according to those terms. // except according to those terms.
trait vec_monad<A> { 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] { 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!(); let mut r = fail!();
for self.each |elt| { r += f(*elt); } for self.each |elt| { r += f(*elt); }
//~^ WARNING unreachable expression //~^ WARNING unreachable expression

View file

@ -11,12 +11,12 @@
enum chan { } enum chan { }
trait channel<T> { trait channel<T> {
fn send(v: T); fn send(&self, v: T);
} }
// `chan` is not a trait, it's an enum // `chan` is not a trait, it's an enum
impl chan for int { //~ ERROR can only implement trait types impl chan for int { //~ ERROR can only implement trait types
fn send(v: int) { fail!() } fn send(&self, v: int) { fail!() }
} }
fn main() { fn main() {

View file

@ -12,7 +12,7 @@
// an impl against a trait // an impl against a trait
trait A { trait A {
fn b<C:Copy,D>(x: C) -> C; fn b<C:Copy,D>(&self, x: C) -> C;
} }
struct E { struct E {
@ -21,7 +21,7 @@ struct E {
impl A for E { impl A for E {
// n.b. The error message is awful -- see #3404 // 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() {} fn main() {}

View file

@ -13,7 +13,7 @@ extern mod std;
fn siphash<T>() { fn siphash<T>() {
trait 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 attempt to use a type argument out of scope
//~^^ ERROR use of undeclared type name `T` //~^^ ERROR use of undeclared type name `T`
//~^^^ ERROR use of undeclared type name `T` //~^^^ ERROR use of undeclared type name `T`

View file

@ -11,8 +11,8 @@
extern mod std; extern mod std;
trait siphash { trait siphash {
fn result() -> u64; fn result(&self) -> u64;
fn reset(); fn reset(&self);
} }
fn siphash(k0 : u64, k1 : u64) -> siphash { fn siphash(k0 : u64, k1 : u64) -> siphash {
@ -21,7 +21,7 @@ fn siphash(k0 : u64, k1 : u64) -> siphash {
v1: u64, v1: u64,
} }
fn mk_result(st : SipState) -> u64 { fn mk_result(&self, st : SipState) -> u64 {
let v0 = st.v0, let v0 = st.v0,
v1 = st.v1; v1 = st.v1;
@ -29,13 +29,13 @@ fn siphash(k0 : u64, k1 : u64) -> siphash {
} }
impl siphash for SipState { impl siphash for SipState {
fn reset() { fn reset(&self) {
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture
//~^ ERROR unresolved name: `k0`. //~^ ERROR unresolved name: `k0`.
self.v1 = k1 ^ 0x646f72616e646f6d; //~ ERROR attempted dynamic environment-capture self.v1 = k1 ^ 0x646f72616e646f6d; //~ ERROR attempted dynamic environment-capture
//~^ ERROR unresolved name: `k1`. //~^ ERROR unresolved name: `k1`.
} }
fn result() -> u64 { return mk_result(self); } fn result(&self) -> u64 { return mk_result(self); }
} }
} }

View file

@ -11,7 +11,7 @@
extern mod std; extern mod std;
trait SipHash { trait SipHash {
fn reset(); fn reset(&self);
} }
fn siphash(k0 : u64) -> SipHash { fn siphash(k0 : u64) -> SipHash {
@ -20,7 +20,7 @@ fn siphash(k0 : u64) -> SipHash {
} }
impl SipHash for SipState { impl SipHash for SipState {
fn reset() { fn reset(&self) {
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture
//~^ ERROR unresolved name: `k0`. //~^ ERROR unresolved name: `k0`.
} }

View file

@ -10,11 +10,11 @@
struct P { child: Option<@mut P> } struct P { child: Option<@mut P> }
trait PTrait { trait PTrait {
fn getChildOption() -> Option<@P>; fn getChildOption(&self) -> Option<@P>;
} }
impl PTrait for 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 const childVal: @P = self.child.get(); //~ ERROR attempt to use a non-constant value in a constant
fail!(); fail!();
} }

View file

@ -16,7 +16,7 @@ mod my_mod {
MyStruct {priv_field: 4} MyStruct {priv_field: 4}
} }
pub impl MyStruct { pub impl MyStruct {
priv fn happyfun() {} priv fn happyfun(&self) {}
} }
} }

View file

@ -8,10 +8,10 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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 { impl<A:Copy> repeat<A> for @A {
fn get() -> A { *self } fn get(&self) -> A { *self }
} }
fn repeater<A:Copy>(v: @A) -> @repeat<A> { fn repeater<A:Copy>(v: @A) -> @repeat<A> {

View file

@ -12,11 +12,11 @@
// be parameterized by a region due to the &self/int constraint. // be parameterized by a region due to the &self/int constraint.
trait foo { trait foo {
fn foo(i: &'self int) -> int; fn foo(&self, i: &'self int) -> int;
} }
impl<T:Copy> foo<'self> for T { 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) { fn to_foo<T:Copy>(t: T) {

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
trait foo { fn foo(); } trait foo { fn foo(&self); }
fn to_foo<T:Copy + foo>(t: T) -> @foo { fn to_foo<T:Copy + foo>(t: T) -> @foo {
@t as @foo //~ ERROR value may contain borrowed pointers; use `&static` bound @t as @foo //~ ERROR value may contain borrowed pointers; use `&static` bound

View file

@ -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() {
}

View file

@ -15,7 +15,7 @@ use core::hashmap::linear::LinearMap;
fn main() { fn main() {
let x: @Map<~str, ~str> = @LinearMap::new::<~str, ~str>() as let x: @Map<~str, ~str> = @LinearMap::new::<~str, ~str>() as
@Map::<~str, ~str>; @(Map::<~str, ~str>);
let y: @Map<uint, ~str> = @x; let y: @Map<uint, ~str> = @x;
//~^ ERROR mismatched types: expected `@core::container::Map<uint,~str>` //~^ ERROR mismatched types: expected `@core::container::Map<uint,~str>`
} }

View file

@ -16,7 +16,7 @@ struct cat {
} }
pub impl cat { pub impl cat {
fn eat() { fn eat(&self) {
self.how_hungry -= 5; self.how_hungry -= 5;
} }

View file

@ -14,7 +14,7 @@ mod a {
} }
pub impl Foo { pub impl Foo {
priv fn foo() {} priv fn foo(&self) {}
} }
} }

View file

@ -18,7 +18,7 @@ mod kitties {
} }
pub impl cat { 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 { pub fn cat(in_x : uint, in_y : int) -> cat {

View file

@ -19,11 +19,11 @@ pure fn modify_in_box(sum: @mut S) {
} }
trait modify_in_box_rec { 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 { 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 sum.f = self; //~ ERROR assigning to mutable field prohibited in pure context
} }
} }

View file

@ -14,7 +14,7 @@
struct an_enum(&'self int); struct an_enum(&'self int);
trait a_trait { trait a_trait {
fn foo() -> &'self int; fn foo(&self) -> &'self int;
} }
struct a_class { x:&'self int } struct a_class { x:&'self int }

View file

@ -9,11 +9,11 @@
// except according to those terms. // except according to those terms.
trait deref { trait deref {
fn get() -> int; fn get(self) -> int;
} }
impl deref for &'self int { impl deref for &'self int {
fn get() -> int { fn get(self) -> int {
*self *self
} }
} }

View file

@ -19,12 +19,12 @@ struct c<'self> {
} }
trait set_f<'self> { trait set_f<'self> {
fn set_f_ok(b: @b<'self>); fn set_f_ok(&self, b: @b<'self>);
fn set_f_bad(b: @b); fn set_f_bad(&self, b: @b);
} }
impl<'self> set_f<'self> for c<'self> { 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; self.f = b;
} }

View file

@ -12,9 +12,9 @@
// refers to self. // refers to self.
trait foo<'self> { trait foo<'self> {
fn self_int() -> &'self int; fn self_int(&self) -> &'self int;
fn any_int() -> &int; fn any_int(&self) -> &int;
} }
struct with_foo<'self> { struct with_foo<'self> {
@ -34,7 +34,7 @@ impl<'self> set_foo_foo for with_foo<'self> {
// Bar is not region parameterized. // Bar is not region parameterized.
trait bar { trait bar {
fn any_int() -> &int; fn any_int(&self) -> &int;
} }
struct with_bar { struct with_bar {

View file

@ -12,7 +12,7 @@ struct ctxt { v: uint }
trait get_ctxt { trait get_ctxt {
// Here the `&` is bound in the method definition: // Here the `&` is bound in the method definition:
fn get_ctxt() -> &ctxt; fn get_ctxt(&self) -> &ctxt;
} }
struct has_ctxt { c: &'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 // Here an error occurs because we used `&self` but
// the definition used `&`: // 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 self.c
} }

View file

@ -11,13 +11,13 @@
struct ctxt { v: uint } struct ctxt { v: uint }
trait get_ctxt<'self> { trait get_ctxt<'self> {
fn get_ctxt() -> &'self ctxt; fn get_ctxt(&self) -> &'self ctxt;
} }
struct has_ctxt<'self> { c: &'self ctxt } struct has_ctxt<'self> { c: &'self ctxt }
impl<'self> get_ctxt<'self> for has_ctxt<'self> { 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 { fn make_gc() -> @get_ctxt {

View file

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
trait get_ctxt { trait get_ctxt {
fn get_ctxt() -> &self/uint; fn get_ctxt(&self) -> &self/uint;
} }
fn make_gc1(gc: @get_ctxt/&a) -> @get_ctxt/&b { fn make_gc1(gc: @get_ctxt/&a) -> @get_ctxt/&b {
@ -21,7 +21,7 @@ struct Foo {
} }
impl get_ctxt/&self for Foo/&self { 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 { fn make_gc2(foo: Foo/&a) -> @get_ctxt/&b {

View file

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
trait add { trait add {
fn plus(x: Self) -> Self; fn plus(&self, x: Self) -> Self;
} }
fn do_add(x: add, y: add) -> add { fn do_add(x: add, y: add) -> add {

View file

@ -14,7 +14,7 @@ trait foo {
} }
impl foo for int { 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() {} fn main() {}

View file

@ -9,8 +9,8 @@
// except according to those terms. // except according to those terms.
trait box_trait<T> { trait box_trait<T> {
fn get() -> T; fn get(&self) -> T;
fn set(t: T); fn set(&self, t: T);
} }
struct box<T> { struct box<T> {
@ -20,8 +20,8 @@ struct box<T> {
struct box_impl<T>(box<T>); struct box_impl<T>(box<T>);
impl<T:Copy> box_trait<T> for box_impl<T> { impl<T:Copy> box_trait<T> for box_impl<T> {
fn get() -> T { return self.f; } fn get(&self) -> T { return self.f; }
fn set(t: T) { self.f = t; } fn set(&self, t: T) { self.f = t; }
} }
fn set_box_trait<T>(b: @box_trait<@const T>, v: @const T) { fn set_box_trait<T>(b: @box_trait<@const T>, v: @const T) {

View file

@ -11,7 +11,7 @@
trait A { } trait A { }
impl A for int { 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() { } fn main() { }

View file

@ -9,10 +9,10 @@
// except according to those terms. // except according to those terms.
trait foo { trait foo {
fn bar(x: uint) -> Self; fn bar(&self, x: uint) -> Self;
} }
impl foo for int { impl foo for int {
fn bar() -> int { fn bar(&self) -> int {
//~^ ERROR method `bar` has 0 parameters but the trait has 1 //~^ ERROR method `bar` has 0 parameters but the trait has 1
self self
} }

View file

@ -10,7 +10,7 @@
// error-pattern: implement a trait or new type instead // error-pattern: implement a trait or new type instead
pub impl <T> Option<T> { pub impl <T> Option<T> {
fn foo() { } fn foo(&self) { }
} }
fn main() { } fn main() { }

View file

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
trait bar { fn dup() -> Self; fn blah<X>(); } trait bar { fn dup(&self) -> Self; fn blah<X>(); }
impl bar for int { fn dup() -> int { self } fn blah<X>() {} } impl bar for int { fn dup(&self) -> int { self } fn blah<X>() {} }
impl bar for uint { fn dup() -> uint { self } fn blah<X>() {} } impl bar for uint { fn dup(&self) -> uint { self } fn blah<X>() {} }
fn main() { fn main() {
10i.dup::<int>(); //~ ERROR does not take type parameters 10i.dup::<int>(); //~ ERROR does not take type parameters

View file

@ -8,8 +8,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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() {} fn main() {}

View file

@ -9,15 +9,15 @@
// except according to those terms. // except according to those terms.
trait TraitA { trait TraitA {
fn method_a() -> int; fn method_a(&self) -> int;
} }
trait TraitB { 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 { 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 a.method_a() + self
} }
} }

View file

@ -15,11 +15,11 @@ fn failfn() {
} }
trait i { trait i {
fn foo(); fn foo(&self);
} }
impl i for ~int { impl i for ~int {
fn foo() { } fn foo(&self) { }
} }
fn main() { fn main() {

View file

@ -13,11 +13,11 @@
// it. // it.
trait iterable<A> { 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] { 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| { for vec::each(self) |e| {
if !f(e) { break; } if !f(e) { break; }
} }
@ -25,7 +25,7 @@ impl<A> iterable<A> for &self/[A] {
} }
impl<A> iterable<A> for ~[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| { for vec::each(self) |e| {
if !f(e) { break; } if !f(e) { break; }
} }

View file

@ -13,11 +13,11 @@ struct Foo {
} }
trait Stuff { trait Stuff {
fn printme(); fn printme(self);
} }
impl Stuff for &self/Foo { impl Stuff for &self/Foo {
fn printme() { fn printme(self) {
io::println(fmt!("%d", self.x)); io::println(fmt!("%d", self.x));
} }
} }

View file

@ -9,11 +9,11 @@
// except according to those terms. // except according to those terms.
trait double { trait double {
fn double() -> uint; fn double(&self) -> uint;
} }
impl double for uint { impl double for uint {
fn double() -> uint { self * 2u } fn double(&self) -> uint { *self * 2u }
} }
struct foo(uint); struct foo(uint);

View file

@ -9,11 +9,11 @@
// except according to those terms. // except according to those terms.
trait double { trait double {
fn double() -> uint; fn double(self) -> uint;
} }
impl double for uint { impl double for uint {
fn double() -> uint { self * 2u } fn double(self) -> uint { self * 2u }
} }
pub fn main() { pub fn main() {

View file

@ -9,15 +9,15 @@
// except according to those terms. // except according to those terms.
trait double { trait double {
fn double() -> uint; fn double(self) -> uint;
} }
impl double for uint { impl double for uint {
fn double() -> uint { self } fn double(self) -> uint { self }
} }
impl double for @uint { impl double for @uint {
fn double() -> uint { *self * 2u } fn double(self) -> uint { *self * 2u }
} }
pub fn main() { pub fn main() {

View file

@ -9,11 +9,11 @@
// except according to those terms. // except according to those terms.
trait double { trait double {
fn double() -> uint; fn double(self) -> uint;
} }
impl double for @@uint { impl double for @@uint {
fn double() -> uint { **self * 2u } fn double(self) -> uint { **self * 2u }
} }
pub fn main() { pub fn main() {

View file

@ -9,11 +9,11 @@
// except according to those terms. // except according to those terms.
trait double { trait double {
fn double() -> uint; fn double(self) -> uint;
} }
impl double for uint { impl double for uint {
fn double() -> uint { self * 2u } fn double(self) -> uint { self * 2u }
} }
pub fn main() { pub fn main() {

View file

@ -9,11 +9,11 @@
// except according to those terms. // except according to those terms.
trait double { trait double {
fn double() -> uint; fn double(self) -> uint;
} }
impl double for uint { impl double for uint {
fn double() -> uint { self * 2u } fn double(self) -> uint { self * 2u }
} }
pub fn main() { pub fn main() {

View file

@ -15,11 +15,11 @@ struct baz_ {baz: int}
type baz = @mut baz_; type baz = @mut baz_;
trait frob { trait frob {
fn frob(); fn frob(&self);
} }
impl frob for foo { impl frob for foo {
fn frob() { fn frob(&self) {
really_impure(self.bar); really_impure(self.bar);
} }
} }

View file

@ -9,11 +9,11 @@
// except according to those terms. // except according to those terms.
trait Foo { trait Foo {
fn foo(); fn foo(self);
} }
impl Foo for int { impl Foo for int {
fn foo() { fn foo(self) {
io::println("Hello world!"); io::println("Hello world!");
} }
} }

View file

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
trait noisy { trait noisy {
fn speak() -> int; fn speak(&self) -> int;
} }
struct dog { struct dog {
@ -19,7 +19,7 @@ struct dog {
} }
pub impl dog { pub impl dog {
priv fn bark() -> int { priv fn bark(&self) -> int {
debug!("Woof %u %d", *self.barks, *self.volume); debug!("Woof %u %d", *self.barks, *self.volume);
*self.barks += 1u; *self.barks += 1u;
if *self.barks % 3u == 0u { if *self.barks % 3u == 0u {
@ -34,7 +34,7 @@ pub impl dog {
} }
impl noisy for dog { impl noisy for dog {
fn speak() -> int { self.bark() } fn speak(&self) -> int { self.bark() }
} }
fn dog() -> dog { fn dog() -> dog {
@ -52,15 +52,15 @@ struct cat {
} }
impl noisy for cat { impl noisy for cat {
fn speak() -> int { self.meow() as int } fn speak(&self) -> int { self.meow() as int }
} }
pub impl cat { pub impl cat {
fn meow_count() -> uint { *self.meows } fn meow_count(&self) -> uint { *self.meows }
} }
priv impl cat { priv impl cat {
fn meow() -> uint { fn meow(&self) -> uint {
debug!("Meow"); debug!("Meow");
*self.meows += 1u; *self.meows += 1u;
if *self.meows % 5u == 0u { if *self.meows % 5u == 0u {

View file

@ -22,10 +22,10 @@ mod kitty {
} }
pub impl cat { 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 { cat {
name: in_name, name: in_name,
meows: 0u meows: 0u

View file

@ -137,25 +137,25 @@ mod test_methods {
impl Fooable for Foo { impl Fooable for Foo {
#[cfg(bogus)] #[cfg(bogus)]
static fn what() { } static fn what(&self) { }
static fn what() { } static fn what(&self) { }
#[cfg(bogus)] #[cfg(bogus)]
fn the() { } fn the(&self) { }
fn the() { } fn the(&self) { }
} }
trait Fooable { trait Fooable {
#[cfg(bogus)] #[cfg(bogus)]
static fn what(); static fn what(&self);
static fn what(); static fn what(&self);
#[cfg(bogus)] #[cfg(bogus)]
fn the(); fn the(&self);
fn the(); fn the(&self);
} }
} }

View file

@ -11,11 +11,11 @@
#[allow(default_methods)]; #[allow(default_methods)];
trait Foo { trait Foo {
fn f() { fn f(&self) {
io::println("Hello!"); io::println("Hello!");
self.g(); self.g();
} }
fn g(); fn g(&self);
} }
struct A { struct A {
@ -23,7 +23,7 @@ struct A {
} }
impl Foo for A { impl Foo for A {
fn g() { fn g(&self) {
io::println("Goodbye!"); io::println("Goodbye!");
} }
} }

View file

@ -10,10 +10,10 @@
trait thing<A> { trait thing<A> {
fn foo() -> Option<A>; fn foo(&self) -> Option<A>;
} }
impl<A> thing<A> for int { 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() } fn foo_func<A, B: thing<A>>(x: B) -> Option<A> { x.foo() }

View file

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
trait Foo<T> { trait Foo<T> {
fn get() -> T; fn get(&self) -> T;
} }
struct S { struct S {
@ -17,7 +17,7 @@ struct S {
} }
impl Foo<int> for S { impl Foo<int> for S {
fn get() -> int { fn get(&self) -> int {
self.x self.x
} }
} }

View file

@ -14,7 +14,7 @@ enum option_<T> {
} }
pub impl<T> option_<T> { pub impl<T> option_<T> {
fn foo() -> bool { true } fn foo(&self) -> bool { true }
} }
enum option__ { enum option__ {
@ -23,7 +23,7 @@ enum option__ {
} }
pub impl option__ { pub impl option__ {
fn foo() -> bool { true } fn foo(&self) -> bool { true }
} }
pub fn main() { pub fn main() {

View file

@ -9,11 +9,11 @@
// except according to those terms. // except according to those terms.
trait foo { trait foo {
fn foo() -> uint; fn foo(&self) -> uint;
} }
impl<T> foo for ~[const T] { impl<T> foo for ~[const T] {
fn foo() -> uint { vec::len(self) } fn foo(&self) -> uint { vec::len(self) }
} }
pub fn main() { pub fn main() {

View file

@ -9,11 +9,11 @@
// except according to those terms. // except according to those terms.
trait Send { trait Send {
fn f(); fn f(&self);
} }
fn f<T:Send>(t: T) { fn f<T:Send>(t: T) {
t.f(); t.f(&self);
} }
pub fn main() { pub fn main() {

View file

@ -9,14 +9,14 @@
// except according to those terms. // except according to those terms.
trait c lam<A:Copy> { trait c lam<A:Copy> {
fn chowder(y: A); fn chowder(&self, y: A);
} }
struct foo<A> { struct foo<A> {
x: A, x: A,
} }
impl<A:Copy> clam<A> for foo<A> { impl<A:Copy> clam<A> for foo<A> {
fn chowder(y: A) { fn chowder(&self, y: A) {
} }
} }

View file

@ -14,7 +14,7 @@ struct foo<A> {
} }
pub impl<A:Copy> 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!(); fail!();
} }
} }

View file

@ -10,7 +10,7 @@
trait clam<A> { } trait clam<A> { }
trait foo<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() { } pub fn main() { }

View file

@ -15,7 +15,7 @@ trait clam<A> { }
struct foo(int); struct foo(int);
pub impl foo { 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() { } pub fn main() { }

View file

@ -13,7 +13,7 @@ struct c1<T> {
} }
pub impl<T:Copy> 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> { pub impl<T:Copy> c1<T> {
fn f2(x: int) { fn f2(&self, x: int) {
} }
} }

View file

@ -13,7 +13,7 @@ struct c1<T> {
} }
pub impl<T:Copy> 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> { 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> { pub impl<T:Copy> c1<T> {
fn f2(x: T) {} fn f2(&self, x: T) {}
} }

View file

@ -18,8 +18,7 @@ impl Drop for socket {
} }
pub impl socket { pub impl socket {
fn set_identity(&self) {
fn set_identity() {
do closure { do closure {
setsockopt_bytes(copy self.sock) setsockopt_bytes(copy self.sock)
} }

View file

@ -13,7 +13,7 @@ struct font {
} }
pub impl font/&self { pub impl font/&self {
fn buf() -> &self/~[u8] { fn buf(&self) -> &self/~[u8] {
self.fontbuf self.fontbuf
} }
} }

View file

@ -11,7 +11,7 @@
trait hax { } trait hax { }
impl<A> hax for A { } impl<A> hax for A { }
fn perform_hax<T:&static>(x: @T) -> hax { fn perform_hax<T:&static>(x: @T) -> @hax {
@x as @hax @x as @hax
} }

View file

@ -13,11 +13,11 @@
type t = bool; type t = bool;
trait it { trait it {
fn f(); fn f(&self);
} }
impl it for t { impl it for t {
fn f() { } fn f(&self) { }
} }
pub fn main() { pub fn main() {

View file

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
trait bar<T> { trait bar<T> {
fn get_bar() -> T; fn get_bar(&self) -> T;
} }
fn foo<T, U: bar<T>>(b: U) -> T { fn foo<T, U: bar<T>>(b: U) -> T {
@ -21,7 +21,7 @@ struct cbar {
} }
impl bar<int> for cbar { impl bar<int> for cbar {
fn get_bar() -> int { fn get_bar(&self) -> int {
self.x self.x
} }
} }

View file

@ -11,11 +11,11 @@
extern mod std; extern mod std;
trait methods { trait methods {
fn to_bytes() -> ~[u8]; fn to_bytes(&self) -> ~[u8];
} }
impl methods for () { impl methods for () {
fn to_bytes() -> ~[u8] { fn to_bytes(&self) -> ~[u8] {
vec::from_elem(0, 0) vec::from_elem(0, 0)
} }
} }

View file

@ -10,8 +10,8 @@
#[allow(default_methods)] #[allow(default_methods)]
trait Canvas { trait Canvas {
fn add_point(point: &int); fn add_point(&self, point: &int);
fn add_points(shapes: &[int]) { fn add_points(&self, shapes: &[int]) {
for shapes.each |pt| { for shapes.each |pt| {
self.add_point(pt) self.add_point(pt)
} }

View file

@ -11,14 +11,14 @@
#[allow(default_methods)]; #[allow(default_methods)];
trait Foo { trait Foo {
fn a() -> int; fn a(&self) -> int;
fn b() -> int { fn b(&self) -> int {
self.a() + 2 self.a() + 2
} }
} }
impl Foo for int { impl Foo for int {
fn a() -> int { fn a(&self) -> int {
3 3
} }
} }

View file

@ -23,7 +23,7 @@ pub enum Shape {
} }
pub impl Shape { pub impl Shape {
pub fn area(sh: Shape) -> float { pub fn area(&self, sh: Shape) -> float {
match sh { match sh {
Circle(_, size) => float::consts::pi * size * size, Circle(_, size) => float::consts::pi * size * size,
Rectangle(Point {x, y}, Point {x: x2, y: y2}) => (x2 - x) * (y2 - y) Rectangle(Point {x, y}, Point {x: x2, y: y2}) => (x2 - x) * (y2 - y)

View file

@ -8,10 +8,10 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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 { impl<A:Copy> repeat<A> for @A {
fn get() -> A { *self } fn get(&self) -> A { *self }
} }
fn repeater<A:Copy>(v: @A) -> @repeat<A> { fn repeater<A:Copy>(v: @A) -> @repeat<A> {

View file

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
trait Product { trait Product {
fn product() -> int; fn product(&self) -> int;
} }
struct Foo { struct Foo {
@ -18,13 +18,13 @@ struct Foo {
} }
pub impl Foo { pub impl Foo {
fn sum() -> int { fn sum(&self) -> int {
self.x + self.y self.x + self.y
} }
} }
impl Product for Foo { impl Product for Foo {
fn product() -> int { fn product(&self) -> int {
self.x * self.y self.x * self.y
} }
} }

View file

@ -13,20 +13,20 @@
#[frobable] #[frobable]
trait frobable { trait frobable {
#[frob_attr] #[frob_attr]
fn frob(); fn frob(&self);
#[defrob_attr] #[defrob_attr]
fn defrob(); fn defrob(&self);
} }
#[int_frobable] #[int_frobable]
impl frobable for int { impl frobable for int {
#[frob_attr1] #[frob_attr1]
fn frob() { fn frob(&self) {
#[frob_attr2]; #[frob_attr2];
} }
#[defrob_attr1] #[defrob_attr1]
fn defrob() { fn defrob(&self) {
#[defrob_attr2]; #[defrob_attr2];
} }
} }

View file

@ -11,11 +11,11 @@
// xfail-fast // xfail-fast
trait vec_monad<A> { 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] { 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 = ~[]; let mut r = ~[];
for self.each |elt| { r += f(elt); } for self.each |elt| { r += f(elt); }
r r
@ -23,11 +23,11 @@ impl<A> vec_monad<A> for ~[A] {
} }
trait option_monad<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> { 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 { match self {
Some(ref a) => { f(a) } Some(ref a) => { f(a) }
None => { None } None => { None }

View file

@ -17,11 +17,11 @@ fn mk_nil<C:ty_ops>(cx: C) -> uint {
} }
trait ty_ops { trait ty_ops {
fn mk() -> uint; fn mk(&self) -> uint;
} }
impl ty_ops for () { impl ty_ops for () {
fn mk() -> uint { 22u } fn mk(&self) -> uint { 22u }
} }
pub fn main() { pub fn main() {

Some files were not shown because too many files have changed in this diff Show more