@@ -8,7 +8,9 @@ import std::map::{map,hashmap,int_hash,hash_from_strs};
8
8
import std:: smallintmap:: { map, smallintmap} ;
9
9
import io:: writer_util;
10
10
import util:: ppaux:: { ty_to_str} ;
11
- import syntax:: print:: pprust:: { expr_to_str, mode_to_str} ;
11
+ import middle:: pat_util:: { pat_bindings} ;
12
+ import syntax:: ast_util:: { path_to_ident} ;
13
+ import syntax:: print:: pprust:: { expr_to_str, mode_to_str, pat_to_str} ;
12
14
export lint, ctypes, unused_imports, while_true, path_statement, old_vecs;
13
15
export unrecognized_lint, non_implicitly_copyable_typarams;
14
16
export vecs_implicitly_copyable, implicit_copies;
@@ -49,6 +51,7 @@ enum lint {
49
51
non_implicitly_copyable_typarams,
50
52
vecs_implicitly_copyable,
51
53
deprecated_mode,
54
+ deprecated_pattern,
52
55
non_camel_case_types
53
56
}
54
57
@@ -140,6 +143,11 @@ fn get_lint_dict() -> lint_dict {
140
143
desc: ~"warn about deprecated uses of modes",
141
144
default : allow} ) ,
142
145
146
+ ( ~"deprecated_pattern",
147
+ @{ lint: deprecated_pattern,
148
+ desc: ~"warn about deprecated uses of pattern bindings",
149
+ default : allow} ) ,
150
+
143
151
( ~"non_camel_case_types",
144
152
@{ lint: non_camel_case_types,
145
153
desc: ~"types, variants and traits must have camel case names",
@@ -474,6 +482,27 @@ fn check_item_non_camel_case_types(cx: ty::ctxt, it: @ast::item) {
474
482
}
475
483
}
476
484
485
+ fn check_pat( tcx: ty:: ctxt, pat: @ast:: pat) {
486
+ debug!{ "lint check_pat pat=%s", pat_to_str( pat) } ;
487
+
488
+ do pat_bindings( tcx. def_map, pat) |binding_mode, id, span, path| {
489
+ match binding_mode {
490
+ ast:: bind_by_ref( _) | ast:: bind_by_value => { }
491
+ ast:: bind_by_implicit_ref => {
492
+ let pat_ty = ty:: node_id_to_type( tcx, id) ;
493
+ let kind = ty:: type_kind( tcx, pat_ty) ;
494
+ if !ty:: kind_is_safe_for_default_mode( kind) {
495
+ tcx. sess. span_lint(
496
+ deprecated_pattern, id, id,
497
+ span,
498
+ fmt!{ "binding `%s` should use ref or copy mode",
499
+ * path_to_ident( path) } ) ;
500
+ }
501
+ }
502
+ }
503
+ }
504
+ }
505
+
477
506
fn check_fn( tcx: ty:: ctxt, fk: visit:: fn_kind, decl: ast:: fn_decl,
478
507
_body: ast:: blk, span: span, id: ast:: node_id) {
479
508
debug!{ "lint check_fn fk=%? id=%?", fk, id} ;
@@ -527,11 +556,12 @@ fn check_fn(tcx: ty::ctxt, fk: visit::fn_kind, decl: ast::fn_decl,
527
556
fn check_crate( tcx: ty:: ctxt, crate : @ast:: crate ) {
528
557
529
558
let v = visit:: mk_simple_visitor( @{
530
- visit_item:
531
- |it| check_item( it, tcx) ,
532
- visit_fn:
533
- |fk, decl, body, span, id| check_fn( tcx, fk, decl, body,
534
- span, id) ,
559
+ visit_item: |it|
560
+ check_item( it, tcx) ,
561
+ visit_fn: |fk, decl, body, span, id|
562
+ check_fn( tcx, fk, decl, body, span, id) ,
563
+ visit_pat: |pat|
564
+ check_pat( tcx, pat) ,
535
565
with * visit:: default_simple_visitor( )
536
566
} ) ;
537
567
visit:: visit_crate( * crate , ( ) , v) ;
0 commit comments