]> git.lizzy.rs Git - rust.git/blob - src/librustc_passes/rvalue_promotion.rs
Auto merge of #56838 - Aaron1011:fix/rustdoc-infer-unify, r=nikomatsakis
[rust.git] / src / librustc_passes / rvalue_promotion.rs
1 // Verifies that the types and values of const and static items
2 // are safe. The rules enforced by this module are:
3 //
4 // - For each *mutable* static item, it checks that its **type**:
5 //     - doesn't have a destructor
6 //     - doesn't own a box
7 //
8 // - For each *immutable* static item, it checks that its **value**:
9 //       - doesn't own a box
10 //       - doesn't contain a struct literal or a call to an enum variant / struct constructor where
11 //           - the type of the struct/enum has a dtor
12 //
13 // Rules Enforced Elsewhere:
14 // - It's not possible to take the address of a static item with unsafe interior. This is enforced
15 // by borrowck::gather_loans
16
17 use rustc::ty::cast::CastKind;
18 use rustc::hir::def::{Def, CtorKind};
19 use rustc::hir::def_id::DefId;
20 use rustc::middle::expr_use_visitor as euv;
21 use rustc::middle::mem_categorization as mc;
22 use rustc::middle::mem_categorization::Categorization;
23 use rustc::ty::{self, Ty, TyCtxt};
24 use rustc::ty::query::Providers;
25 use rustc::ty::subst::Substs;
26 use rustc::util::nodemap::{ItemLocalSet, NodeSet};
27 use rustc::hir;
28 use rustc_data_structures::sync::Lrc;
29 use syntax::ast;
30 use syntax_pos::{Span, DUMMY_SP};
31 use self::Promotability::*;
32 use std::ops::{BitAnd, BitAndAssign, BitOr};
33
34 pub fn provide(providers: &mut Providers) {
35     *providers = Providers {
36         rvalue_promotable_map,
37         const_is_rvalue_promotable_to_static,
38         ..*providers
39     };
40 }
41
42 pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
43     for &body_id in &tcx.hir().krate().body_ids {
44         let def_id = tcx.hir().body_owner_def_id(body_id);
45         tcx.const_is_rvalue_promotable_to_static(def_id);
46     }
47     tcx.sess.abort_if_errors();
48 }
49
50 fn const_is_rvalue_promotable_to_static<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
51                                                   def_id: DefId)
52                                                   -> bool
53 {
54     assert!(def_id.is_local());
55
56     let node_id = tcx.hir().as_local_node_id(def_id)
57         .expect("rvalue_promotable_map invoked with non-local def-id");
58     let body_id = tcx.hir().body_owned_by(node_id);
59     let body_hir_id = tcx.hir().node_to_hir_id(body_id.node_id);
60     tcx.rvalue_promotable_map(def_id).contains(&body_hir_id.local_id)
61 }
62
63 fn rvalue_promotable_map<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
64                                    def_id: DefId)
65                                    -> Lrc<ItemLocalSet>
66 {
67     let outer_def_id = tcx.closure_base_def_id(def_id);
68     if outer_def_id != def_id {
69         return tcx.rvalue_promotable_map(outer_def_id);
70     }
71
72     let mut visitor = CheckCrateVisitor {
73         tcx,
74         tables: &ty::TypeckTables::empty(None),
75         in_fn: false,
76         in_static: false,
77         mut_rvalue_borrows: Default::default(),
78         param_env: ty::ParamEnv::empty(),
79         identity_substs: Substs::empty(),
80         result: ItemLocalSet::default(),
81     };
82
83     // `def_id` should be a `Body` owner
84     let node_id = tcx.hir().as_local_node_id(def_id)
85         .expect("rvalue_promotable_map invoked with non-local def-id");
86     let body_id = tcx.hir().body_owned_by(node_id);
87     let _ = visitor.check_nested_body(body_id);
88
89     Lrc::new(visitor.result)
90 }
91
92 struct CheckCrateVisitor<'a, 'tcx: 'a> {
93     tcx: TyCtxt<'a, 'tcx, 'tcx>,
94     in_fn: bool,
95     in_static: bool,
96     mut_rvalue_borrows: NodeSet,
97     param_env: ty::ParamEnv<'tcx>,
98     identity_substs: &'tcx Substs<'tcx>,
99     tables: &'a ty::TypeckTables<'tcx>,
100     result: ItemLocalSet,
101 }
102
103 #[must_use]
104 #[derive(Debug, Clone, Copy, PartialEq)]
105 enum Promotability {
106     Promotable,
107     NotPromotable
108 }
109
110 impl BitAnd for Promotability {
111     type Output = Self;
112
113     fn bitand(self, rhs: Self) -> Self {
114         match (self, rhs) {
115             (Promotable, Promotable) => Promotable,
116             _ => NotPromotable,
117         }
118     }
119 }
120
121 impl BitAndAssign for Promotability {
122     fn bitand_assign(&mut self, rhs: Self) {
123         *self = *self & rhs
124     }
125 }
126
127 impl BitOr for Promotability {
128     type Output = Self;
129
130     fn bitor(self, rhs: Self) -> Self {
131         match (self, rhs) {
132             (NotPromotable, NotPromotable) => NotPromotable,
133             _ => Promotable,
134         }
135     }
136 }
137
138 impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
139     // Returns true iff all the values of the type are promotable.
140     fn type_promotability(&mut self, ty: Ty<'gcx>) -> Promotability {
141         debug!("type_promotability({})", ty);
142
143         if ty.is_freeze(self.tcx, self.param_env, DUMMY_SP) &&
144             !ty.needs_drop(self.tcx, self.param_env) {
145             Promotable
146         } else {
147             NotPromotable
148         }
149     }
150
151     fn handle_const_fn_call(
152         &mut self,
153         def_id: DefId,
154     ) -> Promotability {
155         if self.tcx.is_promotable_const_fn(def_id) {
156             Promotable
157         } else {
158             NotPromotable
159         }
160     }
161
162     /// While the `ExprUseVisitor` walks, we will identify which
163     /// expressions are borrowed, and insert their ids into this
164     /// table. Actually, we insert the "borrow-id", which is normally
165     /// the id of the expression being borrowed: but in the case of
166     /// `ref mut` borrows, the `id` of the pattern is
167     /// inserted. Therefore later we remove that entry from the table
168     /// and transfer it over to the value being matched. This will
169     /// then prevent said value from being promoted.
170     fn remove_mut_rvalue_borrow(&mut self, pat: &hir::Pat) -> bool {
171         let mut any_removed = false;
172         pat.walk(|p| {
173             any_removed |= self.mut_rvalue_borrows.remove(&p.id);
174             true
175         });
176         any_removed
177     }
178 }
179
180 impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
181     fn check_nested_body(&mut self, body_id: hir::BodyId) -> Promotability {
182         let item_id = self.tcx.hir().body_owner(body_id);
183         let item_def_id = self.tcx.hir().local_def_id(item_id);
184
185         let outer_in_fn = self.in_fn;
186         let outer_tables = self.tables;
187         let outer_param_env = self.param_env;
188         let outer_identity_substs = self.identity_substs;
189
190         self.in_fn = false;
191         self.in_static = false;
192
193         match self.tcx.hir().body_owner_kind(item_id) {
194             hir::BodyOwnerKind::Fn => self.in_fn = true,
195             hir::BodyOwnerKind::Static(_) => self.in_static = true,
196             _ => {}
197         };
198
199
200         self.tables = self.tcx.typeck_tables_of(item_def_id);
201         self.param_env = self.tcx.param_env(item_def_id);
202         self.identity_substs = Substs::identity_for_item(self.tcx, item_def_id);
203
204         let body = self.tcx.hir().body(body_id);
205
206         let tcx = self.tcx;
207         let param_env = self.param_env;
208         let region_scope_tree = self.tcx.region_scope_tree(item_def_id);
209         let tables = self.tables;
210         euv::ExprUseVisitor::new(self, tcx, param_env, &region_scope_tree, tables, None)
211             .consume_body(body);
212
213         let body_promotable = self.check_expr(&body.value);
214         self.in_fn = outer_in_fn;
215         self.tables = outer_tables;
216         self.param_env = outer_param_env;
217         self.identity_substs = outer_identity_substs;
218         body_promotable
219     }
220
221     fn check_stmt(&mut self, stmt: &'tcx hir::Stmt) -> Promotability {
222         match stmt.node {
223             hir::StmtKind::Decl(ref decl, _node_id) => {
224                 match &decl.node {
225                     hir::DeclKind::Local(local) => {
226                         if self.remove_mut_rvalue_borrow(&local.pat) {
227                             if let Some(init) = &local.init {
228                                 self.mut_rvalue_borrows.insert(init.id);
229                             }
230                         }
231
232                         if let Some(ref expr) = local.init {
233                             let _ = self.check_expr(&expr);
234                         }
235                         NotPromotable
236                     }
237                     // Item statements are allowed
238                     hir::DeclKind::Item(_) => Promotable
239                 }
240             }
241             hir::StmtKind::Expr(ref box_expr, _node_id) |
242             hir::StmtKind::Semi(ref box_expr, _node_id) => {
243                 let _ = self.check_expr(box_expr);
244                 NotPromotable
245             }
246         }
247     }
248
249     fn check_expr(&mut self, ex: &'tcx hir::Expr) -> Promotability {
250         let node_ty = self.tables.node_id_to_type(ex.hir_id);
251         let mut outer = check_expr_kind(self, ex, node_ty);
252         outer &= check_adjustments(self, ex);
253
254         // Handle borrows on (or inside the autorefs of) this expression.
255         if self.mut_rvalue_borrows.remove(&ex.id) {
256             outer = NotPromotable
257         }
258
259         if outer == Promotable {
260             self.result.insert(ex.hir_id.local_id);
261         }
262         outer
263     }
264
265     fn check_block(&mut self, block: &'tcx hir::Block) -> Promotability {
266         let mut iter_result = Promotable;
267         for index in block.stmts.iter() {
268             iter_result &= self.check_stmt(index);
269         }
270         match block.expr {
271             Some(ref box_expr) => iter_result & self.check_expr(&*box_expr),
272             None => iter_result,
273         }
274     }
275 }
276
277 /// This function is used to enforce the constraints on
278 /// const/static items. It walks through the *value*
279 /// of the item walking down the expression and evaluating
280 /// every nested expression. If the expression is not part
281 /// of a const/static item, it is qualified for promotion
282 /// instead of producing errors.
283 fn check_expr_kind<'a, 'tcx>(
284     v: &mut CheckCrateVisitor<'a, 'tcx>,
285     e: &'tcx hir::Expr, node_ty: Ty<'tcx>) -> Promotability {
286
287     let ty_result = match node_ty.sty {
288         ty::Adt(def, _) if def.has_dtor(v.tcx) => {
289             NotPromotable
290         }
291         _ => Promotable
292     };
293
294     let node_result = match e.node {
295         hir::ExprKind::Box(ref expr) => {
296             let _ = v.check_expr(&expr);
297             NotPromotable
298         }
299         hir::ExprKind::Unary(op, ref expr) => {
300             let expr_promotability = v.check_expr(expr);
301             if v.tables.is_method_call(e) || op == hir::UnDeref {
302                 return NotPromotable;
303             }
304             expr_promotability
305         }
306         hir::ExprKind::Binary(op, ref lhs, ref rhs) => {
307             let lefty = v.check_expr(lhs);
308             let righty = v.check_expr(rhs);
309             if v.tables.is_method_call(e) {
310                 return NotPromotable;
311             }
312             match v.tables.node_id_to_type(lhs.hir_id).sty {
313                 ty::RawPtr(_) | ty::FnPtr(..) => {
314                     assert!(op.node == hir::BinOpKind::Eq || op.node == hir::BinOpKind::Ne ||
315                             op.node == hir::BinOpKind::Le || op.node == hir::BinOpKind::Lt ||
316                             op.node == hir::BinOpKind::Ge || op.node == hir::BinOpKind::Gt);
317
318                     NotPromotable
319                 }
320                 _ => lefty & righty
321             }
322         }
323         hir::ExprKind::Cast(ref from, _) => {
324             let expr_promotability = v.check_expr(from);
325             debug!("Checking const cast(id={})", from.id);
326             match v.tables.cast_kinds().get(from.hir_id) {
327                 None => {
328                     v.tcx.sess.delay_span_bug(e.span, "no kind for cast");
329                     NotPromotable
330                 },
331                 Some(&CastKind::PtrAddrCast) | Some(&CastKind::FnPtrAddrCast) => {
332                     NotPromotable
333                 }
334                 _ => expr_promotability
335             }
336         }
337         hir::ExprKind::Path(ref qpath) => {
338             let def = v.tables.qpath_def(qpath, e.hir_id);
339             match def {
340                 Def::VariantCtor(..) | Def::StructCtor(..) |
341                 Def::Fn(..) | Def::Method(..) | Def::SelfCtor(..) => Promotable,
342
343                 // References to a static that are themselves within a static
344                 // are inherently promotable with the exception
345                 //  of "#[thread_local]" statics, which may not
346                 // outlive the current function
347                 Def::Static(did, _) => {
348
349                     if v.in_static {
350                         for attr in &v.tcx.get_attrs(did)[..] {
351                             if attr.check_name("thread_local") {
352                                 debug!("Reference to Static(id={:?}) is unpromotable \
353                                        due to a #[thread_local] attribute", did);
354                                 return NotPromotable;
355                             }
356                         }
357                         Promotable
358                     } else {
359                         debug!("Reference to Static(id={:?}) is unpromotable as it is not \
360                                referenced from a static", did);
361                         NotPromotable
362                     }
363                 }
364
365                 Def::Const(did) |
366                 Def::AssociatedConst(did) => {
367                     let promotable = if v.tcx.trait_of_item(did).is_some() {
368                         // Don't peek inside trait associated constants.
369                         NotPromotable
370                     } else if v.tcx.at(e.span).const_is_rvalue_promotable_to_static(did) {
371                         Promotable
372                     } else {
373                         NotPromotable
374                     };
375                     // Just in case the type is more specific than the definition,
376                     // e.g., impl associated const with type parameters, check it.
377                     // Also, trait associated consts are relaxed by this.
378                     promotable | v.type_promotability(node_ty)
379                 }
380                 _ => NotPromotable
381             }
382         }
383         hir::ExprKind::Call(ref callee, ref hirvec) => {
384             let mut call_result = v.check_expr(callee);
385             for index in hirvec.iter() {
386                 call_result &= v.check_expr(index);
387             }
388             let mut callee = &**callee;
389             loop {
390                 callee = match callee.node {
391                     hir::ExprKind::Block(ref block, _) => match block.expr {
392                         Some(ref tail) => &tail,
393                         None => break
394                     },
395                     _ => break
396                 };
397             }
398             // The callee is an arbitrary expression, it doesn't necessarily have a definition.
399             let def = if let hir::ExprKind::Path(ref qpath) = callee.node {
400                 v.tables.qpath_def(qpath, callee.hir_id)
401             } else {
402                 Def::Err
403             };
404             let def_result = match def {
405                 Def::StructCtor(_, CtorKind::Fn) |
406                 Def::VariantCtor(_, CtorKind::Fn) |
407                 Def::SelfCtor(..) => Promotable,
408                 Def::Fn(did) => v.handle_const_fn_call(did),
409                 Def::Method(did) => {
410                     match v.tcx.associated_item(did).container {
411                         ty::ImplContainer(_) => v.handle_const_fn_call(did),
412                         ty::TraitContainer(_) => NotPromotable,
413                     }
414                 }
415                 _ => NotPromotable,
416             };
417             def_result & call_result
418         }
419         hir::ExprKind::MethodCall(ref _pathsegment, ref _span, ref hirvec) => {
420             let mut method_call_result = Promotable;
421             for index in hirvec.iter() {
422                 method_call_result &= v.check_expr(index);
423             }
424             if let Some(def) = v.tables.type_dependent_defs().get(e.hir_id) {
425                 let def_id = def.def_id();
426                 match v.tcx.associated_item(def_id).container {
427                     ty::ImplContainer(_) => method_call_result & v.handle_const_fn_call(def_id),
428                     ty::TraitContainer(_) => NotPromotable,
429                 }
430             } else {
431                 v.tcx.sess.delay_span_bug(e.span, "no type-dependent def for method call");
432                 NotPromotable
433             }
434         }
435         hir::ExprKind::Struct(ref _qpath, ref hirvec, ref option_expr) => {
436             let mut struct_result = Promotable;
437             for index in hirvec.iter() {
438                 struct_result &= v.check_expr(&index.expr);
439             }
440             if let Some(ref expr) = *option_expr {
441                 struct_result &= v.check_expr(&expr);
442             }
443             if let ty::Adt(adt, ..) = v.tables.expr_ty(e).sty {
444                 // unsafe_cell_type doesn't necessarily exist with no_core
445                 if Some(adt.did) == v.tcx.lang_items().unsafe_cell_type() {
446                     return NotPromotable;
447                 }
448             }
449             struct_result
450         }
451
452         hir::ExprKind::Lit(_) => Promotable,
453
454         hir::ExprKind::AddrOf(_, ref expr) |
455         hir::ExprKind::Repeat(ref expr, _) => {
456             v.check_expr(&expr)
457         }
458
459         hir::ExprKind::Closure(_capture_clause, ref _box_fn_decl,
460                                body_id, _span, _option_generator_movability) => {
461             let nested_body_promotable = v.check_nested_body(body_id);
462             // Paths in constant contexts cannot refer to local variables,
463             // as there are none, and thus closures can't have upvars there.
464             if v.tcx.with_freevars(e.id, |fv| !fv.is_empty()) {
465                 NotPromotable
466             } else {
467                 nested_body_promotable
468             }
469         }
470
471         hir::ExprKind::Field(ref expr, _ident) => {
472             let expr_promotability = v.check_expr(&expr);
473             if let Some(def) = v.tables.expr_ty(expr).ty_adt_def() {
474                 if def.is_union() {
475                     return NotPromotable;
476                 }
477             }
478             expr_promotability
479         }
480
481         hir::ExprKind::Block(ref box_block, ref _option_label) => {
482             v.check_block(box_block)
483         }
484
485         hir::ExprKind::Index(ref lhs, ref rhs) => {
486             let lefty = v.check_expr(lhs);
487             let righty = v.check_expr(rhs);
488             if v.tables.is_method_call(e) {
489                 return NotPromotable;
490             }
491             lefty & righty
492         }
493
494         hir::ExprKind::Array(ref hirvec) => {
495             let mut array_result = Promotable;
496             for index in hirvec.iter() {
497                 array_result &= v.check_expr(index);
498             }
499             array_result
500         }
501
502         hir::ExprKind::Type(ref expr, ref _ty) => {
503             v.check_expr(&expr)
504         }
505
506         hir::ExprKind::Tup(ref hirvec) => {
507             let mut tup_result = Promotable;
508             for index in hirvec.iter() {
509                 tup_result &= v.check_expr(index);
510             }
511             tup_result
512         }
513
514
515         // Conditional control flow (possible to implement).
516         hir::ExprKind::Match(ref expr, ref hirvec_arm, ref _match_source) => {
517             // Compute the most demanding borrow from all the arms'
518             // patterns and set that on the discriminator.
519             let mut mut_borrow = false;
520             for pat in hirvec_arm.iter().flat_map(|arm| &arm.pats) {
521                 mut_borrow = v.remove_mut_rvalue_borrow(pat);
522             }
523             if mut_borrow {
524                 v.mut_rvalue_borrows.insert(expr.id);
525             }
526
527             let _ = v.check_expr(expr);
528             for index in hirvec_arm.iter() {
529                 let _ = v.check_expr(&*index.body);
530                 if let Some(hir::Guard::If(ref expr)) = index.guard {
531                     let _ = v.check_expr(&expr);
532                 }
533             }
534             NotPromotable
535         }
536
537         hir::ExprKind::If(ref lhs, ref rhs, ref option_expr) => {
538             let _ = v.check_expr(lhs);
539             let _ = v.check_expr(rhs);
540             if let Some(ref expr) = option_expr {
541                 let _ = v.check_expr(&expr);
542             }
543             NotPromotable
544         }
545
546         // Loops (not very meaningful in constants).
547         hir::ExprKind::While(ref expr, ref box_block, ref _option_label) => {
548             let _ = v.check_expr(expr);
549             let _ = v.check_block(box_block);
550             NotPromotable
551         }
552
553         hir::ExprKind::Loop(ref box_block, ref _option_label, ref _loop_source) => {
554             let _ = v.check_block(box_block);
555             NotPromotable
556         }
557
558         // More control flow (also not very meaningful).
559         hir::ExprKind::Break(_, ref option_expr) | hir::ExprKind::Ret(ref option_expr) => {
560             if let Some(ref expr) = *option_expr {
561                  let _ = v.check_expr(&expr);
562             }
563             NotPromotable
564         }
565
566         hir::ExprKind::Continue(_) => {
567             NotPromotable
568         }
569
570         // Generator expressions
571         hir::ExprKind::Yield(ref expr) => {
572             let _ = v.check_expr(&expr);
573             NotPromotable
574         }
575
576         // Expressions with side-effects.
577         hir::ExprKind::AssignOp(_, ref lhs, ref rhs) | hir::ExprKind::Assign(ref lhs, ref rhs) => {
578             let _ = v.check_expr(lhs);
579             let _ = v.check_expr(rhs);
580             NotPromotable
581         }
582
583         hir::ExprKind::InlineAsm(ref _inline_asm, ref hirvec_lhs, ref hirvec_rhs) => {
584             for index in hirvec_lhs.iter().chain(hirvec_rhs.iter()) {
585                 let _ = v.check_expr(index);
586             }
587             NotPromotable
588         }
589     };
590     ty_result & node_result
591 }
592
593 /// Check the adjustments of an expression
594 fn check_adjustments<'a, 'tcx>(
595     v: &mut CheckCrateVisitor<'a, 'tcx>,
596     e: &hir::Expr) -> Promotability {
597     use rustc::ty::adjustment::*;
598
599     let mut adjustments = v.tables.expr_adjustments(e).iter().peekable();
600     while let Some(adjustment) = adjustments.next() {
601         match adjustment.kind {
602             Adjust::NeverToAny |
603             Adjust::ReifyFnPointer |
604             Adjust::UnsafeFnPointer |
605             Adjust::ClosureFnPointer |
606             Adjust::MutToConstPointer |
607             Adjust::Borrow(_) |
608             Adjust::Unsize => {}
609
610             Adjust::Deref(_) => {
611                 if let Some(next_adjustment) = adjustments.peek() {
612                     if let Adjust::Borrow(_) = next_adjustment.kind {
613                         continue;
614                     }
615                 }
616                 return NotPromotable;
617             }
618         }
619     }
620     Promotable
621 }
622
623 impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> {
624     fn consume(&mut self,
625                _consume_id: ast::NodeId,
626                _consume_span: Span,
627                _cmt: &mc::cmt_,
628                _mode: euv::ConsumeMode) {}
629
630     fn borrow(&mut self,
631               borrow_id: ast::NodeId,
632               _borrow_span: Span,
633               cmt: &mc::cmt_<'tcx>,
634               _loan_region: ty::Region<'tcx>,
635               bk: ty::BorrowKind,
636               loan_cause: euv::LoanCause) {
637         debug!(
638             "borrow(borrow_id={:?}, cmt={:?}, bk={:?}, loan_cause={:?})",
639             borrow_id,
640             cmt,
641             bk,
642             loan_cause,
643         );
644
645         // Kind of hacky, but we allow Unsafe coercions in constants.
646         // These occur when we convert a &T or *T to a *U, as well as
647         // when making a thin pointer (e.g., `*T`) into a fat pointer
648         // (e.g., `*Trait`).
649         if let euv::LoanCause::AutoUnsafe = loan_cause {
650             return;
651         }
652
653         let mut cur = cmt;
654         loop {
655             match cur.cat {
656                 Categorization::ThreadLocal(..) |
657                 Categorization::Rvalue(..) => {
658                     if loan_cause == euv::MatchDiscriminant {
659                         // Ignore the dummy immutable borrow created by EUV.
660                         break;
661                     }
662                     if bk.to_mutbl_lossy() == hir::MutMutable {
663                         self.mut_rvalue_borrows.insert(borrow_id);
664                     }
665                     break;
666                 }
667                 Categorization::StaticItem => {
668                     break;
669                 }
670                 Categorization::Deref(ref cmt, _) |
671                 Categorization::Downcast(ref cmt, _) |
672                 Categorization::Interior(ref cmt, _) => {
673                     cur = cmt;
674                 }
675
676                 Categorization::Upvar(..) |
677                 Categorization::Local(..) => break,
678             }
679         }
680     }
681
682     fn decl_without_init(&mut self, _id: ast::NodeId, _span: Span) {}
683     fn mutate(&mut self,
684               _assignment_id: ast::NodeId,
685               _assignment_span: Span,
686               _assignee_cmt: &mc::cmt_,
687               _mode: euv::MutateMode) {
688     }
689
690     fn matched_pat(&mut self, _: &hir::Pat, _: &mc::cmt_, _: euv::MatchMode) {}
691
692     fn consume_pat(&mut self, _consume_pat: &hir::Pat, _cmt: &mc::cmt_, _mode: euv::ConsumeMode) {}
693 }