1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 use rustc_data_structures::indexed_vec::Idx;
13 use rustc_const_math::ConstInt;
16 use hair::cx::to_ref::ToRef;
17 use rustc::hir::def::{Def, CtorKind};
18 use rustc::middle::const_val::ConstVal;
19 use rustc::ty::{self, AdtKind, VariantDef, Ty};
20 use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow};
21 use rustc::ty::cast::CastKind as TyCastKind;
24 impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
25 type Output = Expr<'tcx>;
27 fn make_mirror<'a, 'gcx>(self, cx: &mut Cx<'a, 'gcx, 'tcx>) -> Expr<'tcx> {
28 let temp_lifetime = cx.region_maps.temporary_scope(self.id);
29 let expr_extent = CodeExtent::Misc(self.id);
31 debug!("Expr::make_mirror(): id={}, span={:?}", self.id, self.span);
33 let mut expr = make_mirror_unadjusted(cx, self);
35 // Now apply adjustments, if any.
36 for adjustment in cx.tables().expr_adjustments(self) {
37 debug!("make_mirror: expr={:?} applying adjustment={:?}",
40 expr = apply_adjustment(cx, self, expr, adjustment);
43 // Next, wrap this up in the expr's scope.
45 temp_lifetime: temp_lifetime,
48 kind: ExprKind::Scope {
54 // Finally, create a destruction scope, if any.
55 if let Some(extent) = cx.region_maps.opt_destruction_extent(self.id) {
57 temp_lifetime: temp_lifetime,
60 kind: ExprKind::Scope {
72 fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
73 hir_expr: &'tcx hir::Expr,
75 adjustment: &Adjustment<'tcx>)
77 let Expr { temp_lifetime, span, .. } = expr;
78 let kind = match adjustment.kind {
79 Adjust::ReifyFnPointer => {
80 ExprKind::ReifyFnPointer { source: expr.to_ref() }
82 Adjust::UnsafeFnPointer => {
83 ExprKind::UnsafeFnPointer { source: expr.to_ref() }
85 Adjust::ClosureFnPointer => {
86 ExprKind::ClosureFnPointer { source: expr.to_ref() }
88 Adjust::NeverToAny => {
89 ExprKind::NeverToAny { source: expr.to_ref() }
91 Adjust::MutToConstPointer => {
92 ExprKind::Cast { source: expr.to_ref() }
94 Adjust::Deref(None) => {
95 ExprKind::Deref { arg: expr.to_ref() }
97 Adjust::Deref(Some(deref)) => {
98 let call = deref.method_call(cx.tcx, expr.ty);
102 ty: cx.tcx.mk_ref(deref.region,
108 kind: ExprKind::Borrow {
109 region: deref.region,
110 borrow_kind: to_borrow_kind(deref.mutbl),
115 overloaded_lvalue(cx, hir_expr, adjustment.target, Some(call), vec![expr.to_ref()])
117 Adjust::Borrow(AutoBorrow::Ref(r, m)) => {
120 borrow_kind: to_borrow_kind(m),
124 Adjust::Borrow(AutoBorrow::RawPtr(m)) => {
125 // Convert this to a suitable `&foo` and
126 // then an unsafe coercion. Limit the region to be just this
128 let region = ty::ReScope(CodeExtent::Misc(hir_expr.id));
129 let region = cx.tcx.mk_region(region);
132 ty: cx.tcx.mk_ref(region,
138 kind: ExprKind::Borrow {
140 borrow_kind: to_borrow_kind(m),
144 ExprKind::Cast { source: expr.to_ref() }
147 ExprKind::Unsize { source: expr.to_ref() }
153 ty: adjustment.target,
159 fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
160 expr: &'tcx hir::Expr)
162 let expr_ty = cx.tables().expr_ty(expr);
163 let temp_lifetime = cx.region_maps.temporary_scope(expr.id);
165 let kind = match expr.node {
166 // Here comes the interesting stuff:
167 hir::ExprMethodCall(.., ref args) => {
168 // Rewrite a.b(c) into UFCS form like Trait::b(a, c)
169 let expr = method_callee(cx, expr, None);
170 let args = args.iter()
180 hir::ExprCall(ref fun, ref args) => {
181 if cx.tables().is_method_call(expr) {
182 // The callee is something implementing Fn, FnMut, or FnOnce.
183 // Find the actual method implementation being called and
184 // build the appropriate UFCS call expression with the
185 // callee-object as expr parameter.
187 // rewrite f(u, v) into FnOnce::call_once(f, (u, v))
189 let method = method_callee(cx, expr, None);
191 let arg_tys = args.iter().map(|e| cx.tables().expr_ty_adjusted(e));
192 let tupled_args = Expr {
193 ty: cx.tcx.mk_tup(arg_tys, false),
194 temp_lifetime: temp_lifetime,
196 kind: ExprKind::Tuple { fields: args.iter().map(ToRef::to_ref).collect() },
201 fun: method.to_ref(),
202 args: vec![fun.to_ref(), tupled_args.to_ref()],
205 let adt_data = if let hir::ExprPath(hir::QPath::Resolved(_, ref path)) = fun.node {
206 // Tuple-like ADTs are represented as ExprCall. We convert them here.
207 expr_ty.ty_adt_def().and_then(|adt_def| {
209 Def::VariantCtor(variant_id, CtorKind::Fn) => {
210 Some((adt_def, adt_def.variant_index_with_id(variant_id)))
212 Def::StructCtor(_, CtorKind::Fn) => Some((adt_def, 0)),
219 if let Some((adt_def, index)) = adt_data {
220 let substs = cx.tables().node_substs(fun.hir_id);
221 let field_refs = args.iter()
225 name: Field::new(idx),
233 variant_index: index,
239 ty: cx.tables().node_id_to_type(fun.hir_id),
247 hir::ExprAddrOf(mutbl, ref expr) => {
248 let region = match expr_ty.sty {
249 ty::TyRef(r, _) => r,
250 _ => span_bug!(expr.span, "type of & not region"),
254 borrow_kind: to_borrow_kind(mutbl),
259 hir::ExprBlock(ref blk) => ExprKind::Block { body: &blk },
261 hir::ExprAssign(ref lhs, ref rhs) => {
268 hir::ExprAssignOp(op, ref lhs, ref rhs) => {
269 if cx.tables().is_method_call(expr) {
270 overloaded_operator(cx, expr, vec![lhs.to_ref(), rhs.to_ref()])
280 hir::ExprLit(..) => ExprKind::Literal { literal: cx.const_eval_literal(expr) },
282 hir::ExprBinary(op, ref lhs, ref rhs) => {
283 if cx.tables().is_method_call(expr) {
284 overloaded_operator(cx, expr, vec![lhs.to_ref(), rhs.to_ref()])
287 match (op.node, cx.constness) {
288 // FIXME(eddyb) use logical ops in constants when
289 // they can handle that kind of control-flow.
290 (hir::BinOp_::BiAnd, hir::Constness::Const) => {
297 (hir::BinOp_::BiOr, hir::Constness::Const) => {
305 (hir::BinOp_::BiAnd, hir::Constness::NotConst) => {
306 ExprKind::LogicalOp {
312 (hir::BinOp_::BiOr, hir::Constness::NotConst) => {
313 ExprKind::LogicalOp {
321 let op = bin_op(op.node);
332 hir::ExprIndex(ref lhs, ref index) => {
333 if cx.tables().is_method_call(expr) {
334 overloaded_lvalue(cx, expr, expr_ty, None, vec![lhs.to_ref(), index.to_ref()])
338 index: index.to_ref(),
343 hir::ExprUnary(hir::UnOp::UnDeref, ref arg) => {
344 if cx.tables().is_method_call(expr) {
345 overloaded_lvalue(cx, expr, expr_ty, None, vec![arg.to_ref()])
347 ExprKind::Deref { arg: arg.to_ref() }
351 hir::ExprUnary(hir::UnOp::UnNot, ref arg) => {
352 if cx.tables().is_method_call(expr) {
353 overloaded_operator(cx, expr, vec![arg.to_ref()])
362 hir::ExprUnary(hir::UnOp::UnNeg, ref arg) => {
363 if cx.tables().is_method_call(expr) {
364 overloaded_operator(cx, expr, vec![arg.to_ref()])
366 // FIXME runtime-overflow
367 if let hir::ExprLit(_) = arg.node {
368 ExprKind::Literal { literal: cx.const_eval_literal(expr) }
378 hir::ExprStruct(ref qpath, ref fields, ref base) => {
380 ty::TyAdt(adt, substs) => {
381 match adt.adt_kind() {
382 AdtKind::Struct | AdtKind::Union => {
383 let field_refs = field_refs(&adt.variants[0], fields);
389 base: base.as_ref().map(|base| {
392 field_types: cx.tables().fru_field_types[&expr.id].clone(),
398 let def = match *qpath {
399 hir::QPath::Resolved(_, ref path) => path.def,
400 hir::QPath::TypeRelative(..) => Def::Err,
403 Def::Variant(variant_id) => {
404 assert!(base.is_none());
406 let index = adt.variant_index_with_id(variant_id);
407 let field_refs = field_refs(&adt.variants[index], fields);
410 variant_index: index,
417 span_bug!(expr.span, "unexpected def: {:?}", def);
425 "unexpected type for struct literal: {:?}",
431 hir::ExprClosure(..) => {
432 let closure_ty = cx.tables().expr_ty(expr);
433 let (def_id, substs) = match closure_ty.sty {
434 ty::TyClosure(def_id, substs) => (def_id, substs),
436 span_bug!(expr.span, "closure expr w/o closure type: {:?}", closure_ty);
439 let upvars = cx.tcx.with_freevars(expr.id, |freevars| {
441 .zip(substs.upvar_tys(def_id, cx.tcx))
442 .map(|(fv, ty)| capture_freevar(cx, expr, fv, ty))
452 hir::ExprPath(ref qpath) => {
453 let def = cx.tables().qpath_def(qpath, expr.hir_id);
454 convert_path_expr(cx, expr, def)
457 hir::ExprInlineAsm(ref asm, ref outputs, ref inputs) => {
458 ExprKind::InlineAsm {
460 outputs: outputs.to_ref(),
461 inputs: inputs.to_ref(),
465 // Now comes the rote stuff:
466 hir::ExprRepeat(ref v, count) => {
467 let c = &cx.tcx.hir.body(count).value;
468 let def_id = cx.tcx.hir.body_owner_def_id(count);
469 let substs = Substs::identity_for_item(cx.tcx.global_tcx(), def_id);
470 let count = match cx.tcx.at(c.span).const_eval(cx.param_env.and((def_id, substs))) {
471 Ok(ConstVal::Integral(ConstInt::Usize(u))) => u,
472 Ok(other) => bug!("constant evaluation of repeat count yielded {:?}", other),
473 Err(s) => cx.fatal_const_eval_err(&s, c.span, "expression")
481 hir::ExprRet(ref v) => ExprKind::Return { value: v.to_ref() },
482 hir::ExprBreak(dest, ref value) => {
483 match dest.target_id {
484 hir::ScopeTarget::Block(target_id) |
485 hir::ScopeTarget::Loop(hir::LoopIdResult::Ok(target_id)) => ExprKind::Break {
486 label: CodeExtent::Misc(target_id),
487 value: value.to_ref(),
489 hir::ScopeTarget::Loop(hir::LoopIdResult::Err(err)) =>
490 bug!("invalid loop id for break: {}", err)
493 hir::ExprAgain(dest) => {
494 match dest.target_id {
495 hir::ScopeTarget::Block(_) => bug!("cannot continue to blocks"),
496 hir::ScopeTarget::Loop(hir::LoopIdResult::Ok(loop_id)) => ExprKind::Continue {
497 label: CodeExtent::Misc(loop_id),
499 hir::ScopeTarget::Loop(hir::LoopIdResult::Err(err)) =>
500 bug!("invalid loop id for continue: {}", err)
503 hir::ExprMatch(ref discr, ref arms, _) => {
505 discriminant: discr.to_ref(),
506 arms: arms.iter().map(|a| convert_arm(cx, a)).collect(),
509 hir::ExprIf(ref cond, ref then, ref otherwise) => {
511 condition: cond.to_ref(),
513 otherwise: otherwise.to_ref(),
516 hir::ExprWhile(ref cond, ref body, _) => {
518 condition: Some(cond.to_ref()),
519 body: block::to_expr_ref(cx, body),
522 hir::ExprLoop(ref body, _, _) => {
525 body: block::to_expr_ref(cx, body),
528 hir::ExprField(ref source, name) => {
529 let index = match cx.tables().expr_ty_adjusted(source).sty {
530 ty::TyAdt(adt_def, _) => adt_def.variants[0].index_of_field_named(name.node),
531 ref ty => span_bug!(expr.span, "field of non-ADT: {:?}", ty),
534 index.unwrap_or_else(|| {
535 span_bug!(expr.span, "no index found for field `{}`", name.node)
538 lhs: source.to_ref(),
539 name: Field::new(index),
542 hir::ExprTupField(ref source, index) => {
544 lhs: source.to_ref(),
545 name: Field::new(index.node as usize),
548 hir::ExprCast(ref source, _) => {
549 // Check to see if this cast is a "coercion cast", where the cast is actually done
550 // using a coercion (or is a no-op).
551 if let Some(&TyCastKind::CoercionCast) = cx.tables().cast_kinds.get(&source.id) {
552 // Convert the lexpr to a vexpr.
553 ExprKind::Use { source: source.to_ref() }
555 ExprKind::Cast { source: source.to_ref() }
558 hir::ExprType(ref source, _) => return source.make_mirror(cx),
559 hir::ExprBox(ref value) => {
561 value: value.to_ref(),
562 value_extents: CodeExtent::Misc(value.id),
565 hir::ExprArray(ref fields) => ExprKind::Array { fields: fields.to_ref() },
566 hir::ExprTup(ref fields) => ExprKind::Tuple { fields: fields.to_ref() },
570 temp_lifetime: temp_lifetime,
577 fn method_callee<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
579 custom_callee: Option<(DefId, &'tcx Substs<'tcx>)>)
581 let temp_lifetime = cx.region_maps.temporary_scope(expr.id);
582 let (def_id, substs) = custom_callee.unwrap_or_else(|| {
583 cx.tables().validate_hir_id(expr.hir_id);
584 (cx.tables().type_dependent_defs[&expr.hir_id.local_id].def_id(),
585 cx.tables().node_substs(expr.hir_id))
588 temp_lifetime: temp_lifetime,
589 ty: cx.tcx().mk_fn_def(def_id, substs),
591 kind: ExprKind::Literal {
592 literal: Literal::Value {
593 value: ConstVal::Function(def_id, substs),
599 fn to_borrow_kind(m: hir::Mutability) -> BorrowKind {
601 hir::MutMutable => BorrowKind::Mut,
602 hir::MutImmutable => BorrowKind::Shared,
606 fn convert_arm<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, arm: &'tcx hir::Arm) -> Arm<'tcx> {
608 patterns: arm.pats.iter().map(|p| {
609 Pattern::from_hir(cx.tcx.global_tcx(),
610 cx.param_env.and(cx.identity_substs),
614 guard: arm.guard.to_ref(),
615 body: arm.body.to_ref(),
619 fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
620 expr: &'tcx hir::Expr,
623 let substs = cx.tables().node_substs(expr.hir_id);
625 // A regular function, constructor function or a constant.
627 Def::Method(def_id) |
628 Def::StructCtor(def_id, CtorKind::Fn) |
629 Def::VariantCtor(def_id, CtorKind::Fn) => ExprKind::Literal {
630 literal: Literal::Value {
631 value: ConstVal::Function(def_id, substs),
636 Def::AssociatedConst(def_id) => ExprKind::Literal {
637 literal: Literal::Item {
643 Def::StructCtor(def_id, CtorKind::Const) |
644 Def::VariantCtor(def_id, CtorKind::Const) => {
645 match cx.tables().node_id_to_type(expr.hir_id).sty {
646 // A unit struct/variant which is used as a value.
647 // We return a completely different ExprKind here to account for this special case.
648 ty::TyAdt(adt_def, substs) => {
651 variant_index: adt_def.variant_index_with_id(def_id),
657 ref sty => bug!("unexpected sty: {:?}", sty),
661 Def::Static(node_id, _) => ExprKind::StaticRef { id: node_id },
663 Def::Local(..) | Def::Upvar(..) => convert_var(cx, expr, def),
665 _ => span_bug!(expr.span, "def `{:?}` not yet implemented", def),
669 fn convert_var<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
670 expr: &'tcx hir::Expr,
673 let temp_lifetime = cx.region_maps.temporary_scope(expr.id);
676 Def::Local(def_id) => {
677 let node_id = cx.tcx.hir.as_local_node_id(def_id).unwrap();
678 ExprKind::VarRef { id: node_id }
681 Def::Upvar(def_id, index, closure_expr_id) => {
682 let id_var = cx.tcx.hir.as_local_node_id(def_id).unwrap();
683 debug!("convert_var(upvar({:?}, {:?}, {:?}))",
687 let var_ty = cx.tables()
688 .node_id_to_type(cx.tcx.hir.node_to_hir_id(id_var));
690 // FIXME free regions in closures are not right
691 let closure_ty = cx.tables()
692 .node_id_to_type(cx.tcx.hir.node_to_hir_id(closure_expr_id));
694 // FIXME we're just hard-coding the idea that the
695 // signature will be &self or &mut self and hence will
696 // have a bound region with number 0
697 let closure_def_id = cx.tcx.hir.local_def_id(closure_expr_id);
698 let region = ty::ReFree(ty::FreeRegion {
699 scope: closure_def_id,
700 bound_region: ty::BoundRegion::BrAnon(0),
702 let region = cx.tcx.mk_region(region);
704 let self_expr = match cx.tcx.closure_kind(closure_def_id) {
705 ty::ClosureKind::Fn => {
706 let ref_closure_ty = cx.tcx.mk_ref(region,
709 mutbl: hir::MutImmutable,
713 temp_lifetime: temp_lifetime,
715 kind: ExprKind::Deref {
718 temp_lifetime: temp_lifetime,
720 kind: ExprKind::SelfRef,
726 ty::ClosureKind::FnMut => {
727 let ref_closure_ty = cx.tcx.mk_ref(region,
730 mutbl: hir::MutMutable,
734 temp_lifetime: temp_lifetime,
736 kind: ExprKind::Deref {
739 temp_lifetime: temp_lifetime,
741 kind: ExprKind::SelfRef,
746 ty::ClosureKind::FnOnce => {
749 temp_lifetime: temp_lifetime,
751 kind: ExprKind::SelfRef,
756 // at this point we have `self.n`, which loads up the upvar
757 let field_kind = ExprKind::Field {
758 lhs: self_expr.to_ref(),
759 name: Field::new(index),
762 // ...but the upvar might be an `&T` or `&mut T` capture, at which
763 // point we need an implicit deref
764 let upvar_id = ty::UpvarId {
766 closure_expr_id: closure_expr_id,
768 match cx.tables().upvar_capture(upvar_id) {
769 ty::UpvarCapture::ByValue => field_kind,
770 ty::UpvarCapture::ByRef(borrow) => {
773 temp_lifetime: temp_lifetime,
774 ty: cx.tcx.mk_ref(borrow.region,
777 mutbl: borrow.kind.to_mutbl_lossy(),
787 _ => span_bug!(expr.span, "type of & not region"),
792 fn bin_op(op: hir::BinOp_) -> BinOp {
794 hir::BinOp_::BiAdd => BinOp::Add,
795 hir::BinOp_::BiSub => BinOp::Sub,
796 hir::BinOp_::BiMul => BinOp::Mul,
797 hir::BinOp_::BiDiv => BinOp::Div,
798 hir::BinOp_::BiRem => BinOp::Rem,
799 hir::BinOp_::BiBitXor => BinOp::BitXor,
800 hir::BinOp_::BiBitAnd => BinOp::BitAnd,
801 hir::BinOp_::BiBitOr => BinOp::BitOr,
802 hir::BinOp_::BiShl => BinOp::Shl,
803 hir::BinOp_::BiShr => BinOp::Shr,
804 hir::BinOp_::BiEq => BinOp::Eq,
805 hir::BinOp_::BiLt => BinOp::Lt,
806 hir::BinOp_::BiLe => BinOp::Le,
807 hir::BinOp_::BiNe => BinOp::Ne,
808 hir::BinOp_::BiGe => BinOp::Ge,
809 hir::BinOp_::BiGt => BinOp::Gt,
810 _ => bug!("no equivalent for ast binop {:?}", op),
814 fn overloaded_operator<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
815 expr: &'tcx hir::Expr,
816 args: Vec<ExprRef<'tcx>>)
818 let fun = method_callee(cx, expr, None);
826 fn overloaded_lvalue<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
827 expr: &'tcx hir::Expr,
829 custom_callee: Option<(DefId, &'tcx Substs<'tcx>)>,
830 args: Vec<ExprRef<'tcx>>)
832 // For an overloaded *x or x[y] expression of type T, the method
833 // call returns an &T and we must add the deref so that the types
834 // line up (this is because `*x` and `x[y]` represent lvalues):
836 let recv_ty = match args[0] {
837 ExprRef::Hair(e) => cx.tables().expr_ty_adjusted(e),
838 ExprRef::Mirror(ref e) => e.ty
841 // Reconstruct the output assuming it's a reference with the
842 // same region and mutability as the receiver. This holds for
843 // `Deref(Mut)::Deref(_mut)` and `Index(Mut)::index(_mut)`.
844 let (region, mt) = match recv_ty.sty {
845 ty::TyRef(region, mt) => (region, mt),
846 _ => span_bug!(expr.span, "overloaded_lvalue: receiver is not a reference"),
848 let ref_ty = cx.tcx.mk_ref(region, ty::TypeAndMut {
853 // construct the complete expression `foo()` for the overloaded call,
854 // which will yield the &T type
855 let temp_lifetime = cx.region_maps.temporary_scope(expr.id);
856 let fun = method_callee(cx, expr, custom_callee);
857 let ref_expr = Expr {
858 temp_lifetime: temp_lifetime,
861 kind: ExprKind::Call {
868 // construct and return a deref wrapper `*foo()`
869 ExprKind::Deref { arg: ref_expr.to_ref() }
872 fn capture_freevar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
873 closure_expr: &'tcx hir::Expr,
874 freevar: &hir::Freevar,
875 freevar_ty: Ty<'tcx>)
877 let id_var = cx.tcx.hir.as_local_node_id(freevar.def.def_id()).unwrap();
878 let upvar_id = ty::UpvarId {
880 closure_expr_id: closure_expr.id,
882 let upvar_capture = cx.tables().upvar_capture(upvar_id);
883 let temp_lifetime = cx.region_maps.temporary_scope(closure_expr.id);
884 let var_ty = cx.tables()
885 .node_id_to_type(cx.tcx.hir.node_to_hir_id(id_var));
886 let captured_var = Expr {
887 temp_lifetime: temp_lifetime,
889 span: closure_expr.span,
890 kind: convert_var(cx, closure_expr, freevar.def),
892 match upvar_capture {
893 ty::UpvarCapture::ByValue => captured_var.to_ref(),
894 ty::UpvarCapture::ByRef(upvar_borrow) => {
895 let borrow_kind = match upvar_borrow.kind {
896 ty::BorrowKind::ImmBorrow => BorrowKind::Shared,
897 ty::BorrowKind::UniqueImmBorrow => BorrowKind::Unique,
898 ty::BorrowKind::MutBorrow => BorrowKind::Mut,
901 temp_lifetime: temp_lifetime,
903 span: closure_expr.span,
904 kind: ExprKind::Borrow {
905 region: upvar_borrow.region,
906 borrow_kind: borrow_kind,
907 arg: captured_var.to_ref(),
914 /// Converts a list of named fields (i.e. for struct-like struct/enum ADTs) into FieldExprRef.
915 fn field_refs<'tcx>(variant: &'tcx VariantDef,
916 fields: &'tcx [hir::Field])
917 -> Vec<FieldExprRef<'tcx>> {
921 name: Field::new(variant.index_of_field_named(field.name.node).unwrap()),
922 expr: field.expr.to_ref(),