diff --git a/doc/tutorial.md b/doc/tutorial.md index 3fa53abf6b9..3e7b9400e17 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -1135,7 +1135,7 @@ can sometimes make code awkward and parenthesis-filled. ~~~ # struct Point { x: float, y: float } # 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 end = ~Point { x: (*start).x + 100f, y: (*start).y + 100f }; 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 } # 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 end = ~Point { x: start.x + 100f, y: start.y + 100f }; let rect = &Rectangle(*start, *end); diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 505bc350249..1227f7859d8 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -75,7 +75,6 @@ pub enum lint { non_camel_case_types, type_limits, default_methods, - deprecated_self, deprecated_mutable_fields, deprecated_drop, foreign_mode, @@ -246,13 +245,6 @@ pub fn get_lint_dict() -> LintDict { default: deny }), - (@~"deprecated_self", - @LintSpec { - lint: deprecated_self, - desc: "warn about deprecated uses of `self`", - default: warn - }), - (@~"deprecated_mutable_fields", @LintSpec { 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_type_limits(cx, i); check_item_default_methods(cx, i); - check_item_deprecated_self(cx, i); check_item_deprecated_mutable_fields(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) { match item.node { ast::item_struct(struct_def, _) => { diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 2ade0810dea..9f5a79c4f81 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -56,6 +56,7 @@ pub enum ObsoleteSyntax { ObsoleteBareFnType, ObsoleteNewtypeEnum, ObsoleteMode, + ObsoleteImplicitSelf, } impl to_bytes::IterBytes for ObsoleteSyntax { @@ -181,6 +182,11 @@ pub impl Parser { "obsolete argument mode", "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); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 0f06976249b..815a8bfab5d 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -78,7 +78,7 @@ use parse::obsolete::{ObsoleteMutVector, ObsoleteTraitImplVisibility}; use parse::obsolete::{ObsoleteRecordType, ObsoleteRecordPattern}; use parse::obsolete::{ObsoleteAssertion, ObsoletePostFnTySigil}; use parse::obsolete::{ObsoleteBareFnType, ObsoleteNewtypeEnum}; -use parse::obsolete::{ObsoleteMode}; +use parse::obsolete::{ObsoleteMode, ObsoleteImplicitSelf}; use parse::prec::{as_prec, token_to_binop}; use parse::token::{can_begin_expr, is_ident, is_ident_or_path}; 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 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; debug!("parse_trait_methods(): trait method signature ends in \ `%s`", @@ -2981,6 +2985,10 @@ pub impl Parser { // XXX: interaction between staticness, self_ty is broken now 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 hi = body.span.hi; let attrs = vec::append(attrs, inner_attrs); diff --git a/src/test/auxiliary/ambig_impl_2_lib.rs b/src/test/auxiliary/ambig_impl_2_lib.rs index c6dfe7b79a9..7c6a920fdd0 100644 --- a/src/test/auxiliary/ambig_impl_2_lib.rs +++ b/src/test/auxiliary/ambig_impl_2_lib.rs @@ -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 } } diff --git a/src/test/auxiliary/cci_class_2.rs b/src/test/auxiliary/cci_class_2.rs index b955ed9c2a7..9dc27054ef7 100644 --- a/src/test/auxiliary/cci_class_2.rs +++ b/src/test/auxiliary/cci_class_2.rs @@ -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 { diff --git a/src/test/auxiliary/cci_impl_lib.rs b/src/test/auxiliary/cci_impl_lib.rs index b7149be00cc..b4191ff1d68 100644 --- a/src/test/auxiliary/cci_impl_lib.rs +++ b/src/test/auxiliary/cci_impl_lib.rs @@ -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); diff --git a/src/test/auxiliary/crate-method-reexport-grrrrrrr2.rs b/src/test/auxiliary/crate-method-reexport-grrrrrrr2.rs index f578ad82d6d..ea42a51ff11 100644 --- a/src/test/auxiliary/crate-method-reexport-grrrrrrr2.rs +++ b/src/test/auxiliary/crate-method-reexport-grrrrrrr2.rs @@ -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) { } } } diff --git a/src/test/auxiliary/issue-2414-a.rs b/src/test/auxiliary/issue-2414-a.rs index fb97adf51a5..9f4f369b70d 100644 --- a/src/test/auxiliary/issue-2414-a.rs +++ b/src/test/auxiliary/issue-2414-a.rs @@ -14,10 +14,10 @@ type t1 = uint; trait foo { - fn foo(); + fn foo(&self); } impl foo for ~str { - fn foo() {} + fn foo(&self) {} } diff --git a/src/test/auxiliary/issue-2526.rs b/src/test/auxiliary/issue-2526.rs index 958fb75b9d2..c09e64eac8c 100644 --- a/src/test/auxiliary/issue-2526.rs +++ b/src/test/auxiliary/issue-2526.rs @@ -56,5 +56,5 @@ fn context_res() -> context_res { pub type context = arc_destruct; pub impl context { - fn socket() { } + fn socket(&self) { } } diff --git a/src/test/auxiliary/issue_2472_b.rs b/src/test/auxiliary/issue_2472_b.rs index 1dd30edcc98..7969128ce52 100644 --- a/src/test/auxiliary/issue_2472_b.rs +++ b/src/test/auxiliary/issue_2472_b.rs @@ -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) { } } diff --git a/src/test/auxiliary/issue_3136_a.rs b/src/test/auxiliary/issue_3136_a.rs index c80457ef1e9..f7c866da9ae 100644 --- a/src/test/auxiliary/issue_3136_a.rs +++ b/src/test/auxiliary/issue_3136_a.rs @@ -9,11 +9,11 @@ // except according to those terms. trait x { - fn use_x(); + fn use_x(&self); } struct y(()); impl x for y { - fn use_x() { + fn use_x(&self) { struct foo { //~ ERROR quux i: () } diff --git a/src/test/auxiliary/trait_inheritance_auto_xc_2_aux.rs b/src/test/auxiliary/trait_inheritance_auto_xc_2_aux.rs index 11d4b28c215..1c7ebd941c3 100644 --- a/src/test/auxiliary/trait_inheritance_auto_xc_2_aux.rs +++ b/src/test/auxiliary/trait_inheritance_auto_xc_2_aux.rs @@ -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 } } diff --git a/src/test/auxiliary/trait_inheritance_auto_xc_aux.rs b/src/test/auxiliary/trait_inheritance_auto_xc_aux.rs index ecd43686b77..d5949d1ce09 100644 --- a/src/test/auxiliary/trait_inheritance_auto_xc_aux.rs +++ b/src/test/auxiliary/trait_inheritance_auto_xc_aux.rs @@ -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 { } diff --git a/src/test/auxiliary/trait_inheritance_cross_trait_call_xc_aux.rs b/src/test/auxiliary/trait_inheritance_cross_trait_call_xc_aux.rs index 724860d6855..c9694fec610 100644 --- a/src/test/auxiliary/trait_inheritance_cross_trait_call_xc_aux.rs +++ b/src/test/auxiliary/trait_inheritance_cross_trait_call_xc_aux.rs @@ -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 } } diff --git a/src/test/compile-fail/ambig_impl_unify.rs b/src/test/compile-fail/ambig_impl_unify.rs index 7e27a51ccdd..ce8c2a29544 100644 --- a/src/test/compile-fail/ambig_impl_unify.rs +++ b/src/test/compile-fail/ambig_impl_unify.rs @@ -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() { diff --git a/src/test/compile-fail/assign-to-method.rs b/src/test/compile-fail/assign-to-method.rs index 2436e4da8df..4993846f445 100644 --- a/src/test/compile-fail/assign-to-method.rs +++ b/src/test/compile-fail/assign-to-method.rs @@ -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 { diff --git a/src/test/compile-fail/auto-ref-borrowck-failure.rs b/src/test/compile-fail/auto-ref-borrowck-failure.rs index 3cf1c770df7..9fe7ae40dbb 100644 --- a/src/test/compile-fail/auto-ref-borrowck-failure.rs +++ b/src/test/compile-fail/auto-ref-borrowck-failure.rs @@ -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)); } } diff --git a/src/test/compile-fail/bad-method-typaram-kind.rs b/src/test/compile-fail/bad-method-typaram-kind.rs index 7032a3a0b22..d5b8f99ada0 100644 --- a/src/test/compile-fail/bad-method-typaram-kind.rs +++ b/src/test/compile-fail/bad-method-typaram-kind.rs @@ -13,11 +13,11 @@ fn foo() { } trait bar { - fn bar(); + fn bar(&self); } impl bar for uint { - fn bar() { + fn bar(&self) { } } diff --git a/src/test/compile-fail/borrowck-autoref-3261.rs b/src/test/compile-fail/borrowck-autoref-3261.rs index b874eac34b1..9f517ad99a1 100644 --- a/src/test/compile-fail/borrowck-autoref-3261.rs +++ b/src/test/compile-fail/borrowck-autoref-3261.rs @@ -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) } } diff --git a/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs b/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs index 61cf346ffa4..23debb4c5e2 100644 --- a/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs +++ b/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs @@ -20,7 +20,7 @@ impl ops::Add for Point { } pub impl Point { - fn times(z: int) -> int { + fn times(&self, z: int) -> int { self.x * self.y * z } } diff --git a/src/test/compile-fail/borrowck-loan-rcvr.rs b/src/test/compile-fail/borrowck-loan-rcvr.rs index 85989bf9d21..4a7228dcca3 100644 --- a/src/test/compile-fail/borrowck-loan-rcvr.rs +++ b/src/test/compile-fail/borrowck-loan-rcvr.rs @@ -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) { } } diff --git a/src/test/compile-fail/class-cast-to-trait.rs b/src/test/compile-fail/class-cast-to-trait.rs index 9133b80aa1e..caa79132182 100644 --- a/src/test/compile-fail/class-cast-to-trait.rs +++ b/src/test/compile-fail/class-cast-to-trait.rs @@ -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, diff --git a/src/test/compile-fail/class-method-missing.rs b/src/test/compile-fail/class-method-missing.rs index 2a7e2cea6fa..f3c5ab2019d 100644 --- a/src/test/compile-fail/class-method-missing.rs +++ b/src/test/compile-fail/class-method-missing.rs @@ -10,7 +10,7 @@ // error-pattern:missing method `eat` trait animal { - fn eat(); + fn eat(&self); } struct cat { diff --git a/src/test/compile-fail/class-missing-self.rs b/src/test/compile-fail/class-missing-self.rs index 9d3eb644656..b78b065d028 100644 --- a/src/test/compile-fail/class-missing-self.rs +++ b/src/test/compile-fail/class-missing-self.rs @@ -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 diff --git a/src/test/compile-fail/explicit-call-to-supertrait-dtor.rs b/src/test/compile-fail/explicit-call-to-supertrait-dtor.rs index 3b1dda19448..26b13566f7a 100644 --- a/src/test/compile-fail/explicit-call-to-supertrait-dtor.rs +++ b/src/test/compile-fail/explicit-call-to-supertrait-dtor.rs @@ -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 } } diff --git a/src/test/compile-fail/infinite-instantiation.rs b/src/test/compile-fail/infinite-instantiation.rs index 21f49b11f66..23b9532083a 100644 --- a/src/test/compile-fail/infinite-instantiation.rs +++ b/src/test/compile-fail/infinite-instantiation.rs @@ -12,17 +12,17 @@ // issue 2258 trait to_opt { - fn to_option() -> Option; + fn to_option(&self) -> Option; } impl to_opt for uint { - fn to_option() -> Option { + fn to_option(&self) -> Option { Some(self) } } impl to_opt for Option { - fn to_option() -> Option> { + fn to_option(&self) -> Option> { Some(self) } } diff --git a/src/test/compile-fail/issue-2149.rs b/src/test/compile-fail/issue-2149.rs index 361a20ad451..def1fa30f3b 100644 --- a/src/test/compile-fail/issue-2149.rs +++ b/src/test/compile-fail/issue-2149.rs @@ -9,11 +9,11 @@ // except according to those terms. trait vec_monad { - fn bind(f: &fn(A) -> ~[B]); + fn bind(&self, f: &fn(A) -> ~[B]); } impl vec_monad for ~[A] { - fn bind(f: &fn(A) -> ~[B]) { + fn bind(&self, f: &fn(A) -> ~[B]) { let mut r = fail!(); for self.each |elt| { r += f(*elt); } //~^ WARNING unreachable expression diff --git a/src/test/compile-fail/issue-2330.rs b/src/test/compile-fail/issue-2330.rs index e255d46633a..d8acbf2893a 100644 --- a/src/test/compile-fail/issue-2330.rs +++ b/src/test/compile-fail/issue-2330.rs @@ -11,12 +11,12 @@ enum chan { } trait channel { - 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() { diff --git a/src/test/compile-fail/issue-2611-5.rs b/src/test/compile-fail/issue-2611-5.rs index b0e2878c46b..9840650fa2e 100644 --- a/src/test/compile-fail/issue-2611-5.rs +++ b/src/test/compile-fail/issue-2611-5.rs @@ -12,7 +12,7 @@ // an impl against a trait trait A { - fn b(x: C) -> C; + fn b(&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(_x: G) -> G { fail!() } //~ ERROR method `b` has an incompatible type + fn b(&self, _x: G) -> G { fail!() } //~ ERROR method `b` has an incompatible type } fn main() {} diff --git a/src/test/compile-fail/issue-3021-c.rs b/src/test/compile-fail/issue-3021-c.rs index f5bcae5377c..4fc4c005cf6 100644 --- a/src/test/compile-fail/issue-3021-c.rs +++ b/src/test/compile-fail/issue-3021-c.rs @@ -13,7 +13,7 @@ extern mod std; fn siphash() { 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` diff --git a/src/test/compile-fail/issue-3021-d.rs b/src/test/compile-fail/issue-3021-d.rs index 4efbec92948..5b076c81eb8 100644 --- a/src/test/compile-fail/issue-3021-d.rs +++ b/src/test/compile-fail/issue-3021-d.rs @@ -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); } } } diff --git a/src/test/compile-fail/issue-3021.rs b/src/test/compile-fail/issue-3021.rs index 117156748ae..343683d79c1 100644 --- a/src/test/compile-fail/issue-3021.rs +++ b/src/test/compile-fail/issue-3021.rs @@ -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`. } diff --git a/src/test/compile-fail/issue-3668.rs b/src/test/compile-fail/issue-3668.rs index 2b25afeb0e7..1b121878697 100644 --- a/src/test/compile-fail/issue-3668.rs +++ b/src/test/compile-fail/issue-3668.rs @@ -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!(); } diff --git a/src/test/compile-fail/issue-3763.rs b/src/test/compile-fail/issue-3763.rs index 09a3f3d89c4..f6226032eee 100644 --- a/src/test/compile-fail/issue-3763.rs +++ b/src/test/compile-fail/issue-3763.rs @@ -16,7 +16,7 @@ mod my_mod { MyStruct {priv_field: 4} } pub impl MyStruct { - priv fn happyfun() {} + priv fn happyfun(&self) {} } } diff --git a/src/test/compile-fail/kindck-owned-trait-contains.rs b/src/test/compile-fail/kindck-owned-trait-contains.rs index 4f8269bb11b..abde71fb5d3 100644 --- a/src/test/compile-fail/kindck-owned-trait-contains.rs +++ b/src/test/compile-fail/kindck-owned-trait-contains.rs @@ -8,10 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -trait repeat { fn get() -> A; } +trait repeat { fn get(&self) -> A; } impl repeat for @A { - fn get() -> A { *self } + fn get(&self) -> A { *self } } fn repeater(v: @A) -> @repeat { diff --git a/src/test/compile-fail/kindck-owned-trait-scoped.rs b/src/test/compile-fail/kindck-owned-trait-scoped.rs index 391b65e3c81..1f8b9577e6c 100644 --- a/src/test/compile-fail/kindck-owned-trait-scoped.rs +++ b/src/test/compile-fail/kindck-owned-trait-scoped.rs @@ -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 foo<'self> for T { - fn foo(i: &'self int) -> int {*i} + fn foo(&self, i: &'self int) -> int {*i} } fn to_foo(t: T) { diff --git a/src/test/compile-fail/kindck-owned-trait.rs b/src/test/compile-fail/kindck-owned-trait.rs index a92a764afe7..af6924ef608 100644 --- a/src/test/compile-fail/kindck-owned-trait.rs +++ b/src/test/compile-fail/kindck-owned-trait.rs @@ -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: T) -> @foo { @t as @foo //~ ERROR value may contain borrowed pointers; use `&static` bound diff --git a/src/test/compile-fail/lint-deprecated-self.rs b/src/test/compile-fail/lint-deprecated-self.rs deleted file mode 100644 index 9da103396d8..00000000000 --- a/src/test/compile-fail/lint-deprecated-self.rs +++ /dev/null @@ -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() { -} - - diff --git a/src/test/compile-fail/map-types.rs b/src/test/compile-fail/map-types.rs index 8b6c6b8410a..486fa63a9aa 100644 --- a/src/test/compile-fail/map-types.rs +++ b/src/test/compile-fail/map-types.rs @@ -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 = @x; //~^ ERROR mismatched types: expected `@core::container::Map` } diff --git a/src/test/compile-fail/mutable-class-fields-2.rs b/src/test/compile-fail/mutable-class-fields-2.rs index 3a63cdee20c..56c715c9847 100644 --- a/src/test/compile-fail/mutable-class-fields-2.rs +++ b/src/test/compile-fail/mutable-class-fields-2.rs @@ -16,7 +16,7 @@ struct cat { } pub impl cat { - fn eat() { + fn eat(&self) { self.how_hungry -= 5; } diff --git a/src/test/compile-fail/private-impl-method.rs b/src/test/compile-fail/private-impl-method.rs index 1ab8d25bb30..74bdcdc7f82 100644 --- a/src/test/compile-fail/private-impl-method.rs +++ b/src/test/compile-fail/private-impl-method.rs @@ -14,7 +14,7 @@ mod a { } pub impl Foo { - priv fn foo() {} + priv fn foo(&self) {} } } diff --git a/src/test/compile-fail/private-method.rs b/src/test/compile-fail/private-method.rs index 363a5fd0d2b..c918758ad7c 100644 --- a/src/test/compile-fail/private-method.rs +++ b/src/test/compile-fail/private-method.rs @@ -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 { diff --git a/src/test/compile-fail/pure-modifies-aliased.rs b/src/test/compile-fail/pure-modifies-aliased.rs index 2aa81dd4fa2..e48b03f694e 100644 --- a/src/test/compile-fail/pure-modifies-aliased.rs +++ b/src/test/compile-fail/pure-modifies-aliased.rs @@ -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 } } diff --git a/src/test/compile-fail/regions-bounds.rs b/src/test/compile-fail/regions-bounds.rs index 92d1aab781c..a136c829165 100644 --- a/src/test/compile-fail/regions-bounds.rs +++ b/src/test/compile-fail/regions-bounds.rs @@ -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 } diff --git a/src/test/compile-fail/regions-escape-via-trait-or-not.rs b/src/test/compile-fail/regions-escape-via-trait-or-not.rs index 767d7c9174d..1b737c273db 100644 --- a/src/test/compile-fail/regions-escape-via-trait-or-not.rs +++ b/src/test/compile-fail/regions-escape-via-trait-or-not.rs @@ -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 } } diff --git a/src/test/compile-fail/regions-infer-paramd-indirect.rs b/src/test/compile-fail/regions-infer-paramd-indirect.rs index 7b2a760270c..600590daded 100644 --- a/src/test/compile-fail/regions-infer-paramd-indirect.rs +++ b/src/test/compile-fail/regions-infer-paramd-indirect.rs @@ -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; } diff --git a/src/test/compile-fail/regions-infer-paramd-method.rs b/src/test/compile-fail/regions-infer-paramd-method.rs index 93d493314fd..5fd3d68d9f3 100644 --- a/src/test/compile-fail/regions-infer-paramd-method.rs +++ b/src/test/compile-fail/regions-infer-paramd-method.rs @@ -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 { diff --git a/src/test/compile-fail/regions-trait-1.rs b/src/test/compile-fail/regions-trait-1.rs index 8104f62595c..74afdf11758 100644 --- a/src/test/compile-fail/regions-trait-1.rs +++ b/src/test/compile-fail/regions-trait-1.rs @@ -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 } diff --git a/src/test/compile-fail/regions-trait-2.rs b/src/test/compile-fail/regions-trait-2.rs index d76bc798705..d6f3a74e3ee 100644 --- a/src/test/compile-fail/regions-trait-2.rs +++ b/src/test/compile-fail/regions-trait-2.rs @@ -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 { diff --git a/src/test/compile-fail/regions-trait-3.rs b/src/test/compile-fail/regions-trait-3.rs index 414d848a966..6bd0b212b96 100644 --- a/src/test/compile-fail/regions-trait-3.rs +++ b/src/test/compile-fail/regions-trait-3.rs @@ -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 { diff --git a/src/test/compile-fail/selftype-traittype.rs b/src/test/compile-fail/selftype-traittype.rs index f704f408662..467154244b7 100644 --- a/src/test/compile-fail/selftype-traittype.rs +++ b/src/test/compile-fail/selftype-traittype.rs @@ -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 { diff --git a/src/test/compile-fail/staticness-mismatch.rs b/src/test/compile-fail/staticness-mismatch.rs index e67a4099987..531d722d8bc 100644 --- a/src/test/compile-fail/staticness-mismatch.rs +++ b/src/test/compile-fail/staticness-mismatch.rs @@ -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() {} diff --git a/src/test/compile-fail/tps-invariant-trait.rs b/src/test/compile-fail/tps-invariant-trait.rs index 1699534216e..a4d39fa829e 100644 --- a/src/test/compile-fail/tps-invariant-trait.rs +++ b/src/test/compile-fail/tps-invariant-trait.rs @@ -9,8 +9,8 @@ // except according to those terms. trait box_trait { - fn get() -> T; - fn set(t: T); + fn get(&self) -> T; + fn set(&self, t: T); } struct box { @@ -20,8 +20,8 @@ struct box { struct box_impl(box); impl box_trait for box_impl { - 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(b: @box_trait<@const T>, v: @const T) { diff --git a/src/test/compile-fail/trait-impl-can-not-have-untraitful-methods.rs b/src/test/compile-fail/trait-impl-can-not-have-untraitful-methods.rs index a20186c362b..1471d9232b2 100644 --- a/src/test/compile-fail/trait-impl-can-not-have-untraitful-methods.rs +++ b/src/test/compile-fail/trait-impl-can-not-have-untraitful-methods.rs @@ -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() { } diff --git a/src/test/compile-fail/trait-impl-different-num-params.rs b/src/test/compile-fail/trait-impl-different-num-params.rs index f32793ad1e4..c1544c2f557 100644 --- a/src/test/compile-fail/trait-impl-different-num-params.rs +++ b/src/test/compile-fail/trait-impl-different-num-params.rs @@ -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 } diff --git a/src/test/compile-fail/trait-or-new-type-instead.rs b/src/test/compile-fail/trait-or-new-type-instead.rs index dc7c7cec65f..a5e37eb949d 100644 --- a/src/test/compile-fail/trait-or-new-type-instead.rs +++ b/src/test/compile-fail/trait-or-new-type-instead.rs @@ -10,7 +10,7 @@ // error-pattern: implement a trait or new type instead pub impl Option { - fn foo() { } + fn foo(&self) { } } fn main() { } diff --git a/src/test/compile-fail/trait-test-2.rs b/src/test/compile-fail/trait-test-2.rs index e63a1dc3563..ebdf354234a 100644 --- a/src/test/compile-fail/trait-test-2.rs +++ b/src/test/compile-fail/trait-test-2.rs @@ -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(); } -impl bar for int { fn dup() -> int { self } fn blah() {} } -impl bar for uint { fn dup() -> uint { self } fn blah() {} } +trait bar { fn dup(&self) -> Self; fn blah(); } +impl bar for int { fn dup(&self) -> int { self } fn blah() {} } +impl bar for uint { fn dup(&self) -> uint { self } fn blah() {} } fn main() { 10i.dup::(); //~ ERROR does not take type parameters diff --git a/src/test/compile-fail/trait-test.rs b/src/test/compile-fail/trait-test.rs index cd92801fb4d..1682e98fb23 100644 --- a/src/test/compile-fail/trait-test.rs +++ b/src/test/compile-fail/trait-test.rs @@ -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() {} diff --git a/src/test/compile-fail/vtable-res-trait-param.rs b/src/test/compile-fail/vtable-res-trait-param.rs index 514448c9644..adcf2021274 100644 --- a/src/test/compile-fail/vtable-res-trait-param.rs +++ b/src/test/compile-fail/vtable-res-trait-param.rs @@ -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: A) -> int; + fn gimme_an_a(&self, a: A) -> int; } impl TraitB for int { - fn gimme_an_a(a: A) -> int { + fn gimme_an_a(&self, a: A) -> int { a.method_a() + self } } diff --git a/src/test/run-fail/unwind-box-trait.rs b/src/test/run-fail/unwind-box-trait.rs index 5c8edb91008..2ed3b39a445 100644 --- a/src/test/run-fail/unwind-box-trait.rs +++ b/src/test/run-fail/unwind-box-trait.rs @@ -15,11 +15,11 @@ fn failfn() { } trait i { - fn foo(); + fn foo(&self); } impl i for ~int { - fn foo() { } + fn foo(&self) { } } fn main() { diff --git a/src/test/run-pass/assignability-trait.rs b/src/test/run-pass/assignability-trait.rs index ae046babfdf..5fecbbe70e4 100644 --- a/src/test/run-pass/assignability-trait.rs +++ b/src/test/run-pass/assignability-trait.rs @@ -13,11 +13,11 @@ // it. trait iterable { - fn iterate(blk: &fn(x: &A) -> bool); + fn iterate(&self, blk: &fn(x: &A) -> bool); } impl iterable 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 iterable for &self/[A] { } impl iterable 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; } } diff --git a/src/test/run-pass/auto-ref.rs b/src/test/run-pass/auto-ref.rs index b6d71fcfb55..82fca3318b1 100644 --- a/src/test/run-pass/auto-ref.rs +++ b/src/test/run-pass/auto-ref.rs @@ -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)); } } diff --git a/src/test/run-pass/autoderef-method-newtype.rs b/src/test/run-pass/autoderef-method-newtype.rs index 732c26694ad..a4dbab49c0c 100644 --- a/src/test/run-pass/autoderef-method-newtype.rs +++ b/src/test/run-pass/autoderef-method-newtype.rs @@ -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); diff --git a/src/test/run-pass/autoderef-method-on-trait.rs b/src/test/run-pass/autoderef-method-on-trait.rs index 3d64c5d0e42..c4e8e168573 100644 --- a/src/test/run-pass/autoderef-method-on-trait.rs +++ b/src/test/run-pass/autoderef-method-on-trait.rs @@ -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() { diff --git a/src/test/run-pass/autoderef-method-priority.rs b/src/test/run-pass/autoderef-method-priority.rs index a3d4e28dec7..ee37781d702 100644 --- a/src/test/run-pass/autoderef-method-priority.rs +++ b/src/test/run-pass/autoderef-method-priority.rs @@ -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() { diff --git a/src/test/run-pass/autoderef-method-twice-but-not-thrice.rs b/src/test/run-pass/autoderef-method-twice-but-not-thrice.rs index 9a6469bbca8..1a49ceb1cde 100644 --- a/src/test/run-pass/autoderef-method-twice-but-not-thrice.rs +++ b/src/test/run-pass/autoderef-method-twice-but-not-thrice.rs @@ -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() { diff --git a/src/test/run-pass/autoderef-method-twice.rs b/src/test/run-pass/autoderef-method-twice.rs index c44ded77ec8..68691d9aa62 100644 --- a/src/test/run-pass/autoderef-method-twice.rs +++ b/src/test/run-pass/autoderef-method-twice.rs @@ -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() { diff --git a/src/test/run-pass/autoderef-method.rs b/src/test/run-pass/autoderef-method.rs index e6b05989903..9721eb9207e 100644 --- a/src/test/run-pass/autoderef-method.rs +++ b/src/test/run-pass/autoderef-method.rs @@ -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() { diff --git a/src/test/run-pass/borrowck-newtype-issue-2573.rs b/src/test/run-pass/borrowck-newtype-issue-2573.rs index 7e81345739f..7724836b5db 100644 --- a/src/test/run-pass/borrowck-newtype-issue-2573.rs +++ b/src/test/run-pass/borrowck-newtype-issue-2573.rs @@ -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); } } diff --git a/src/test/run-pass/boxed-trait-with-vstore.rs b/src/test/run-pass/boxed-trait-with-vstore.rs index 1d2c30108f1..e94525d1691 100644 --- a/src/test/run-pass/boxed-trait-with-vstore.rs +++ b/src/test/run-pass/boxed-trait-with-vstore.rs @@ -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!"); } } diff --git a/src/test/run-pass/class-cast-to-trait-multiple-types.rs b/src/test/run-pass/class-cast-to-trait-multiple-types.rs index 50a3d5cc617..eefa78cc3c9 100644 --- a/src/test/run-pass/class-cast-to-trait-multiple-types.rs +++ b/src/test/run-pass/class-cast-to-trait-multiple-types.rs @@ -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 { diff --git a/src/test/run-pass/class-exports.rs b/src/test/run-pass/class-exports.rs index 85cbbcc23a3..aa5bb2b519c 100644 --- a/src/test/run-pass/class-exports.rs +++ b/src/test/run-pass/class-exports.rs @@ -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 diff --git a/src/test/run-pass/conditional-compile.rs b/src/test/run-pass/conditional-compile.rs index fa6f59999f8..3a626ca6ac1 100644 --- a/src/test/run-pass/conditional-compile.rs +++ b/src/test/run-pass/conditional-compile.rs @@ -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); } } diff --git a/src/test/run-pass/default-method-simple.rs b/src/test/run-pass/default-method-simple.rs index 4e17506d6ea..62b29d4e4eb 100644 --- a/src/test/run-pass/default-method-simple.rs +++ b/src/test/run-pass/default-method-simple.rs @@ -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!"); } } diff --git a/src/test/run-pass/early-vtbl-resolution.rs b/src/test/run-pass/early-vtbl-resolution.rs index 0191934d608..4728f718463 100644 --- a/src/test/run-pass/early-vtbl-resolution.rs +++ b/src/test/run-pass/early-vtbl-resolution.rs @@ -10,10 +10,10 @@ trait thing { - fn foo() -> Option; + fn foo(&self) -> Option; } impl thing for int { - fn foo() -> Option { None } + fn foo(&self) -> Option { None } } fn foo_func>(x: B) -> Option { x.foo() } diff --git a/src/test/run-pass/generic-object.rs b/src/test/run-pass/generic-object.rs index 60e1c1a7c37..acdd3fc4600 100644 --- a/src/test/run-pass/generic-object.rs +++ b/src/test/run-pass/generic-object.rs @@ -9,7 +9,7 @@ // except according to those terms. trait Foo { - fn get() -> T; + fn get(&self) -> T; } struct S { @@ -17,7 +17,7 @@ struct S { } impl Foo for S { - fn get() -> int { + fn get(&self) -> int { self.x } } diff --git a/src/test/run-pass/impl-implicit-trait.rs b/src/test/run-pass/impl-implicit-trait.rs index 88e220670ba..10a5661a324 100644 --- a/src/test/run-pass/impl-implicit-trait.rs +++ b/src/test/run-pass/impl-implicit-trait.rs @@ -14,7 +14,7 @@ enum option_ { } pub impl option_ { - 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() { diff --git a/src/test/run-pass/impl-variance.rs b/src/test/run-pass/impl-variance.rs index d772b76108e..849aa2a29f4 100644 --- a/src/test/run-pass/impl-variance.rs +++ b/src/test/run-pass/impl-variance.rs @@ -9,11 +9,11 @@ // except according to those terms. trait foo { - fn foo() -> uint; + fn foo(&self) -> uint; } impl foo for ~[const T] { - fn foo() -> uint { vec::len(self) } + fn foo(&self) -> uint { vec::len(self) } } pub fn main() { diff --git a/src/test/run-pass/issue-2284.rs b/src/test/run-pass/issue-2284.rs index ebf7eec470c..6dda45a99f9 100644 --- a/src/test/run-pass/issue-2284.rs +++ b/src/test/run-pass/issue-2284.rs @@ -9,11 +9,11 @@ // except according to those terms. trait Send { - fn f(); + fn f(&self); } fn f(t: T) { - t.f(); + t.f(&self); } pub fn main() { diff --git a/src/test/run-pass/issue-2288.rs b/src/test/run-pass/issue-2288.rs index fe32af7b15f..9dcee06ba85 100644 --- a/src/test/run-pass/issue-2288.rs +++ b/src/test/run-pass/issue-2288.rs @@ -9,14 +9,14 @@ // except according to those terms. trait c lam { - fn chowder(y: A); + fn chowder(&self, y: A); } struct foo { x: A, } impl clam for foo { - fn chowder(y: A) { + fn chowder(&self, y: A) { } } diff --git a/src/test/run-pass/issue-2311-2.rs b/src/test/run-pass/issue-2311-2.rs index f60db84eb86..5f47e7ccb9f 100644 --- a/src/test/run-pass/issue-2311-2.rs +++ b/src/test/run-pass/issue-2311-2.rs @@ -14,7 +14,7 @@ struct foo { } pub impl foo { - fn bar>(c: C) -> B { + fn bar>(&self, c: C) -> B { fail!(); } } diff --git a/src/test/run-pass/issue-2311.rs b/src/test/run-pass/issue-2311.rs index f3ced02c122..dc873ed08d7 100644 --- a/src/test/run-pass/issue-2311.rs +++ b/src/test/run-pass/issue-2311.rs @@ -10,7 +10,7 @@ trait clam { } trait foo { - fn bar>(c: C) -> B; + fn bar>(&self, c: C) -> B; } pub fn main() { } diff --git a/src/test/run-pass/issue-2312.rs b/src/test/run-pass/issue-2312.rs index ad6320aed2b..f3aa96298f0 100644 --- a/src/test/run-pass/issue-2312.rs +++ b/src/test/run-pass/issue-2312.rs @@ -15,7 +15,7 @@ trait clam { } struct foo(int); pub impl foo { - fn bar>(c: C) -> B { fail!(); } + fn bar>(&self, c: C) -> B { fail!(); } } pub fn main() { } diff --git a/src/test/run-pass/issue-2445-b.rs b/src/test/run-pass/issue-2445-b.rs index 73bf97ad7af..55c72a41a6a 100644 --- a/src/test/run-pass/issue-2445-b.rs +++ b/src/test/run-pass/issue-2445-b.rs @@ -13,7 +13,7 @@ struct c1 { } pub impl c1 { - fn f1(x: int) { + fn f1(&self, x: int) { } } @@ -24,7 +24,7 @@ fn c1(x: T) -> c1 { } pub impl c1 { - fn f2(x: int) { + fn f2(&self, x: int) { } } diff --git a/src/test/run-pass/issue-2445.rs b/src/test/run-pass/issue-2445.rs index 973b8d85161..5a82b534015 100644 --- a/src/test/run-pass/issue-2445.rs +++ b/src/test/run-pass/issue-2445.rs @@ -13,7 +13,7 @@ struct c1 { } pub impl c1 { - fn f1(x: T) {} + fn f1(&self, x: T) {} } fn c1(x: T) -> c1 { @@ -23,7 +23,7 @@ fn c1(x: T) -> c1 { } pub impl c1 { - fn f2(x: T) {} + fn f2(&self, x: T) {} } diff --git a/src/test/run-pass/issue-2487-a.rs b/src/test/run-pass/issue-2487-a.rs index 138860ce72d..59986638088 100644 --- a/src/test/run-pass/issue-2487-a.rs +++ b/src/test/run-pass/issue-2487-a.rs @@ -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) } diff --git a/src/test/run-pass/issue-2502.rs b/src/test/run-pass/issue-2502.rs index c7a7dc53965..9af41e48aa2 100644 --- a/src/test/run-pass/issue-2502.rs +++ b/src/test/run-pass/issue-2502.rs @@ -13,7 +13,7 @@ struct font { } pub impl font/&self { - fn buf() -> &self/~[u8] { + fn buf(&self) -> &self/~[u8] { self.fontbuf } } diff --git a/src/test/run-pass/issue-2734.rs b/src/test/run-pass/issue-2734.rs index a76d2242b40..35c3d6a88ee 100644 --- a/src/test/run-pass/issue-2734.rs +++ b/src/test/run-pass/issue-2734.rs @@ -11,7 +11,7 @@ trait hax { } impl hax for A { } -fn perform_hax(x: @T) -> hax { +fn perform_hax(x: @T) -> @hax { @x as @hax } diff --git a/src/test/run-pass/issue-2935.rs b/src/test/run-pass/issue-2935.rs index 323b5d8ed5a..c1f4e1e49aa 100644 --- a/src/test/run-pass/issue-2935.rs +++ b/src/test/run-pass/issue-2935.rs @@ -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() { diff --git a/src/test/run-pass/issue-2936.rs b/src/test/run-pass/issue-2936.rs index 2e343e9afe6..5acae2da1ce 100644 --- a/src/test/run-pass/issue-2936.rs +++ b/src/test/run-pass/issue-2936.rs @@ -9,7 +9,7 @@ // except according to those terms. trait bar { - fn get_bar() -> T; + fn get_bar(&self) -> T; } fn foo>(b: U) -> T { @@ -21,7 +21,7 @@ struct cbar { } impl bar for cbar { - fn get_bar() -> int { + fn get_bar(&self) -> int { self.x } } diff --git a/src/test/run-pass/issue-2989.rs b/src/test/run-pass/issue-2989.rs index 72af21368f1..10b845a923d 100644 --- a/src/test/run-pass/issue-2989.rs +++ b/src/test/run-pass/issue-2989.rs @@ -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) } } diff --git a/src/test/run-pass/issue-3563-2.rs b/src/test/run-pass/issue-3563-2.rs index 332127d0204..52d6792f401 100644 --- a/src/test/run-pass/issue-3563-2.rs +++ b/src/test/run-pass/issue-3563-2.rs @@ -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) } diff --git a/src/test/run-pass/issue-3683.rs b/src/test/run-pass/issue-3683.rs index 79e205d262a..edbc7852542 100644 --- a/src/test/run-pass/issue-3683.rs +++ b/src/test/run-pass/issue-3683.rs @@ -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 } } diff --git a/src/test/run-pass/issue-3753.rs b/src/test/run-pass/issue-3753.rs index 920736a976e..948ff1afd81 100644 --- a/src/test/run-pass/issue-3753.rs +++ b/src/test/run-pass/issue-3753.rs @@ -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) diff --git a/src/test/run-pass/kindck-owned-trait-contains-1.rs b/src/test/run-pass/kindck-owned-trait-contains-1.rs index 75b0a633552..7beb4881d7a 100644 --- a/src/test/run-pass/kindck-owned-trait-contains-1.rs +++ b/src/test/run-pass/kindck-owned-trait-contains-1.rs @@ -8,10 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -trait repeat { fn get() -> A; } +trait repeat { fn get(&self) -> A; } impl repeat for @A { - fn get() -> A { *self } + fn get(&self) -> A { *self } } fn repeater(v: @A) -> @repeat { diff --git a/src/test/run-pass/max-min-classes.rs b/src/test/run-pass/max-min-classes.rs index 56c16d92874..58dcb24edf9 100644 --- a/src/test/run-pass/max-min-classes.rs +++ b/src/test/run-pass/max-min-classes.rs @@ -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 } } diff --git a/src/test/run-pass/method-attributes.rs b/src/test/run-pass/method-attributes.rs index 20cd9643b08..db7440738da 100644 --- a/src/test/run-pass/method-attributes.rs +++ b/src/test/run-pass/method-attributes.rs @@ -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]; } } diff --git a/src/test/run-pass/monad.rs b/src/test/run-pass/monad.rs index b21b3b6c7fb..9b864257d4b 100644 --- a/src/test/run-pass/monad.rs +++ b/src/test/run-pass/monad.rs @@ -11,11 +11,11 @@ // xfail-fast trait vec_monad { - fn bind(f: &fn(&A) -> ~[B]) -> ~[B]; + fn bind(&self, f: &fn(&A) -> ~[B]) -> ~[B]; } impl vec_monad for ~[A] { - fn bind(f: &fn(&A) -> ~[B]) -> ~[B] { + fn bind(&self, f: &fn(&A) -> ~[B]) -> ~[B] { let mut r = ~[]; for self.each |elt| { r += f(elt); } r @@ -23,11 +23,11 @@ impl vec_monad for ~[A] { } trait option_monad { - fn bind(f: &fn(&A) -> Option) -> Option; + fn bind(&self, f: &fn(&A) -> Option) -> Option; } impl option_monad for Option { - fn bind(f: &fn(&A) -> Option) -> Option { + fn bind(&self, f: &fn(&A) -> Option) -> Option { match self { Some(ref a) => { f(a) } None => { None } diff --git a/src/test/run-pass/monomorphize-trait-in-fn-at.rs b/src/test/run-pass/monomorphize-trait-in-fn-at.rs index 6e5d92da1cb..a591c3034d2 100644 --- a/src/test/run-pass/monomorphize-trait-in-fn-at.rs +++ b/src/test/run-pass/monomorphize-trait-in-fn-at.rs @@ -17,11 +17,11 @@ fn mk_nil(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() { diff --git a/src/test/run-pass/monomorphized-callees-with-ty-params-3314.rs b/src/test/run-pass/monomorphized-callees-with-ty-params-3314.rs index ecf30b206c5..90b3e623f5e 100644 --- a/src/test/run-pass/monomorphized-callees-with-ty-params-3314.rs +++ b/src/test/run-pass/monomorphized-callees-with-ty-params-3314.rs @@ -14,17 +14,17 @@ trait Serializer { } trait Serializable { - fn serialize(s: S); + fn serialize(&self, s: S); } impl Serializable for int { - fn serialize(_s: S) { } + fn serialize(&self, _s: S) { } } struct F { a: A } impl Serializable for F { - fn serialize(s: S) { + fn serialize(&self, s: S) { self.a.serialize(s); } } diff --git a/src/test/run-pass/nested-class.rs b/src/test/run-pass/nested-class.rs index eeda69e621d..6447d46ad89 100644 --- a/src/test/run-pass/nested-class.rs +++ b/src/test/run-pass/nested-class.rs @@ -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 { diff --git a/src/test/run-pass/rcvr-borrowed-to-region.rs b/src/test/run-pass/rcvr-borrowed-to-region.rs index a7daa566480..3f02af3f71c 100644 --- a/src/test/run-pass/rcvr-borrowed-to-region.rs +++ b/src/test/run-pass/rcvr-borrowed-to-region.rs @@ -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; } } diff --git a/src/test/run-pass/rcvr-borrowed-to-slice.rs b/src/test/run-pass/rcvr-borrowed-to-slice.rs index f7f6b9b05e3..9328189c47c 100644 --- a/src/test/run-pass/rcvr-borrowed-to-slice.rs +++ b/src/test/run-pass/rcvr-borrowed-to-slice.rs @@ -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; diff --git a/src/test/run-pass/reflect-visit-data.rs b/src/test/run-pass/reflect-visit-data.rs index 0f3f4db3bbf..5b3ba0d45ed 100644 --- a/src/test/run-pass/reflect-visit-data.rs +++ b/src/test/run-pass/reflect-visit-data.rs @@ -19,7 +19,7 @@ use intrinsic::{TyDesc, get_tydesc, visit_tydesc, TyVisitor}; /// Trait for visitor that wishes to reflect on data. trait movable_ptr { - fn move_ptr(adjustment: &fn(*c_void) -> *c_void); + fn move_ptr(&self, adjustment: &fn(*c_void) -> *c_void); } /// Helper function for alignment calculation. @@ -33,26 +33,26 @@ struct ptr_visit_adaptor(Inner); pub impl ptr_visit_adaptor { #[inline(always)] - fn bump(sz: uint) { + fn bump(&self, sz: uint) { do self.inner.move_ptr() |p| { ((p as uint) + sz) as *c_void }; } #[inline(always)] - fn align(a: uint) { + fn align(&self, a: uint) { do self.inner.move_ptr() |p| { align(p as uint, a) as *c_void }; } #[inline(always)] - fn align_to() { + fn align_to(&self) { self.align(sys::min_align_of::()); } #[inline(always)] - fn bump_past() { + fn bump_past(&self) { self.bump(sys::size_of::()); } @@ -479,13 +479,13 @@ struct Stuff { } pub impl my_visitor { - fn get(f: &fn(T)) { + fn get(&self, f: &fn(T)) { unsafe { f(*(self.ptr1 as *T)); } } - fn visit_inner(inner: *TyDesc) -> bool { + fn visit_inner(&self, inner: *TyDesc) -> bool { unsafe { let u = my_visitor(*self); let v = ptr_visit_adaptor::(Inner {inner: u}); @@ -498,7 +498,7 @@ pub impl my_visitor { struct Inner { inner: V } impl movable_ptr for my_visitor { - fn move_ptr(adjustment: &fn(*c_void) -> *c_void) { + fn move_ptr(&self, adjustment: &fn(*c_void) -> *c_void) { self.ptr1 = adjustment(self.ptr1); self.ptr2 = adjustment(self.ptr2); } diff --git a/src/test/run-pass/regions-self-impls.rs b/src/test/run-pass/regions-self-impls.rs index 6b5634fbd50..2f4eefe5243 100644 --- a/src/test/run-pass/regions-self-impls.rs +++ b/src/test/run-pass/regions-self-impls.rs @@ -13,11 +13,11 @@ struct Clam<'self> { } trait get_chowder<'self> { - fn get_chowder() -> &'self int; + fn get_chowder(&self) -> &'self int; } impl<'self> get_chowder<'self> for Clam<'self> { - fn get_chowder() -> &'self int { return self.chowder; } + fn get_chowder(&self) -> &'self int { return self.chowder; } } pub fn main() { diff --git a/src/test/run-pass/regions-trait.rs b/src/test/run-pass/regions-trait.rs index cc12c1b7dd9..db8cfd1a865 100644 --- a/src/test/run-pass/regions-trait.rs +++ b/src/test/run-pass/regions-trait.rs @@ -11,13 +11,13 @@ struct Ctxt { v: uint } trait get_ctxt { - fn get_ctxt() -> &self/Ctxt; + fn get_ctxt(&self) -> &self/Ctxt; } struct HasCtxt { c: &'self Ctxt } impl get_ctxt<'self> for HasCtxt<'self> { - fn get_ctxt() -> &self/Ctxt { + fn get_ctxt(&self) -> &self/Ctxt { self.c } } diff --git a/src/test/run-pass/resource-destruct.rs b/src/test/run-pass/resource-destruct.rs index 074415375dc..db444f08fab 100644 --- a/src/test/run-pass/resource-destruct.rs +++ b/src/test/run-pass/resource-destruct.rs @@ -19,7 +19,7 @@ impl Drop for shrinky_pointer { } pub impl shrinky_pointer { - fn look_at() -> int { return **(self.i); } + fn look_at(&self) -> int { return **(self.i); } } fn shrinky_pointer(i: @@mut int) -> shrinky_pointer { diff --git a/src/test/run-pass/static-impl.rs b/src/test/run-pass/static-impl.rs index 2ee6f631ea5..fe5a6bd2bd5 100644 --- a/src/test/run-pass/static-impl.rs +++ b/src/test/run-pass/static-impl.rs @@ -11,42 +11,42 @@ // xfail-fast pub trait plus { - fn plus() -> int; + fn plus(&self) -> int; } mod a { use plus; - impl plus for uint { fn plus() -> int { self as int + 20 } } + impl plus for uint { fn plus(&self) -> int { self as int + 20 } } } mod b { use plus; - impl plus for ~str { fn plus() -> int { 200 } } + impl plus for ~str { fn plus(&self) -> int { 200 } } } trait uint_utils { - fn str() -> ~str; - fn multi(f: &fn(uint)); + fn str(self) -> ~str; + fn multi(self, f: &fn(uint)); } impl uint_utils for uint { - fn str() -> ~str { uint::to_str(self) } - fn multi(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; } } } trait vec_utils { - fn length_() -> uint; - fn iter_(f: &fn(&T)); - fn map_(f: &fn(&T) -> U) -> ~[U]; + fn length_(&self, ) -> uint; + fn iter_(&self, f: &fn(&T)); + fn map_(&self, f: &fn(&T) -> U) -> ~[U]; } impl vec_utils for ~[T] { - fn length_() -> uint { vec::len(self) } - fn iter_(f: &fn(&T)) { for self.each |x| { f(x); } } - fn map_(f: &fn(&T) -> U) -> ~[U] { + fn length_(&self) -> uint { vec::len(self) } + fn iter_(&self, f: &fn(&T)) { for self.each |x| { f(x); } } + fn map_(&self, f: &fn(&T) -> U) -> ~[U] { let mut r = ~[]; for self.each |elt| { r += ~[f(elt)]; } r diff --git a/src/test/run-pass/static-method-in-trait-with-tps-intracrate.rs b/src/test/run-pass/static-method-in-trait-with-tps-intracrate.rs index f51eb6e1ae2..1146412ec4f 100644 --- a/src/test/run-pass/static-method-in-trait-with-tps-intracrate.rs +++ b/src/test/run-pass/static-method-in-trait-with-tps-intracrate.rs @@ -9,15 +9,15 @@ // except according to those terms. trait Deserializer { - fn read_int() -> int; + fn read_int(&self) -> int; } trait Deserializable { - static fn deserialize(d: &D) -> Self; + static fn deserialize(&self, d: &D) -> Self; } impl Deserializable for int { - static fn deserialize(d: &D) -> int { + static fn deserialize(&self, d: &D) -> int { return d.read_int(); } } @@ -25,7 +25,7 @@ impl Deserializable for int { struct FromThinAir { dummy: () } impl Deserializer for FromThinAir { - fn read_int() -> int { 22 } + fn read_int(&self) -> int { 22 } } pub fn main() { diff --git a/src/test/run-pass/trait-bounds.rs b/src/test/run-pass/trait-bounds.rs index a07e5c6cf3f..6dcd2a41e07 100644 --- a/src/test/run-pass/trait-bounds.rs +++ b/src/test/run-pass/trait-bounds.rs @@ -9,22 +9,22 @@ // except according to those terms. trait connection { - fn read() -> int; + fn read(&self) -> int; } trait connection_factory { - fn create() -> C; + fn create(&self) -> C; } type my_connection = (); type my_connection_factory = (); impl connection for () { - fn read() -> int { 43 } + fn read(&self) -> int { 43 } } impl connection_factory for my_connection_factory { - fn create() -> my_connection { () } + fn create(&self) -> my_connection { () } } pub fn main() { diff --git a/src/test/run-pass/trait-composition-trivial.rs b/src/test/run-pass/trait-composition-trivial.rs index 56645b48218..328c0b6888c 100644 --- a/src/test/run-pass/trait-composition-trivial.rs +++ b/src/test/run-pass/trait-composition-trivial.rs @@ -9,11 +9,11 @@ // except according to those terms. trait Foo { - fn foo(); + fn foo(&self); } trait Bar : Foo { - fn bar(); + fn bar(&self); } pub fn main() {} diff --git a/src/test/run-pass/trait-default-method-bound-subst2.rs b/src/test/run-pass/trait-default-method-bound-subst2.rs index cba45c6bb23..ce72c7e9a44 100644 --- a/src/test/run-pass/trait-default-method-bound-subst2.rs +++ b/src/test/run-pass/trait-default-method-bound-subst2.rs @@ -11,7 +11,7 @@ // xfail-test trait A { - fn g(x: T) -> T { x } + fn g(&self, x: T) -> T { x } } impl A for int { } diff --git a/src/test/run-pass/trait-default-method-bound-subst3.rs b/src/test/run-pass/trait-default-method-bound-subst3.rs index 5a9b4fbb9e6..3c1e6a59d03 100644 --- a/src/test/run-pass/trait-default-method-bound-subst3.rs +++ b/src/test/run-pass/trait-default-method-bound-subst3.rs @@ -11,7 +11,7 @@ #[allow(default_methods)]; trait A { - fn g(x: T, y: T) -> (T, T) { (x, y) } + fn g(&self, x: T, y: T) -> (T, T) { (x, y) } } impl A for int { } diff --git a/src/test/run-pass/trait-default-method-bound-subst4.rs b/src/test/run-pass/trait-default-method-bound-subst4.rs index ee0feafa5c1..9ac66bfb737 100644 --- a/src/test/run-pass/trait-default-method-bound-subst4.rs +++ b/src/test/run-pass/trait-default-method-bound-subst4.rs @@ -11,7 +11,7 @@ #[allow(default_methods)]; trait A { - fn g(x: uint) -> uint { x } + fn g(&self, x: uint) -> uint { x } } impl A for int { } diff --git a/src/test/run-pass/trait-default-method-bound.rs b/src/test/run-pass/trait-default-method-bound.rs index 4c2c030eaab..627bc96e6ae 100644 --- a/src/test/run-pass/trait-default-method-bound.rs +++ b/src/test/run-pass/trait-default-method-bound.rs @@ -11,7 +11,7 @@ #[allow(default_methods)]; trait A { - fn g() -> int { 10 } + fn g(&self) -> int { 10 } } impl A for int { } diff --git a/src/test/run-pass/trait-generic.rs b/src/test/run-pass/trait-generic.rs index 7b8ebe6d34c..85e706c9fe5 100644 --- a/src/test/run-pass/trait-generic.rs +++ b/src/test/run-pass/trait-generic.rs @@ -11,23 +11,23 @@ // xfail-fast trait to_str { - fn to_str() -> ~str; + fn to_str(&self) -> ~str; } impl to_str for int { - fn to_str() -> ~str { int::to_str(self) } + fn to_str(&self) -> ~str { int::to_str(self) } } impl to_str for ~str { - fn to_str() -> ~str { copy self } + fn to_str(&self) -> ~str { copy self } } impl to_str for () { - fn to_str() -> ~str { ~"()" } + fn to_str(&self) -> ~str { ~"()" } } trait map { - fn map(f: &fn(&T) -> U) -> ~[U]; + fn map(&self, f: &fn(&T) -> U) -> ~[U]; } impl map for ~[T] { - fn map(f: &fn(&T) -> U) -> ~[U] { + fn map(&self, f: &fn(&T) -> U) -> ~[U] { let mut r = ~[]; for self.each |x| { r += ~[f(x)]; } r diff --git a/src/test/run-pass/trait-inheritance-auto.rs b/src/test/run-pass/trait-inheritance-auto.rs index efc4cfa6156..51a3168f6e8 100644 --- a/src/test/run-pass/trait-inheritance-auto.rs +++ b/src/test/run-pass/trait-inheritance-auto.rs @@ -12,17 +12,17 @@ // A is already a Foo Bar Baz impl Quux for T { } -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 { } 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(a: &T) { fail_unless!(a.f() == 10); diff --git a/src/test/run-pass/trait-inheritance-call-bound-inherited.rs b/src/test/run-pass/trait-inheritance-call-bound-inherited.rs index 75dea9c500a..dcc1deed846 100644 --- a/src/test/run-pass/trait-inheritance-call-bound-inherited.rs +++ b/src/test/run-pass/trait-inheritance-call-bound-inherited.rs @@ -8,13 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -trait Foo { fn f() -> int; } -trait Bar : Foo { fn g() -> int; } +trait Foo { fn f(&self) -> int; } +trait Bar : Foo { fn g(&self) -> int; } struct A { x: int } -impl Foo for A { fn f() -> int { 10 } } -impl Bar for A { fn g() -> int { 20 } } +impl Foo for A { fn f(&self) -> int { 10 } } +impl Bar for A { fn g(&self) -> int { 20 } } // Call a function on Foo, given a T: Bar fn gg(a: &T) -> int { diff --git a/src/test/run-pass/trait-inheritance-call-bound-inherited2.rs b/src/test/run-pass/trait-inheritance-call-bound-inherited2.rs index e8d553dae18..ad23cab016e 100644 --- a/src/test/run-pass/trait-inheritance-call-bound-inherited2.rs +++ b/src/test/run-pass/trait-inheritance-call-bound-inherited2.rs @@ -8,15 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -trait Foo { fn f() -> int; } -trait Bar : Foo { fn g() -> int; } -trait Baz : Bar { fn h() -> int; } +trait Foo { fn f(&self) -> int; } +trait Bar : Foo { fn g(&self) -> int; } +trait Baz : Bar { fn h(&self) -> int; } 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 } } // Call a function on Foo, given a T: Baz, // which is inherited via Bar diff --git a/src/test/run-pass/trait-inheritance-cast-without-call-to-supertrait.rs b/src/test/run-pass/trait-inheritance-cast-without-call-to-supertrait.rs index 3447cbad84a..39565382118 100644 --- a/src/test/run-pass/trait-inheritance-cast-without-call-to-supertrait.rs +++ b/src/test/run-pass/trait-inheritance-cast-without-call-to-supertrait.rs @@ -12,11 +12,11 @@ // methods. Not testing supertrait methods trait Foo { - fn f() -> int; + fn f(&self) -> int; } trait Bar : Foo { - fn g() -> int; + fn g(&self) -> int; } struct A { @@ -24,11 +24,11 @@ struct A { } impl Foo for A { - fn f() -> int { 10 } + fn f(&self) -> int { 10 } } impl Bar for A { - fn g() -> int { 20 } + fn g(&self) -> int { 20 } } pub fn main() { diff --git a/src/test/run-pass/trait-inheritance-cross-trait-call.rs b/src/test/run-pass/trait-inheritance-cross-trait-call.rs index 47b5f60233b..2cde60ecf58 100644 --- a/src/test/run-pass/trait-inheritance-cross-trait-call.rs +++ b/src/test/run-pass/trait-inheritance-cross-trait-call.rs @@ -8,16 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -trait Foo { fn f() -> int; } -trait Bar : Foo { fn g() -> int; } +trait Foo { fn f(&self) -> int; } +trait Bar : Foo { fn g(&self) -> int; } 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 { // Testing that this impl can call the impl of Foo - fn g() -> int { self.f() } + fn g(&self) -> int { self.f() } } pub fn main() { diff --git a/src/test/run-pass/trait-inheritance-simple.rs b/src/test/run-pass/trait-inheritance-simple.rs index f56a50f1430..9ca3ccaa22c 100644 --- a/src/test/run-pass/trait-inheritance-simple.rs +++ b/src/test/run-pass/trait-inheritance-simple.rs @@ -8,13 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -trait Foo { fn f() -> int; } -trait Bar : Foo { fn g() -> int; } +trait Foo { fn f(&self) -> int; } +trait Bar : Foo { fn g(&self) -> int; } struct A { x: int } -impl Foo for A { fn f() -> int { 10 } } -impl Bar for A { fn g() -> int { 20 } } +impl Foo for A { fn f(&self) -> int { 10 } } +impl Bar for A { fn g(&self) -> int { 20 } } fn ff(a: &T) -> int { a.f() diff --git a/src/test/run-pass/trait-inheritance-subst.rs b/src/test/run-pass/trait-inheritance-subst.rs index 5900805e957..c1ee7a2c00a 100644 --- a/src/test/run-pass/trait-inheritance-subst.rs +++ b/src/test/run-pass/trait-inheritance-subst.rs @@ -9,7 +9,7 @@ // except according to those terms. pub trait Add { - pure fn add(rhs: &RHS) -> Result; + pure fn add(&self, rhs: &RHS) -> Result; } trait MyNum : Add { } @@ -17,7 +17,7 @@ trait MyNum : Add { } struct MyInt { val: int } impl Add for MyInt { - pure fn add(other: &MyInt) -> MyInt { mi(self.val + other.val) } + pure fn add(&self, other: &MyInt) -> MyInt { mi(self.val + other.val) } } impl MyNum for MyInt; diff --git a/src/test/run-pass/trait-inheritance-subst2.rs b/src/test/run-pass/trait-inheritance-subst2.rs index 77e15a802e4..20b7d529fae 100644 --- a/src/test/run-pass/trait-inheritance-subst2.rs +++ b/src/test/run-pass/trait-inheritance-subst2.rs @@ -9,11 +9,11 @@ // except according to those terms. trait Panda { - fn chomp(bamboo: &T) -> T; + fn chomp(&self, bamboo: &T) -> T; } trait Add: Panda { - fn add(rhs: &RHS) -> Result; + fn add(&self, rhs: &RHS) -> Result; } trait MyNum : Add { } @@ -21,13 +21,13 @@ trait MyNum : Add { } struct MyInt { val: int } impl Panda for MyInt { - fn chomp(bamboo: &MyInt) -> MyInt { + fn chomp(&self, bamboo: &MyInt) -> MyInt { mi(self.val + bamboo.val) } } impl Add for MyInt { - fn add(other: &MyInt) -> MyInt { self.chomp(other) } + fn add(&self, other: &MyInt) -> MyInt { self.chomp(other) } } impl MyNum for MyInt; diff --git a/src/test/run-pass/trait-inheritance-visibility.rs b/src/test/run-pass/trait-inheritance-visibility.rs index 861e9c0c84a..c70c2ecf976 100644 --- a/src/test/run-pass/trait-inheritance-visibility.rs +++ b/src/test/run-pass/trait-inheritance-visibility.rs @@ -9,9 +9,9 @@ // except according to those terms. mod traits { - pub trait Foo { fn f() -> int; } + pub trait Foo { fn f(&self) -> int; } - impl Foo for int { fn f() -> int { 10 } } + impl Foo for int { fn f(&self) -> int { 10 } } } trait Quux: traits::Foo { } diff --git a/src/test/run-pass/trait-inheritance2.rs b/src/test/run-pass/trait-inheritance2.rs index 78e3b43730e..d18452f11fa 100644 --- a/src/test/run-pass/trait-inheritance2.rs +++ b/src/test/run-pass/trait-inheritance2.rs @@ -8,17 +8,17 @@ // 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 { } 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 } } impl Quux for A; fn f(a: &T) { diff --git a/src/test/run-pass/trait-region-pointer-simple.rs b/src/test/run-pass/trait-region-pointer-simple.rs index d55ca35fff2..1ce2cddc29b 100644 --- a/src/test/run-pass/trait-region-pointer-simple.rs +++ b/src/test/run-pass/trait-region-pointer-simple.rs @@ -9,7 +9,7 @@ // except according to those terms. trait Foo { - fn f() -> int; + fn f(&self) -> int; } struct A { @@ -17,7 +17,7 @@ struct A { } impl Foo for A { - fn f() -> int { + fn f(&self) -> int { io::println(~"Today's number is " + self.x.to_str()); return self.x; } diff --git a/src/test/run-pass/trait-to-str.rs b/src/test/run-pass/trait-to-str.rs index 29de9d1df81..d5e1a1f2120 100644 --- a/src/test/run-pass/trait-to-str.rs +++ b/src/test/run-pass/trait-to-str.rs @@ -17,15 +17,15 @@ extern mod core; use core::{str, int, vec}; trait to_str { - fn to_str() -> ~str; + fn to_str(&self) -> ~str; } impl to_str for int { - fn to_str() -> ~str { int::to_str(self) } + fn to_str(&self) -> ~str { int::to_str(self) } } impl to_str for ~[T] { - fn to_str() -> ~str { + fn to_str(&self) -> ~str { ~"[" + str::connect(vec::map(self, |e| e.to_str() ), ~", ") + ~"]" } } diff --git a/src/test/run-pass/traits-default-method-macro.rs b/src/test/run-pass/traits-default-method-macro.rs index f3f20cc50be..21e05aba27b 100644 --- a/src/test/run-pass/traits-default-method-macro.rs +++ b/src/test/run-pass/traits-default-method-macro.rs @@ -11,7 +11,7 @@ #[allow(default_methods)]; trait Foo { - fn bar() -> ~str { + fn bar(&self) -> ~str { fmt!("test") } } diff --git a/src/test/run-pass/traits-default-method-trivial.rs b/src/test/run-pass/traits-default-method-trivial.rs index fbfce37242d..8edb83ce60e 100644 --- a/src/test/run-pass/traits-default-method-trivial.rs +++ b/src/test/run-pass/traits-default-method-trivial.rs @@ -11,16 +11,16 @@ #[allow(default_methods)]; trait Cat { - fn meow() -> bool; - fn scratch() -> bool; - fn purr() -> bool { true } + fn meow(&self) -> bool; + fn scratch(&self) -> bool; + fn purr(&self) -> bool { true } } impl Cat for int { - fn meow() -> bool { + fn meow(&self) -> bool { self.scratch() } - fn scratch() -> bool { + fn scratch(&self) -> bool { self.purr() } } diff --git a/src/test/run-pass/typeclasses-eq-example.rs b/src/test/run-pass/typeclasses-eq-example.rs index 87a62f81e6d..56b03bc4489 100644 --- a/src/test/run-pass/typeclasses-eq-example.rs +++ b/src/test/run-pass/typeclasses-eq-example.rs @@ -11,13 +11,13 @@ // Example from lkuper's intern talk, August 2012. trait Equal { - fn isEq(a: Self) -> bool; + fn isEq(&self, a: Self) -> bool; } enum Color { cyan, magenta, yellow, black } impl Equal for Color { - fn isEq(a: Color) -> bool { + fn isEq(&self, a: Color) -> bool { match (self, a) { (cyan, cyan) => { true } (magenta, magenta) => { true } @@ -34,7 +34,7 @@ enum ColorTree { } impl Equal for ColorTree { - fn isEq(a: ColorTree) -> bool { + fn isEq(&self, a: ColorTree) -> bool { match (self, a) { (leaf(x), leaf(y)) => { x.isEq(y) } (branch(l1, r1), branch(l2, r2)) => { diff --git a/src/test/run-pass/use-trait-before-def.rs b/src/test/run-pass/use-trait-before-def.rs index 1bd68bfa4b6..0b59ced98c9 100644 --- a/src/test/run-pass/use-trait-before-def.rs +++ b/src/test/run-pass/use-trait-before-def.rs @@ -10,6 +10,6 @@ // Issue #1761 -impl foo for int { fn foo() -> int { 10 } } -trait foo { fn foo() -> int; } +impl foo for int { fn foo(&self) -> int { 10 } } +trait foo { fn foo(&self) -> int; } pub fn main() {}