@@ -66,6 +66,7 @@ enum lint {
66
66
structural_records,
67
67
type_limits,
68
68
default_methods,
69
+ deprecated_self,
69
70
70
71
managed_heap_memory,
71
72
owned_heap_memory,
@@ -208,6 +209,11 @@ fn get_lint_dict() -> lint_dict {
208
209
desc: ~"allow default methods",
209
210
default : forbid} ) ,
210
211
212
+ ( ~"deprecated_self",
213
+ @{ lint: deprecated_self,
214
+ desc: ~"warn about deprecated uses of `self `",
215
+ default : allow} ) ,
216
+
211
217
/* FIXME(#3266)--make liveness warnings lintable
212
218
(~"unused_variable",
213
219
@{lint: unused_variable,
@@ -421,6 +427,7 @@ fn check_item(i: @ast::item, cx: ty::ctxt) {
421
427
check_item_deprecated_modes( cx, i) ;
422
428
check_item_type_limits( cx, i) ;
423
429
check_item_default_methods( cx, i) ;
430
+ check_item_deprecated_self( cx, i) ;
424
431
}
425
432
426
433
// 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) {
591
598
}
592
599
}
593
600
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
+
594
636
fn check_item_structural_records( cx: ty:: ctxt, it: @ast:: item) {
595
637
let visit = item_stopping_visitor( visit:: mk_simple_visitor( @{
596
638
visit_expr: fn @( e: @ast:: expr) {
0 commit comments