Skip to content

Commit ebd9ad4

Browse files
committed
librustc: Add a lint mode for deprecated self. r=brson
1 parent 41c0d70 commit ebd9ad4

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

src/librustc/middle/lint.rs

+42
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) {
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)