]> git.lizzy.rs Git - rust.git/blob - src/librustc_typeck/check/upvar.rs
rustc: replace Res in hir::Upvar with only Local/Upvar data.
[rust.git] / src / librustc_typeck / check / upvar.rs
1 //! ### Inferring borrow kinds for upvars
2 //!
3 //! Whenever there is a closure expression, we need to determine how each
4 //! upvar is used. We do this by initially assigning each upvar an
5 //! immutable "borrow kind" (see `ty::BorrowKind` for details) and then
6 //! "escalating" the kind as needed. The borrow kind proceeds according to
7 //! the following lattice:
8 //!
9 //!     ty::ImmBorrow -> ty::UniqueImmBorrow -> ty::MutBorrow
10 //!
11 //! So, for example, if we see an assignment `x = 5` to an upvar `x`, we
12 //! will promote its borrow kind to mutable borrow. If we see an `&mut x`
13 //! we'll do the same. Naturally, this applies not just to the upvar, but
14 //! to everything owned by `x`, so the result is the same for something
15 //! like `x.f = 5` and so on (presuming `x` is not a borrowed pointer to a
16 //! struct). These adjustments are performed in
17 //! `adjust_upvar_borrow_kind()` (you can trace backwards through the code
18 //! from there).
19 //!
20 //! The fact that we are inferring borrow kinds as we go results in a
21 //! semi-hacky interaction with mem-categorization. In particular,
22 //! mem-categorization will query the current borrow kind as it
23 //! categorizes, and we'll return the *current* value, but this may get
24 //! adjusted later. Therefore, in this module, we generally ignore the
25 //! borrow kind (and derived mutabilities) that are returned from
26 //! mem-categorization, since they may be inaccurate. (Another option
27 //! would be to use a unification scheme, where instead of returning a
28 //! concrete borrow kind like `ty::ImmBorrow`, we return a
29 //! `ty::InferBorrow(upvar_id)` or something like that, but this would
30 //! then mean that all later passes would have to check for these figments
31 //! and report an error, and it just seems like more mess in the end.)
32
33 use super::FnCtxt;
34
35 use crate::middle::expr_use_visitor as euv;
36 use crate::middle::mem_categorization as mc;
37 use crate::middle::mem_categorization::Categorization;
38 use rustc::hir;
39 use rustc::hir::def_id::DefId;
40 use rustc::hir::def_id::LocalDefId;
41 use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
42 use rustc::infer::UpvarRegion;
43 use rustc::ty::{self, Ty, TyCtxt, UpvarSubsts};
44 use syntax::ast;
45 use syntax_pos::Span;
46
47 impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
48     pub fn closure_analyze(&self, body: &'gcx hir::Body) {
49         InferBorrowKindVisitor { fcx: self }.visit_body(body);
50
51         // it's our job to process these.
52         assert!(self.deferred_call_resolutions.borrow().is_empty());
53     }
54 }
55
56 struct InferBorrowKindVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
57     fcx: &'a FnCtxt<'a, 'gcx, 'tcx>,
58 }
59
60 impl<'a, 'gcx, 'tcx> Visitor<'gcx> for InferBorrowKindVisitor<'a, 'gcx, 'tcx> {
61     fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'gcx> {
62         NestedVisitorMap::None
63     }
64
65     fn visit_expr(&mut self, expr: &'gcx hir::Expr) {
66         if let hir::ExprKind::Closure(cc, _, body_id, _, _) = expr.node {
67             let body = self.fcx.tcx.hir().body(body_id);
68             self.visit_body(body);
69             self.fcx
70                 .analyze_closure(expr.hir_id, expr.span, body, cc);
71         }
72
73         intravisit::walk_expr(self, expr);
74     }
75 }
76
77 impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
78     fn analyze_closure(
79         &self,
80         closure_hir_id: hir::HirId,
81         span: Span,
82         body: &hir::Body,
83         capture_clause: hir::CaptureClause,
84     ) {
85         /*!
86          * Analysis starting point.
87          */
88
89         debug!(
90             "analyze_closure(id={:?}, body.id={:?})",
91             closure_hir_id,
92             body.id()
93         );
94
95         // Extract the type of the closure.
96         let ty = self.node_ty(closure_hir_id);
97         let (closure_def_id, substs) = match ty.sty {
98             ty::Closure(def_id, substs) => (def_id, UpvarSubsts::Closure(substs)),
99             ty::Generator(def_id, substs, _) => (def_id, UpvarSubsts::Generator(substs)),
100             ty::Error => {
101                 // #51714: skip analysis when we have already encountered type errors
102                 return;
103             }
104             _ => {
105                 span_bug!(
106                     span,
107                     "type of closure expr {:?} is not a closure {:?}",
108                     closure_hir_id,
109                     ty
110                 );
111             }
112         };
113
114         let infer_kind = if let UpvarSubsts::Closure(closure_substs) = substs {
115             if self.closure_kind(closure_def_id, closure_substs).is_none() {
116                 Some(closure_substs)
117             } else {
118                 None
119             }
120         } else {
121             None
122         };
123
124         if let Some(upvars) = self.tcx.upvars(closure_def_id) {
125             let mut upvar_list: Vec<ty::UpvarId> = Vec::with_capacity(upvars.len());
126             for upvar in upvars.iter() {
127                 let upvar_id = ty::UpvarId {
128                     var_path: ty::UpvarPath {
129                         hir_id: upvar.var_id,
130                     },
131                     closure_expr_id: LocalDefId::from_def_id(closure_def_id),
132                 };
133                 debug!("seed upvar_id {:?}", upvar_id);
134                 // Adding the upvar Id to the list of Upvars, which will be added
135                 // to the map for the closure at the end of the for loop.
136                 upvar_list.push(upvar_id);
137
138                 let capture_kind = match capture_clause {
139                     hir::CaptureByValue => ty::UpvarCapture::ByValue,
140                     hir::CaptureByRef => {
141                         let origin = UpvarRegion(upvar_id, span);
142                         let upvar_region = self.next_region_var(origin);
143                         let upvar_borrow = ty::UpvarBorrow {
144                             kind: ty::ImmBorrow,
145                             region: upvar_region,
146                         };
147                         ty::UpvarCapture::ByRef(upvar_borrow)
148                     }
149                 };
150
151                 self.tables
152                     .borrow_mut()
153                     .upvar_capture_map
154                     .insert(upvar_id, capture_kind);
155             }
156             // Add the vector of upvars to the map keyed with the closure id.
157             // This gives us an easier access to them without having to call
158             // tcx.upvars again..
159             if !upvar_list.is_empty() {
160                 self.tables
161                     .borrow_mut()
162                     .upvar_list
163                     .insert(closure_def_id, upvar_list);
164             }
165         }
166
167         let body_owner_def_id = self.tcx.hir().body_owner_def_id(body.id());
168         let region_scope_tree = &self.tcx.region_scope_tree(body_owner_def_id);
169         let mut delegate = InferBorrowKind {
170             fcx: self,
171             closure_def_id: closure_def_id,
172             current_closure_kind: ty::ClosureKind::LATTICE_BOTTOM,
173             current_origin: None,
174             adjust_upvar_captures: ty::UpvarCaptureMap::default(),
175         };
176         euv::ExprUseVisitor::with_infer(
177             &mut delegate,
178             &self.infcx,
179             self.param_env,
180             region_scope_tree,
181             &self.tables.borrow(),
182         )
183         .consume_body(body);
184
185         if let Some(closure_substs) = infer_kind {
186             // Unify the (as yet unbound) type variable in the closure
187             // substs with the kind we inferred.
188             let inferred_kind = delegate.current_closure_kind;
189             let closure_kind_ty = closure_substs.closure_kind_ty(closure_def_id, self.tcx);
190             self.demand_eqtype(span, inferred_kind.to_ty(self.tcx), closure_kind_ty);
191
192             // If we have an origin, store it.
193             if let Some(origin) = delegate.current_origin {
194                 self.tables
195                     .borrow_mut()
196                     .closure_kind_origins_mut()
197                     .insert(closure_hir_id, origin);
198             }
199         }
200
201         self.tables
202             .borrow_mut()
203             .upvar_capture_map
204             .extend(delegate.adjust_upvar_captures);
205
206         // Now that we've analyzed the closure, we know how each
207         // variable is borrowed, and we know what traits the closure
208         // implements (Fn vs FnMut etc). We now have some updates to do
209         // with that information.
210         //
211         // Note that no closure type C may have an upvar of type C
212         // (though it may reference itself via a trait object). This
213         // results from the desugaring of closures to a struct like
214         // `Foo<..., UV0...UVn>`. If one of those upvars referenced
215         // C, then the type would have infinite size (and the
216         // inference algorithm will reject it).
217
218         // Equate the type variables for the upvars with the actual types.
219         let final_upvar_tys = self.final_upvar_tys(closure_hir_id);
220         debug!(
221             "analyze_closure: id={:?} substs={:?} final_upvar_tys={:?}",
222             closure_hir_id, substs, final_upvar_tys
223         );
224         for (upvar_ty, final_upvar_ty) in substs
225             .upvar_tys(closure_def_id, self.tcx)
226             .zip(final_upvar_tys)
227         {
228             self.demand_suptype(span, upvar_ty, final_upvar_ty);
229         }
230
231         // If we are also inferred the closure kind here,
232         // process any deferred resolutions.
233         let deferred_call_resolutions = self.remove_deferred_call_resolutions(closure_def_id);
234         for deferred_call_resolution in deferred_call_resolutions {
235             deferred_call_resolution.resolve(self);
236         }
237     }
238
239     // Returns a list of `ClosureUpvar`s for each upvar.
240     fn final_upvar_tys(&self, closure_id: hir::HirId) -> Vec<Ty<'tcx>> {
241         // Presently an unboxed closure type cannot "escape" out of a
242         // function, so we will only encounter ones that originated in the
243         // local crate or were inlined into it along with some function.
244         // This may change if abstract return types of some sort are
245         // implemented.
246         let tcx = self.tcx;
247         let closure_def_id = tcx.hir().local_def_id_from_hir_id(closure_id);
248
249         tcx.upvars(closure_def_id).iter().flat_map(|upvars| {
250             upvars
251                 .iter()
252                 .map(|upvar| {
253                     let upvar_ty = self.node_ty(upvar.var_id);
254                     let upvar_id = ty::UpvarId {
255                         var_path: ty::UpvarPath { hir_id: upvar.var_id },
256                         closure_expr_id: LocalDefId::from_def_id(closure_def_id),
257                     };
258                     let capture = self.tables.borrow().upvar_capture(upvar_id);
259
260                     debug!(
261                         "var_id={:?} upvar_ty={:?} capture={:?}",
262                         upvar.var_id, upvar_ty, capture
263                     );
264
265                     match capture {
266                         ty::UpvarCapture::ByValue => upvar_ty,
267                         ty::UpvarCapture::ByRef(borrow) => tcx.mk_ref(
268                             borrow.region,
269                             ty::TypeAndMut {
270                                 ty: upvar_ty,
271                                 mutbl: borrow.kind.to_mutbl_lossy(),
272                             },
273                         ),
274                     }
275                 })
276         })
277             .collect()
278     }
279 }
280
281 struct InferBorrowKind<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
282     fcx: &'a FnCtxt<'a, 'gcx, 'tcx>,
283
284     // The def-id of the closure whose kind and upvar accesses are being inferred.
285     closure_def_id: DefId,
286
287     // The kind that we have inferred that the current closure
288     // requires. Note that we *always* infer a minimal kind, even if
289     // we don't always *use* that in the final result (i.e., sometimes
290     // we've taken the closure kind from the expectations instead, and
291     // for generators we don't even implement the closure traits
292     // really).
293     current_closure_kind: ty::ClosureKind,
294
295     // If we modified `current_closure_kind`, this field contains a `Some()` with the
296     // variable access that caused us to do so.
297     current_origin: Option<(Span, ast::Name)>,
298
299     // For each upvar that we access, we track the minimal kind of
300     // access we need (ref, ref mut, move, etc).
301     adjust_upvar_captures: ty::UpvarCaptureMap<'tcx>,
302 }
303
304 impl<'a, 'gcx, 'tcx> InferBorrowKind<'a, 'gcx, 'tcx> {
305     fn adjust_upvar_borrow_kind_for_consume(
306         &mut self,
307         cmt: &mc::cmt_<'tcx>,
308         mode: euv::ConsumeMode,
309     ) {
310         debug!(
311             "adjust_upvar_borrow_kind_for_consume(cmt={:?}, mode={:?})",
312             cmt, mode
313         );
314
315         // we only care about moves
316         match mode {
317             euv::Copy => {
318                 return;
319             }
320             euv::Move(_) => {}
321         }
322
323         let tcx = self.fcx.tcx;
324
325         // watch out for a move of the deref of a borrowed pointer;
326         // for that to be legal, the upvar would have to be borrowed
327         // by value instead
328         let guarantor = cmt.guarantor();
329         debug!(
330             "adjust_upvar_borrow_kind_for_consume: guarantor={:?}",
331             guarantor
332         );
333         debug!(
334             "adjust_upvar_borrow_kind_for_consume: guarantor.cat={:?}",
335             guarantor.cat
336         );
337         if let Categorization::Deref(_, mc::BorrowedPtr(..)) = guarantor.cat {
338             debug!(
339                 "adjust_upvar_borrow_kind_for_consume: found deref with note {:?}",
340                 cmt.note
341             );
342             match guarantor.note {
343                 mc::NoteUpvarRef(upvar_id) => {
344                     debug!(
345                         "adjust_upvar_borrow_kind_for_consume: \
346                          setting upvar_id={:?} to by value",
347                         upvar_id
348                     );
349
350                     // to move out of an upvar, this must be a FnOnce closure
351                     self.adjust_closure_kind(
352                         upvar_id.closure_expr_id,
353                         ty::ClosureKind::FnOnce,
354                         guarantor.span,
355                         var_name(tcx, upvar_id.var_path.hir_id),
356                     );
357
358                     self.adjust_upvar_captures
359                         .insert(upvar_id, ty::UpvarCapture::ByValue);
360                 }
361                 mc::NoteClosureEnv(upvar_id) => {
362                     // we get just a closureenv ref if this is a
363                     // `move` closure, or if the upvar has already
364                     // been inferred to by-value. In any case, we
365                     // must still adjust the kind of the closure
366                     // to be a FnOnce closure to permit moves out
367                     // of the environment.
368                     self.adjust_closure_kind(
369                         upvar_id.closure_expr_id,
370                         ty::ClosureKind::FnOnce,
371                         guarantor.span,
372                         var_name(tcx, upvar_id.var_path.hir_id),
373                     );
374                 }
375                 mc::NoteIndex | mc::NoteNone => {}
376             }
377         }
378     }
379
380     /// Indicates that `cmt` is being directly mutated (e.g., assigned
381     /// to). If cmt contains any by-ref upvars, this implies that
382     /// those upvars must be borrowed using an `&mut` borrow.
383     fn adjust_upvar_borrow_kind_for_mut(&mut self, cmt: &mc::cmt_<'tcx>) {
384         debug!("adjust_upvar_borrow_kind_for_mut(cmt={:?})", cmt);
385
386         match cmt.cat.clone() {
387             Categorization::Deref(base, mc::Unique)
388             | Categorization::Interior(base, _)
389             | Categorization::Downcast(base, _) => {
390                 // Interior or owned data is mutable if base is
391                 // mutable, so iterate to the base.
392                 self.adjust_upvar_borrow_kind_for_mut(&base);
393             }
394
395             Categorization::Deref(base, mc::BorrowedPtr(..)) => {
396                 if !self.try_adjust_upvar_deref(cmt, ty::MutBorrow) {
397                     // assignment to deref of an `&mut`
398                     // borrowed pointer implies that the
399                     // pointer itself must be unique, but not
400                     // necessarily *mutable*
401                     self.adjust_upvar_borrow_kind_for_unique(&base);
402                 }
403             }
404
405             Categorization::Deref(_, mc::UnsafePtr(..))
406             | Categorization::StaticItem
407             | Categorization::ThreadLocal(..)
408             | Categorization::Rvalue(..)
409             | Categorization::Local(_)
410             | Categorization::Upvar(..) => {
411                 return;
412             }
413         }
414     }
415
416     fn adjust_upvar_borrow_kind_for_unique(&mut self, cmt: &mc::cmt_<'tcx>) {
417         debug!("adjust_upvar_borrow_kind_for_unique(cmt={:?})", cmt);
418
419         match cmt.cat.clone() {
420             Categorization::Deref(base, mc::Unique)
421             | Categorization::Interior(base, _)
422             | Categorization::Downcast(base, _) => {
423                 // Interior or owned data is unique if base is
424                 // unique.
425                 self.adjust_upvar_borrow_kind_for_unique(&base);
426             }
427
428             Categorization::Deref(base, mc::BorrowedPtr(..)) => {
429                 if !self.try_adjust_upvar_deref(cmt, ty::UniqueImmBorrow) {
430                     // for a borrowed pointer to be unique, its
431                     // base must be unique
432                     self.adjust_upvar_borrow_kind_for_unique(&base);
433                 }
434             }
435
436             Categorization::Deref(_, mc::UnsafePtr(..))
437             | Categorization::StaticItem
438             | Categorization::ThreadLocal(..)
439             | Categorization::Rvalue(..)
440             | Categorization::Local(_)
441             | Categorization::Upvar(..) => {}
442         }
443     }
444
445     fn try_adjust_upvar_deref(
446         &mut self,
447         cmt: &mc::cmt_<'tcx>,
448         borrow_kind: ty::BorrowKind,
449     ) -> bool {
450         assert!(match borrow_kind {
451             ty::MutBorrow => true,
452             ty::UniqueImmBorrow => true,
453
454             // imm borrows never require adjusting any kinds, so we don't wind up here
455             ty::ImmBorrow => false,
456         });
457
458         let tcx = self.fcx.tcx;
459
460         match cmt.note {
461             mc::NoteUpvarRef(upvar_id) => {
462                 // if this is an implicit deref of an
463                 // upvar, then we need to modify the
464                 // borrow_kind of the upvar to make sure it
465                 // is inferred to mutable if necessary
466                 self.adjust_upvar_borrow_kind(upvar_id, borrow_kind);
467
468                 // also need to be in an FnMut closure since this is not an ImmBorrow
469                 self.adjust_closure_kind(
470                     upvar_id.closure_expr_id,
471                     ty::ClosureKind::FnMut,
472                     cmt.span,
473                     var_name(tcx, upvar_id.var_path.hir_id),
474                 );
475
476                 true
477             }
478             mc::NoteClosureEnv(upvar_id) => {
479                 // this kind of deref occurs in a `move` closure, or
480                 // for a by-value upvar; in either case, to mutate an
481                 // upvar, we need to be an FnMut closure
482                 self.adjust_closure_kind(
483                     upvar_id.closure_expr_id,
484                     ty::ClosureKind::FnMut,
485                     cmt.span,
486                     var_name(tcx, upvar_id.var_path.hir_id),
487                 );
488
489                 true
490             }
491             mc::NoteIndex | mc::NoteNone => false,
492         }
493     }
494
495     /// We infer the borrow_kind with which to borrow upvars in a stack closure.
496     /// The borrow_kind basically follows a lattice of `imm < unique-imm < mut`,
497     /// moving from left to right as needed (but never right to left).
498     /// Here the argument `mutbl` is the borrow_kind that is required by
499     /// some particular use.
500     fn adjust_upvar_borrow_kind(&mut self, upvar_id: ty::UpvarId, kind: ty::BorrowKind) {
501         let upvar_capture = self
502             .adjust_upvar_captures
503             .get(&upvar_id)
504             .cloned()
505             .unwrap_or_else(|| self.fcx.tables.borrow().upvar_capture(upvar_id));
506         debug!(
507             "adjust_upvar_borrow_kind(upvar_id={:?}, upvar_capture={:?}, kind={:?})",
508             upvar_id, upvar_capture, kind
509         );
510
511         match upvar_capture {
512             ty::UpvarCapture::ByValue => {
513                 // Upvar is already by-value, the strongest criteria.
514             }
515             ty::UpvarCapture::ByRef(mut upvar_borrow) => {
516                 match (upvar_borrow.kind, kind) {
517                     // Take RHS:
518                     (ty::ImmBorrow, ty::UniqueImmBorrow)
519                     | (ty::ImmBorrow, ty::MutBorrow)
520                     | (ty::UniqueImmBorrow, ty::MutBorrow) => {
521                         upvar_borrow.kind = kind;
522                         self.adjust_upvar_captures
523                             .insert(upvar_id, ty::UpvarCapture::ByRef(upvar_borrow));
524                     }
525                     // Take LHS:
526                     (ty::ImmBorrow, ty::ImmBorrow)
527                     | (ty::UniqueImmBorrow, ty::ImmBorrow)
528                     | (ty::UniqueImmBorrow, ty::UniqueImmBorrow)
529                     | (ty::MutBorrow, _) => {}
530                 }
531             }
532         }
533     }
534
535     fn adjust_closure_kind(
536         &mut self,
537         closure_id: LocalDefId,
538         new_kind: ty::ClosureKind,
539         upvar_span: Span,
540         var_name: ast::Name,
541     ) {
542         debug!(
543             "adjust_closure_kind(closure_id={:?}, new_kind={:?}, upvar_span={:?}, var_name={})",
544             closure_id, new_kind, upvar_span, var_name
545         );
546
547         // Is this the closure whose kind is currently being inferred?
548         if closure_id.to_def_id() != self.closure_def_id {
549             debug!("adjust_closure_kind: not current closure");
550             return;
551         }
552
553         // closures start out as `Fn`.
554         let existing_kind = self.current_closure_kind;
555
556         debug!(
557             "adjust_closure_kind: closure_id={:?}, existing_kind={:?}, new_kind={:?}",
558             closure_id, existing_kind, new_kind
559         );
560
561         match (existing_kind, new_kind) {
562             (ty::ClosureKind::Fn, ty::ClosureKind::Fn)
563             | (ty::ClosureKind::FnMut, ty::ClosureKind::Fn)
564             | (ty::ClosureKind::FnMut, ty::ClosureKind::FnMut)
565             | (ty::ClosureKind::FnOnce, _) => {
566                 // no change needed
567             }
568
569             (ty::ClosureKind::Fn, ty::ClosureKind::FnMut)
570             | (ty::ClosureKind::Fn, ty::ClosureKind::FnOnce)
571             | (ty::ClosureKind::FnMut, ty::ClosureKind::FnOnce) => {
572                 // new kind is stronger than the old kind
573                 self.current_closure_kind = new_kind;
574                 self.current_origin = Some((upvar_span, var_name));
575             }
576         }
577     }
578 }
579
580 impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'gcx, 'tcx> {
581     fn consume(
582         &mut self,
583         _consume_id: hir::HirId,
584         _consume_span: Span,
585         cmt: &mc::cmt_<'tcx>,
586         mode: euv::ConsumeMode,
587     ) {
588         debug!("consume(cmt={:?},mode={:?})", cmt, mode);
589         self.adjust_upvar_borrow_kind_for_consume(cmt, mode);
590     }
591
592     fn matched_pat(
593         &mut self,
594         _matched_pat: &hir::Pat,
595         _cmt: &mc::cmt_<'tcx>,
596         _mode: euv::MatchMode,
597     ) {
598     }
599
600     fn consume_pat(
601         &mut self,
602         _consume_pat: &hir::Pat,
603         cmt: &mc::cmt_<'tcx>,
604         mode: euv::ConsumeMode,
605     ) {
606         debug!("consume_pat(cmt={:?},mode={:?})", cmt, mode);
607         self.adjust_upvar_borrow_kind_for_consume(cmt, mode);
608     }
609
610     fn borrow(
611         &mut self,
612         borrow_id: hir::HirId,
613         _borrow_span: Span,
614         cmt: &mc::cmt_<'tcx>,
615         _loan_region: ty::Region<'tcx>,
616         bk: ty::BorrowKind,
617         _loan_cause: euv::LoanCause,
618     ) {
619         debug!(
620             "borrow(borrow_id={}, cmt={:?}, bk={:?})",
621             borrow_id, cmt, bk
622         );
623
624         match bk {
625             ty::ImmBorrow => {}
626             ty::UniqueImmBorrow => {
627                 self.adjust_upvar_borrow_kind_for_unique(cmt);
628             }
629             ty::MutBorrow => {
630                 self.adjust_upvar_borrow_kind_for_mut(cmt);
631             }
632         }
633     }
634
635     fn decl_without_init(&mut self, _id: hir::HirId, _span: Span) {}
636
637     fn mutate(
638         &mut self,
639         _assignment_id: hir::HirId,
640         _assignment_span: Span,
641         assignee_cmt: &mc::cmt_<'tcx>,
642         _mode: euv::MutateMode,
643     ) {
644         debug!("mutate(assignee_cmt={:?})", assignee_cmt);
645
646         self.adjust_upvar_borrow_kind_for_mut(assignee_cmt);
647     }
648 }
649
650 fn var_name(tcx: TyCtxt<'_, '_, '_>, var_hir_id: hir::HirId) -> ast::Name {
651     tcx.hir().name_by_hir_id(var_hir_id)
652 }