Skip to content

Commit 8fa66e8

Browse files
committed
librustc: Remove implicit self from the language, except for old-style drop blocks.
1 parent a410652 commit 8fa66e8

File tree

133 files changed

+339
-395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+339
-395
lines changed

doc/tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ can sometimes make code awkward and parenthesis-filled.
11351135
~~~
11361136
# struct Point { x: float, y: float }
11371137
# enum Shape { Rectangle(Point, Point) }
1138-
# impl Shape { fn area() -> int { 0 } }
1138+
# impl Shape { fn area(&self) -> int { 0 } }
11391139
let start = @Point { x: 10f, y: 20f };
11401140
let end = ~Point { x: (*start).x + 100f, y: (*start).y + 100f };
11411141
let rect = &Rectangle(*start, *end);
@@ -1149,7 +1149,7 @@ dot), so in most cases, explicitly dereferencing the receiver is not necessary.
11491149
~~~
11501150
# struct Point { x: float, y: float }
11511151
# enum Shape { Rectangle(Point, Point) }
1152-
# impl Shape { fn area() -> int { 0 } }
1152+
# impl Shape { fn area(&self) -> int { 0 } }
11531153
let start = @Point { x: 10f, y: 20f };
11541154
let end = ~Point { x: start.x + 100f, y: start.y + 100f };
11551155
let rect = &Rectangle(*start, *end);

src/librustc/middle/lint.rs

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ pub enum lint {
7575
non_camel_case_types,
7676
type_limits,
7777
default_methods,
78-
deprecated_self,
7978
deprecated_mutable_fields,
8079
deprecated_drop,
8180
foreign_mode,
@@ -246,13 +245,6 @@ pub fn get_lint_dict() -> LintDict {
246245
default: deny
247246
}),
248247

249-
(@~"deprecated_self",
250-
@LintSpec {
251-
lint: deprecated_self,
252-
desc: "warn about deprecated uses of `self`",
253-
default: warn
254-
}),
255-
256248
(@~"deprecated_mutable_fields",
257249
@LintSpec {
258250
lint: deprecated_mutable_fields,
@@ -497,7 +489,6 @@ fn check_item(i: @ast::item, cx: ty::ctxt) {
497489
check_item_deprecated_modes(cx, i);
498490
check_item_type_limits(cx, i);
499491
check_item_default_methods(cx, i);
500-
check_item_deprecated_self(cx, i);
501492
check_item_deprecated_mutable_fields(cx, i);
502493
check_item_deprecated_drop(cx, i);
503494
}
@@ -677,46 +668,6 @@ fn check_item_default_methods(cx: ty::ctxt, item: @ast::item) {
677668
}
678669
}
679670

680-
fn check_item_deprecated_self(cx: ty::ctxt, item: @ast::item) {
681-
fn maybe_warn(cx: ty::ctxt,
682-
item: @ast::item,
683-
self_ty: ast::self_ty) {
684-
match self_ty.node {
685-
ast::sty_by_ref => {
686-
cx.sess.span_lint(
687-
deprecated_self,
688-
item.id,
689-
item.id,
690-
self_ty.span,
691-
~"this method form is deprecated; use an explicit `self` \
692-
parameter or mark the method as static");
693-
}
694-
_ => {}
695-
}
696-
}
697-
698-
match /*bad*/copy item.node {
699-
ast::item_trait(_, _, methods) => {
700-
for methods.each |method| {
701-
match /*bad*/copy *method {
702-
ast::required(ty_method) => {
703-
maybe_warn(cx, item, ty_method.self_ty);
704-
}
705-
ast::provided(method) => {
706-
maybe_warn(cx, item, method.self_ty);
707-
}
708-
}
709-
}
710-
}
711-
ast::item_impl(_, _, _, methods) => {
712-
for methods.each |method| {
713-
maybe_warn(cx, item, method.self_ty);
714-
}
715-
}
716-
_ => {}
717-
}
718-
}
719-
720671
fn check_item_deprecated_mutable_fields(cx: ty::ctxt, item: @ast::item) {
721672
match item.node {
722673
ast::item_struct(struct_def, _) => {

src/libsyntax/parse/obsolete.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub enum ObsoleteSyntax {
5656
ObsoleteBareFnType,
5757
ObsoleteNewtypeEnum,
5858
ObsoleteMode,
59+
ObsoleteImplicitSelf,
5960
}
6061

6162
impl to_bytes::IterBytes for ObsoleteSyntax {
@@ -181,6 +182,11 @@ pub impl Parser {
181182
"obsolete argument mode",
182183
"replace `-` or `++` mode with `+`"
183184
),
185+
ObsoleteImplicitSelf => (
186+
"implicit self",
187+
"use an explicit `self` declaration or declare the method as \
188+
static"
189+
),
184190
};
185191

186192
self.report(sp, kind, kind_str, desc);

src/libsyntax/parse/parser.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ use parse::obsolete::{ObsoleteMutVector, ObsoleteTraitImplVisibility};
7878
use parse::obsolete::{ObsoleteRecordType, ObsoleteRecordPattern};
7979
use parse::obsolete::{ObsoleteAssertion, ObsoletePostFnTySigil};
8080
use parse::obsolete::{ObsoleteBareFnType, ObsoleteNewtypeEnum};
81-
use parse::obsolete::{ObsoleteMode};
81+
use parse::obsolete::{ObsoleteMode, ObsoleteImplicitSelf};
8282
use parse::prec::{as_prec, token_to_binop};
8383
use parse::token::{can_begin_expr, is_ident, is_ident_or_path};
8484
use parse::token::{is_plain_ident, INTERPOLATED, special_idents};
@@ -471,6 +471,10 @@ pub impl Parser {
471471
// XXX: Wrong. Shouldn't allow both static and self_ty
472472
let self_ty = if is_static { static_sty } else { self_ty };
473473
474+
if self_ty.node == sty_by_ref {
475+
self.obsolete(self_ty.span, ObsoleteImplicitSelf);
476+
}
477+
474478
let hi = p.last_span.hi;
475479
debug!("parse_trait_methods(): trait method signature ends in \
476480
`%s`",
@@ -2981,6 +2985,10 @@ pub impl Parser {
29812985
// XXX: interaction between staticness, self_ty is broken now
29822986
let self_ty = if is_static { static_sty} else { self_ty };
29832987

2988+
if self_ty.node == sty_by_ref {
2989+
self.obsolete(self_ty.span, ObsoleteImplicitSelf);
2990+
}
2991+
29842992
let (inner_attrs, body) = self.parse_inner_attrs_and_block(true);
29852993
let hi = body.span.hi;
29862994
let attrs = vec::append(attrs, inner_attrs);

src/test/auxiliary/ambig_impl_2_lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
// except according to those terms.
1010

1111
trait me {
12-
fn me() -> uint;
12+
fn me(&self) -> uint;
1313
}
14-
impl me for uint { fn me() -> uint { self } }
14+
impl me for uint { fn me(&self) -> uint { self } }

src/test/auxiliary/cci_class_2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub mod kitties {
1717
}
1818

1919
pub impl cat {
20-
fn speak() {}
20+
fn speak(&self) {}
2121
}
2222

2323
pub fn cat(in_x : uint, in_y : int) -> cat {

src/test/auxiliary/cci_impl_lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
#[link(name="cci_impl_lib", vers="0.0")];
1212

1313
trait uint_helpers {
14-
fn to(v: uint, f: &fn(uint));
14+
fn to(self, v: uint, f: &fn(uint));
1515
}
1616

1717
impl uint_helpers for uint {
1818
#[inline]
19-
fn to(v: uint, f: &fn(uint)) {
19+
fn to(self, v: uint, f: &fn(uint)) {
2020
let mut i = self;
2121
while i < v {
2222
f(i);

src/test/auxiliary/crate-method-reexport-grrrrrrr2.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ pub mod name_pool {
1616
pub type name_pool = ();
1717

1818
pub trait add {
19-
fn add(s: ~str);
19+
fn add(&self, s: ~str);
2020
}
2121

2222
impl add for name_pool {
23-
fn add(s: ~str) {
23+
fn add(&self, s: ~str) {
2424
}
2525
}
2626
}
@@ -31,11 +31,11 @@ pub mod rust {
3131
pub type rt = @();
3232

3333
pub trait cx {
34-
fn cx();
34+
fn cx(&self);
3535
}
3636

3737
impl cx for rt {
38-
fn cx() {
38+
fn cx(&self) {
3939
}
4040
}
4141
}

src/test/auxiliary/issue-2414-a.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
type t1 = uint;
1515

1616
trait foo {
17-
fn foo();
17+
fn foo(&self);
1818
}
1919

2020
impl foo for ~str {
21-
fn foo() {}
21+
fn foo(&self) {}
2222
}
2323

src/test/auxiliary/issue-2526.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ fn context_res() -> context_res {
5656
pub type context = arc_destruct<context_res>;
5757

5858
pub impl context {
59-
fn socket() { }
59+
fn socket(&self) { }
6060
}

src/test/auxiliary/issue_2472_b.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
pub struct S(());
1313

1414
pub impl S {
15-
fn foo() { }
15+
fn foo(&self) { }
1616
}
1717

1818
pub trait T {
19-
fn bar();
19+
fn bar(&self);
2020
}
2121

2222
impl T for S {
23-
fn bar() { }
23+
fn bar(&self) { }
2424
}

src/test/auxiliary/issue_3136_a.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
// except according to those terms.
1010

1111
trait x {
12-
fn use_x<T>();
12+
fn use_x<T>(&self);
1313
}
1414
struct y(());
1515
impl x for y {
16-
fn use_x<T>() {
16+
fn use_x<T>(&self) {
1717
struct foo { //~ ERROR quux
1818
i: ()
1919
}

src/test/auxiliary/trait_inheritance_auto_xc_2_aux.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
pub trait Foo { fn f() -> int; }
12-
pub trait Bar { fn g() -> int; }
13-
pub trait Baz { fn h() -> int; }
11+
pub trait Foo { fn f(&self) -> int; }
12+
pub trait Bar { fn g(&self) -> int; }
13+
pub trait Baz { fn h(&self) -> int; }
1414

1515
pub struct A { x: int }
1616

17-
impl Foo for A { fn f() -> int { 10 } }
18-
impl Bar for A { fn g() -> int { 20 } }
19-
impl Baz for A { fn h() -> int { 30 } }
17+
impl Foo for A { fn f(&self) -> int { 10 } }
18+
impl Bar for A { fn g(&self) -> int { 20 } }
19+
impl Baz for A { fn h(&self) -> int { 30 } }
2020

2121

src/test/auxiliary/trait_inheritance_auto_xc_aux.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
trait Foo { fn f() -> int; }
12-
trait Bar { fn g() -> int; }
13-
trait Baz { fn h() -> int; }
11+
trait Foo { fn f(&self) -> int; }
12+
trait Bar { fn g(&self) -> int; }
13+
trait Baz { fn h(&self) -> int; }
1414

1515
trait Quux: Foo + Bar + Baz { }
1616

src/test/auxiliary/trait_inheritance_cross_trait_call_xc_aux.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111

1212
pub trait Foo {
13-
fn f() -> int;
13+
fn f(&self) -> int;
1414
}
1515

1616
pub struct A {
1717
x: int
1818
}
1919

2020
impl Foo for A {
21-
fn f() -> int { 10 }
21+
fn f(&self) -> int { 10 }
2222
}

src/test/compile-fail/ambig_impl_unify.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
// except according to those terms.
1010

1111
trait foo {
12-
fn foo() -> int;
12+
fn foo(&self) -> int;
1313
}
1414

1515
impl foo for ~[uint] {
16-
fn foo() -> int {1} //~ NOTE candidate #1 is `__extensions__::foo`
16+
fn foo(&self) -> int {1} //~ NOTE candidate #1 is `__extensions__::foo`
1717
}
1818

1919
impl foo for ~[int] {
20-
fn foo() -> int {2} //~ NOTE candidate #2 is `__extensions__::foo`
20+
fn foo(&self) -> int {2} //~ NOTE candidate #2 is `__extensions__::foo`
2121
}
2222

2323
fn main() {

src/test/compile-fail/assign-to-method.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct cat {
1616

1717
pub impl cat {
1818

19-
fn speak() { self.meows += 1u; }
19+
fn speak(&self) { self.meows += 1u; }
2020
}
2121

2222
fn cat(in_x : uint, in_y : int) -> cat {

src/test/compile-fail/auto-ref-borrowck-failure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ struct Foo {
1515
}
1616

1717
trait Stuff {
18-
fn printme();
18+
fn printme(self);
1919
}
2020

2121
impl Stuff for &'self mut Foo {
22-
fn printme() {
22+
fn printme(self) {
2323
io::println(fmt!("%d", self.x));
2424
}
2525
}

src/test/compile-fail/bad-method-typaram-kind.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ fn foo<T>() {
1313
}
1414

1515
trait bar {
16-
fn bar<T:Copy>();
16+
fn bar<T:Copy>(&self);
1717
}
1818

1919
impl bar for uint {
20-
fn bar<T:Copy>() {
20+
fn bar<T:Copy>(&self) {
2121
}
2222
}
2323

src/test/compile-fail/borrowck-autoref-3261.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
struct X(Either<(uint,uint),extern fn()>);
1212

1313
pub impl &'self X {
14-
fn with(blk: &fn(x: &Either<(uint,uint),extern fn()>)) {
14+
fn with(self, blk: &fn(x: &Either<(uint,uint),extern fn()>)) {
1515
blk(&**self)
1616
}
1717
}

src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl ops::Add<int,int> for Point {
2020
}
2121

2222
pub impl Point {
23-
fn times(z: int) -> int {
23+
fn times(&self, z: int) -> int {
2424
self.x * self.y * z
2525
}
2626
}

0 commit comments

Comments
 (0)