@@ -1052,42 +1052,6 @@ fn detect_manual_memcpy<'tcx>(
10521052 }
10531053}
10541054
1055- // Delegate that traverses expression and detects mutable variables being used
1056- struct UsesMutableDelegate {
1057- found_mutable : bool ,
1058- }
1059-
1060- impl < ' tcx > Delegate < ' tcx > for UsesMutableDelegate {
1061- fn consume ( & mut self , _: & PlaceWithHirId < ' tcx > , _: ConsumeMode ) { }
1062-
1063- fn borrow ( & mut self , _: & PlaceWithHirId < ' tcx > , bk : ty:: BorrowKind ) {
1064- // Mutable variable is found
1065- if let ty:: BorrowKind :: MutBorrow = bk {
1066- self . found_mutable = true ;
1067- }
1068- }
1069-
1070- fn mutate ( & mut self , _: & PlaceWithHirId < ' tcx > ) { }
1071- }
1072-
1073- // Uses UsesMutableDelegate to find mutable variables in an expression expr
1074- fn has_mutable_variables < ' tcx > ( cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' _ > ) -> bool {
1075- let mut delegate = UsesMutableDelegate { found_mutable : false } ;
1076- let def_id = expr. hir_id . owner . to_def_id ( ) ;
1077- cx. tcx . infer_ctxt ( ) . enter ( |infcx| {
1078- ExprUseVisitor :: new (
1079- & mut delegate,
1080- & infcx,
1081- def_id. expect_local ( ) ,
1082- cx. param_env ,
1083- cx. typeck_results ( ) ,
1084- )
1085- . walk_expr ( expr) ;
1086- } ) ;
1087-
1088- delegate. found_mutable
1089- }
1090-
10911055// Scans for the usage of the for loop pattern
10921056struct ForPatternVisitor < ' a , ' tcx > {
10931057 found_pattern : bool ,
@@ -1253,7 +1217,7 @@ fn detect_same_item_push<'tcx>(
12531217 if same_item_push_visitor. should_lint {
12541218 if let Some ( ( vec, pushed_item) ) = same_item_push_visitor. vec_push {
12551219 // Make sure that the push does not involve possibly mutating values
1256- if ! has_mutable_variables ( cx , pushed_item ) {
1220+ if mutated_variables ( pushed_item , cx ) . map_or ( false , |mutvars| mutvars . is_empty ( ) ) {
12571221 // Walk through the expression being pushed and make sure that it
12581222 // does not contain the for loop pattern
12591223 let mut for_pat_visitor = ForPatternVisitor {
0 commit comments