let terminator = self.body[location.block].terminator();
debug!("add_moved_or_invoked_closure_note: terminator={:?}", terminator);
if let TerminatorKind::Call {
- func: Operand::Constant(box Constant { literal: ty::Const { ty: const_ty, .. }, .. }),
+ func: Operand::Constant(box Constant { literal, .. }),
args,
..
} = &terminator.kind
{
- if let ty::FnDef(id, _) = *const_ty.kind() {
+ if let ty::FnDef(id, _) = *literal.ty().kind() {
debug!("add_moved_or_invoked_closure_note: id={:?}", id);
if self.infcx.tcx.parent(id) == self.infcx.tcx.lang_items().fn_once_trait() {
let closure = match args.first() {
// so it's safe to call `expect_local`.
//
// We know the field exists so it's safe to call operator[] and `unwrap` here.
- let (&var_id, _) =
- self.infcx.tcx.typeck(def_id.expect_local()).closure_captures[&def_id]
- .get_index(field.index())
- .unwrap();
+ let var_id = self
+ .infcx
+ .tcx
+ .typeck(def_id.expect_local())
+ .closure_min_captures_flattened(def_id)
+ .nth(field.index())
+ .unwrap()
+ .get_root_variable();
self.infcx.tcx.hir().name(var_id).to_string()
}
let expr = &self.infcx.tcx.hir().expect_expr(hir_id).kind;
debug!("closure_span: hir_id={:?} expr={:?}", hir_id, expr);
if let hir::ExprKind::Closure(.., body_id, args_span, _) = expr {
- for (upvar_hir_id, place) in
- self.infcx.tcx.typeck(def_id.expect_local()).closure_captures[&def_id]
- .keys()
- .zip(places)
+ for (captured_place, place) in self
+ .infcx
+ .tcx
+ .typeck(def_id.expect_local())
+ .closure_min_captures_flattened(def_id)
+ .zip(places)
{
- let span = self.infcx.tcx.upvars_mentioned(local_did)?[upvar_hir_id].span;
+ let upvar_hir_id = captured_place.get_root_variable();
+ //FIXME(project-rfc-2229#8): Use better span from captured_place
+ let span = self.infcx.tcx.upvars_mentioned(local_did)?[&upvar_hir_id].span;
match place {
Operand::Copy(place) | Operand::Move(place)
if target_place == place.as_ref() =>
debug!("closure_span: found captured local {:?}", place);
let body = self.infcx.tcx.hir().body(*body_id);
let generator_kind = body.generator_kind();
- let upvar_id = ty::UpvarId {
- var_path: ty::UpvarPath { hir_id: *upvar_hir_id },
- closure_expr_id: local_did,
- };
// If we have a more specific span available, point to that.
// We do this even though this span might be part of a borrow error
// to a span that shows why the upvar is used in the closure,
// so a move-related span is as good as any (and potentially better,
// if the overall error is due to a move of the upvar).
- let usage_span =
- match self.infcx.tcx.typeck(local_did).upvar_capture(upvar_id) {
- ty::UpvarCapture::ByValue(Some(span)) => span,
- _ => span,
- };
+
+ let usage_span = match captured_place.info.capture_kind {
+ ty::UpvarCapture::ByValue(Some(span)) => span,
+ _ => span,
+ };
return Some((*args_span, generator_kind, usage_span));
}
_ => {}