Skip to content

Commit d35b78a

Browse files
committed
---
yaml --- r: 39411 b: refs/heads/incoming c: ebd9ad4 h: refs/heads/master i: 39409: 42ae34a 39407: b520c21 v: v3
1 parent 4feb25f commit d35b78a

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 3d5418789064fdb463e872a4e651af1c628a3650
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278
9-
refs/heads/incoming: 41c0d7083e19b0940fafb8b452ac24d5403f532b
9+
refs/heads/incoming: ebd9ad4d0446ac76bdbb0ada21e943ad0cbeef60
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/librustc/middle/lint.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ enum lint {
6666
structural_records,
6767
type_limits,
6868
default_methods,
69+
deprecated_self,
6970

7071
managed_heap_memory,
7172
owned_heap_memory,
@@ -208,6 +209,11 @@ fn get_lint_dict() -> lint_dict {
208209
desc: ~"allow default methods",
209210
default: forbid}),
210211

212+
(~"deprecated_self",
213+
@{lint: deprecated_self,
214+
desc: ~"warn about deprecated uses of `self`",
215+
default: allow}),
216+
211217
/* FIXME(#3266)--make liveness warnings lintable
212218
(~"unused_variable",
213219
@{lint: unused_variable,
@@ -421,6 +427,7 @@ fn check_item(i: @ast::item, cx: ty::ctxt) {
421427
check_item_deprecated_modes(cx, i);
422428
check_item_type_limits(cx, i);
423429
check_item_default_methods(cx, i);
430+
check_item_deprecated_self(cx, i);
424431
}
425432

426433
// Take a visitor, and modify it so that it will not proceed past subitems.
@@ -591,6 +598,41 @@ fn check_item_default_methods(cx: ty::ctxt, item: @ast::item) {
591598
}
592599
}
593600

601+
fn check_item_deprecated_self(cx: ty::ctxt, item: @ast::item) {
602+
fn maybe_warn(cx: ty::ctxt,
603+
item: @ast::item,
604+
self_ty: ast::self_ty) {
605+
cx.sess.span_lint(
606+
deprecated_self,
607+
item.id,
608+
item.id,
609+
self_ty.span,
610+
~"this method form is deprecated; use an explicit `self` \
611+
parameter or mark the method as static");
612+
}
613+
614+
match item.node {
615+
ast::item_trait(_, _, methods) => {
616+
for methods.each |method| {
617+
match *method {
618+
ast::required(ty_method) => {
619+
maybe_warn(cx, item, ty_method.self_ty);
620+
}
621+
ast::provided(method) => {
622+
maybe_warn(cx, item, method.self_ty);
623+
}
624+
}
625+
}
626+
}
627+
ast::item_impl(_, _, _, methods) => {
628+
for methods.each |method| {
629+
maybe_warn(cx, item, method.self_ty);
630+
}
631+
}
632+
_ => {}
633+
}
634+
}
635+
594636
fn check_item_structural_records(cx: ty::ctxt, it: @ast::item) {
595637
let visit = item_stopping_visitor(visit::mk_simple_visitor(@{
596638
visit_expr: fn@(e: @ast::expr) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#[forbid(deprecated_self)]
2+
mod a {
3+
trait T {
4+
fn f(); //~ ERROR this method form is deprecated
5+
}
6+
7+
struct S {
8+
x: int
9+
}
10+
11+
impl S : T {
12+
fn f() { //~ ERROR this method form is deprecated
13+
}
14+
}
15+
}
16+
17+
fn main() {
18+
}
19+
20+

0 commit comments

Comments
 (0)