@@ -813,27 +813,24 @@ fn check_unused_unsafe(cx: &Context, e: &ast::Expr) {
813813}
814814
815815fn 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+ }
836832 }
833+ _ => ( )
837834 }
838835}
839836
@@ -1075,6 +1072,8 @@ impl Visitor<()> for Context {
10751072
10761073 fn visit_pat( & mut self , p: @ast:: Pat , _ : ( ) ) {
10771074 check_pat_non_uppercase_statics ( self , p) ;
1075+ check_unused_mut_pat ( self , p) ;
1076+
10781077 visit:: walk_pat ( self , p, ( ) ) ;
10791078 }
10801079
@@ -1095,30 +1094,9 @@ impl Visitor<()> for Context {
10951094 visit:: walk_stmt ( self , s, ( ) ) ;
10961095 }
10971096
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-
11181097 fn visit_fn ( & mut self , fk : & visit:: fn_kind , decl : & ast:: fn_decl ,
11191098 body : & ast:: Block , span : Span , id : ast:: NodeId , _: ( ) ) {
11201099 let recurse = |this : & mut Context | {
1121- check_unused_mut_fn_decl ( this, decl) ;
11221100 visit:: walk_fn ( this, fk, decl, body, span, id, ( ) ) ;
11231101 } ;
11241102
0 commit comments