@@ -3,7 +3,7 @@ import middle::ty;
3
3
import syntax :: { ast, visit} ;
4
4
import syntax:: attr;
5
5
import syntax:: codemap:: span;
6
- import std:: map:: { map, hashmap, hash_from_strs} ;
6
+ import std:: map:: { map, hashmap, int_hash , hash_from_strs} ;
7
7
import io:: writer_util;
8
8
import syntax:: print:: pprust:: expr_to_str;
9
9
@@ -26,6 +26,7 @@ enum lint {
26
26
unused_imports,
27
27
while_true,
28
28
path_statement,
29
+ old_vecs,
29
30
}
30
31
31
32
enum level {
@@ -62,7 +63,12 @@ fn get_lint_dict() -> lint_dict {
62
63
( "path_statement" ,
63
64
@{ lint: path_statement,
64
65
desc: "path statements with no effect" ,
65
- default : warn} )
66
+ default : warn} ) ,
67
+
68
+ ( "old_vecs" ,
69
+ @{ lint: old_vecs,
70
+ desc: "old (deprecated) vectors and strings" ,
71
+ default : ignore} )
66
72
67
73
] ;
68
74
hash_from_strs ( v)
@@ -185,6 +191,7 @@ fn check_item(cx: ctxt, i: @ast::item) {
185
191
unused_imports { check_item_unused_imports( cx, level, i) ; }
186
192
while_true { check_item_while_true( cx, level, i) ; }
187
193
path_statement { check_item_path_statement( cx, level, i) ; }
194
+ old_vecs { check_item_old_vecs( cx, level, i) ; }
188
195
}
189
196
}
190
197
}
@@ -279,6 +286,50 @@ fn check_item_path_statement(cx: ctxt, level: level, it: @ast::item) {
279
286
visit:: visit_item ( it, ( ) , visit) ;
280
287
}
281
288
289
+ fn check_item_old_vecs ( cx : ctxt , level : level , it : @ast:: item ) {
290
+ let uses_vstore = int_hash ( ) ;
291
+
292
+ let visit = visit:: mk_simple_visitor ( @{
293
+
294
+ visit_expr : fn @( e: @ast:: expr) {
295
+ alt e. node {
296
+ ast:: expr_vec ( _, _) |
297
+ ast:: expr_lit ( @{ node: ast:: lit_str ( _) , span: _} )
298
+ if ! uses_vstore. contains_key ( e. id ) {
299
+ cx. span_lint ( level, e. span , "deprecated vec/str expr" ) ;
300
+ }
301
+ ast:: expr_vstore ( @inner, _) {
302
+ uses_vstore. insert ( inner. id , true ) ;
303
+ }
304
+ _ { }
305
+ }
306
+ } ,
307
+
308
+ visit_ty: fn @( t: @ast:: ty) {
309
+ alt t. node {
310
+ ast:: ty_vec ( _)
311
+ if ! uses_vstore. contains_key ( t. id ) {
312
+ cx. span_lint ( level, t. span , "deprecated vec type" ) ;
313
+ }
314
+
315
+ ast:: ty_path ( @{ span: _, global: _, idents: ids,
316
+ rp: none, types: _} , _)
317
+ if ids == [ "str" ] && ( ! uses_vstore. contains_key ( t. id ) ) {
318
+ cx. span_lint ( level, t. span , "deprecated str type" ) ;
319
+ }
320
+
321
+ ast:: ty_vstore ( inner, _) {
322
+ uses_vstore. insert ( inner. id , true ) ;
323
+ }
324
+ _ { }
325
+ }
326
+ }
327
+
328
+ with * visit:: default_simple_visitor ( )
329
+ } ) ;
330
+ visit:: visit_item ( it, ( ) , visit) ;
331
+ }
332
+
282
333
283
334
fn check_crate ( tcx : ty:: ctxt , crate : @ast:: crate ,
284
335
lint_opts : [ ( lint , level ) ] , time_pass : bool ) {
0 commit comments