- // hir.tables().upvar_list[fn_id].
- // Gather the upvars of a closure, if any.
- let upvar_decls: Vec<_> = tcx.with_freevars(fn_id, |freevars| {
- freevars.iter().map(|fv| {
- let var_id = fv.var_id();
- let var_hir_id = tcx.hir().node_to_hir_id(var_id);
- let closure_expr_id = tcx.hir().local_def_id(fn_id);
- let capture = hir.tables().upvar_capture(ty::UpvarId {
- var_path: ty::UpvarPath {hir_id: var_hir_id},
- closure_expr_id: LocalDefId::from_def_id(closure_expr_id),
- });
- let by_ref = match capture {
- ty::UpvarCapture::ByValue => false,
- ty::UpvarCapture::ByRef(..) => true
- };
- let mut decl = UpvarDecl {
- debug_name: keywords::Invalid.name(),
- var_hir_id: ClearCrossCrate::Set(var_hir_id),
- by_ref,
- mutability: Mutability::Not,
- };
- if let Some(Node::Binding(pat)) = tcx.hir().find(var_id) {
- if let hir::PatKind::Binding(_, _, ident, _) = pat.node {
- decl.debug_name = ident.name;