- /// Walk closure captures but using `closure_caputes` instead
- /// of `closure_min_captures`.
- ///
- /// This is needed because clippy uses `ExprUseVisitor` after TypeckResults
- /// are written back. We don't currently writeback min_captures to
- /// TypeckResults.
- fn walk_captures_closure_captures(&mut self, closure_expr: &hir::Expr<'_>) {
- // FIXME(arora-aman): Remove this function once rust-lang/project-rfc-2229#18
- // is completed.
- debug!("walk_captures_closure_captures({:?}), ", closure_expr);
-
- let closure_def_id = self.tcx().hir().local_def_id(closure_expr.hir_id).to_def_id();
- let cl_span = self.tcx().hir().span(closure_expr.hir_id);
-
- let captures = &self.mc.typeck_results.closure_captures[&closure_def_id];
-
- for (&var_id, &upvar_id) in captures {
- let upvar_capture = self.mc.typeck_results.upvar_capture(upvar_id);
- let captured_place =
- return_if_err!(self.cat_captured_var(closure_expr.hir_id, cl_span, var_id));
- match upvar_capture {
- ty::UpvarCapture::ByValue(_) => {
- let mode = copy_or_move(&self.mc, &captured_place);
- self.delegate.consume(&captured_place, captured_place.hir_id, mode);
- }
- ty::UpvarCapture::ByRef(upvar_borrow) => {
- self.delegate.borrow(&captured_place, captured_place.hir_id, upvar_borrow.kind);
- }
- }
- }
- }
-