@@ -74,6 +74,7 @@ pub enum lint {
74
74
unused_imports,
75
75
unnecessary_qualification,
76
76
while_true,
77
+ deprecated_for_loop,
77
78
path_statement,
78
79
unrecognized_lint,
79
80
non_camel_case_types,
@@ -165,6 +166,13 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
165
166
default : warn
166
167
} ) ,
167
168
169
+ ( "deprecated_for_loop" ,
170
+ LintSpec {
171
+ lint : deprecated_for_loop,
172
+ desc : "recommend using `foreach` or `do` instead of `for`" ,
173
+ default : allow
174
+ } ) ,
175
+
168
176
( "path_statement" ,
169
177
LintSpec {
170
178
lint : path_statement,
@@ -561,6 +569,24 @@ fn lint_while_true() -> visit::vt<@mut Context> {
561
569
} )
562
570
}
563
571
572
+ fn lint_deprecated_for_loop ( ) -> visit:: vt < @mut Context > {
573
+ visit:: mk_vt ( @visit:: Visitor {
574
+ visit_expr : |e, ( cx, vt) : ( @mut Context , visit:: vt < @mut Context > ) | {
575
+ match e. node {
576
+ ast:: expr_call( _, _, ast:: ForSugar ) |
577
+ ast:: expr_method_call( _, _, _, _, _, ast:: ForSugar ) => {
578
+ cx. span_lint ( deprecated_for_loop, e. span ,
579
+ "`for` is deprecated; use `foreach <pat> in \
580
+ <iterator>` or `do`")
581
+ }
582
+ _ => { }
583
+ }
584
+ visit:: visit_expr ( e, ( cx, vt) ) ;
585
+ } ,
586
+ .. * visit:: default_visitor ( )
587
+ } )
588
+ }
589
+
564
590
fn lint_type_limits ( ) -> visit:: vt < @mut Context > {
565
591
fn is_valid < T : cmp:: Ord > ( binop : ast:: binop , v : T ,
566
592
min : T , max : T ) -> bool {
@@ -1096,6 +1122,7 @@ pub fn check_crate(tcx: ty::ctxt, crate: @ast::Crate) {
1096
1122
1097
1123
// Register each of the lint passes with the context
1098
1124
cx. add_lint ( lint_while_true ( ) ) ;
1125
+ cx. add_lint ( lint_deprecated_for_loop ( ) ) ;
1099
1126
cx. add_lint ( lint_path_statement ( ) ) ;
1100
1127
cx. add_lint ( lint_heap ( ) ) ;
1101
1128
cx. add_lint ( lint_type_limits ( ) ) ;
0 commit comments