@@ -813,27 +813,24 @@ fn check_unused_unsafe(cx: &Context, e: &ast::Expr) {
813
813
}
814
814
815
815
fn check_unused_mut_pat ( cx : & Context , p : @ast:: Pat ) {
816
- let mut used = false ;
817
- let mut bindings = 0 ;
818
- do pat_util:: pat_bindings ( cx. tcx . def_map , p) |_, id, _, _| {
819
- used = used || cx. tcx . used_mut_nodes . contains ( & id) ;
820
- bindings += 1 ;
821
- }
822
- if !used {
823
- let msg = if bindings == 1 {
824
- "variable does not need to be mutable"
825
- } else {
826
- "variables do not need to be mutable"
827
- } ;
828
- cx. span_lint ( unused_mut, p. span , msg) ;
829
- }
830
- }
831
-
832
- fn check_unused_mut_fn_decl ( cx : & Context , fd : & ast:: fn_decl ) {
833
- for arg in fd. inputs . iter ( ) {
834
- if arg. is_mutbl {
835
- check_unused_mut_pat ( cx, arg. pat ) ;
816
+ match p. node {
817
+ ast:: PatIdent ( ast:: BindByValue ( ast:: MutMutable ) , _, _) => {
818
+ let mut used = false ;
819
+ let mut bindings = 0 ;
820
+ do pat_util:: pat_bindings ( cx. tcx . def_map , p) |_, id, _, _| {
821
+ used = used || cx. tcx . used_mut_nodes . contains ( & id) ;
822
+ bindings += 1 ;
823
+ }
824
+ if !used {
825
+ let msg = if bindings == 1 {
826
+ "variable does not need to be mutable"
827
+ } else {
828
+ "variables do not need to be mutable"
829
+ } ;
830
+ cx. span_lint ( unused_mut, p. span , msg) ;
831
+ }
836
832
}
833
+ _ => ( )
837
834
}
838
835
}
839
836
@@ -1075,6 +1072,8 @@ impl Visitor<()> for Context {
1075
1072
1076
1073
fn visit_pat( & mut self , p: @ast:: Pat , _ : ( ) ) {
1077
1074
check_pat_non_uppercase_statics ( self , p) ;
1075
+ check_unused_mut_pat ( self , p) ;
1076
+
1078
1077
visit:: walk_pat ( self , p, ( ) ) ;
1079
1078
}
1080
1079
@@ -1095,30 +1094,9 @@ impl Visitor<()> for Context {
1095
1094
visit:: walk_stmt ( self , s, ( ) ) ;
1096
1095
}
1097
1096
1098
- fn visit_ty_method ( & mut self , tm : & ast:: TypeMethod , _: ( ) ) {
1099
- check_unused_mut_fn_decl ( self , & tm. decl ) ;
1100
- visit:: walk_ty_method ( self , tm, ( ) ) ;
1101
- }
1102
-
1103
- fn visit_trait_method ( & mut self , tm : & ast:: trait_method , _: ( ) ) {
1104
- match * tm {
1105
- ast:: required( ref m) => check_unused_mut_fn_decl ( self , & m. decl ) ,
1106
- ast:: provided( ref m) => check_unused_mut_fn_decl ( self , & m. decl )
1107
- }
1108
- visit:: walk_trait_method ( self , tm, ( ) ) ;
1109
- }
1110
-
1111
- fn visit_local ( & mut self , l : @ast:: Local , _: ( ) ) {
1112
- if l. is_mutbl {
1113
- check_unused_mut_pat ( self , l. pat ) ;
1114
- }
1115
- visit:: walk_local ( self , l, ( ) ) ;
1116
- }
1117
-
1118
1097
fn visit_fn ( & mut self , fk : & visit:: fn_kind , decl : & ast:: fn_decl ,
1119
1098
body : & ast:: Block , span : Span , id : ast:: NodeId , _: ( ) ) {
1120
1099
let recurse = |this : & mut Context | {
1121
- check_unused_mut_fn_decl ( this, decl) ;
1122
1100
visit:: walk_fn ( this, fk, decl, body, span, id, ( ) ) ;
1123
1101
} ;
1124
1102
0 commit comments