@@ -3,7 +3,7 @@ use clippy_utils::sugg::DiagnosticExt;
33use clippy_utils:: ty:: is_copy;
44use rustc_data_structures:: fx:: FxIndexMap ;
55use rustc_errors:: Applicability ;
6- use rustc_hir:: * ;
6+ use rustc_hir:: { CaptureBy , Closure , Expr , ExprKind , HirId } ;
77use rustc_hir_typeck:: expr_use_visitor as euv;
88use rustc_infer:: infer:: TyCtxtInferExt ;
99use rustc_lint:: { LateContext , LateLintPass } ;
@@ -41,7 +41,7 @@ declare_clippy_lint! {
4141declare_lint_pass ! ( NeedlessMove => [ NEEDLESS_MOVE ] ) ;
4242
4343impl NeedlessMove {
44- fn check_closure < ' tcx > ( & self , cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' tcx > , closure : & ' tcx Closure < ' tcx > ) {
44+ fn check_closure < ' tcx > ( cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' tcx > , closure : & ' tcx Closure < ' tcx > ) {
4545 let CaptureBy :: Value { move_kw } = closure. capture_clause else {
4646 return ;
4747 } ;
@@ -58,8 +58,8 @@ impl NeedlessMove {
5858 mut captured_vars,
5959 } = {
6060 let mut ctx = MovedVariablesCtxt {
61- captured_vars : Default :: default ( ) ,
62- moved_vars : Default :: default ( ) ,
61+ captured_vars : FxIndexMap :: default ( ) ,
62+ moved_vars : FxIndexMap :: default ( ) ,
6363 } ;
6464 let body = cx. tcx . hir ( ) . body ( closure. body ) ;
6565 let infcx = cx. tcx . infer_ctxt ( ) . build ( ) ;
@@ -70,7 +70,7 @@ impl NeedlessMove {
7070
7171 // Remove the captured vars which were also `move`d.
7272 // See special case 1. below.
73- for ( hir_id, _upvars) in moved_vars. iter ( ) {
73+ for ( hir_id, _upvars) in & moved_vars {
7474 let Some ( vars) = captured_vars. get_mut ( hir_id) else {
7575 continue ;
7676 } ;
@@ -99,9 +99,11 @@ impl NeedlessMove {
9999 } ;
100100
101101 match ( moved_vars. is_empty ( ) , captured_vars. is_empty ( ) ) {
102- ( true , true ) => lint ( "there were no captured variables, so the `move` is unnecessary" ) ,
102+ ( true , true ) => {
103+ lint ( "there were no captured variables, so the `move` is unnecessary" ) ;
104+ } ,
103105 ( false , true ) => {
104- lint ( "there were consumed variables, but no borrowed variables, so the `move` is unnecessary" )
106+ lint ( "there were consumed variables, but no borrowed variables, so the `move` is unnecessary" ) ;
105107 } ,
106108 ( _, false ) => {
107109 // captured_vars is not empty, so `move` actually makes a difference and we
@@ -121,7 +123,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessMove {
121123 return ;
122124 } ;
123125
124- self . check_closure ( cx, expr, closure) ;
126+ Self :: check_closure ( cx, expr, closure) ;
125127 }
126128}
127129
0 commit comments