1 use crate::hir::def_id::DefId;
2 use crate::ty::subst::SubstsRef;
3 use crate::ty::{CanonicalUserTypeAnnotation, ClosureSubsts, GeneratorSubsts, Region, Ty};
11 // There are two visitors, one for immutable and one for mutable references,
12 // but both are generated by the following macro. The code is written according
13 // to the following conventions:
15 // - introduce a `visit_foo` and a `super_foo` method for every MIR type
16 // - `visit_foo`, by default, calls `super_foo`
17 // - `super_foo`, by default, destructures the `foo` and calls `visit_foo`
19 // This allows you as a user to override `visit_foo` for types are
20 // interested in, and invoke (within that method) call
21 // `self.super_foo` to get the default behavior. Just as in an OO
22 // language, you should never call `super` methods ordinarily except
23 // in that circumstance.
25 // For the most part, we do not destructure things external to the
26 // MIR, e.g., types, spans, etc, but simply visit them and stop. This
27 // avoids duplication with other visitors like `TypeFoldable`.
31 // The code is written in a very deliberate style intended to minimize
32 // the chance of things being overlooked. You'll notice that we always
33 // use pattern matching to reference fields and we ensure that all
34 // matches are exhaustive.
36 // For example, the `super_basic_block_data` method begins like this:
39 // fn super_basic_block_data(&mut self,
41 // data: & $($mutability)? BasicBlockData<'tcx>) {
42 // let BasicBlockData {
48 // for statement in statements {
49 // self.visit_statement(block, statement);
56 // Here we used `let BasicBlockData { <fields> } = *data` deliberately,
57 // rather than writing `data.statements` in the body. This is because if one
58 // adds a new field to `BasicBlockData`, one will be forced to revise this code,
59 // and hence one will (hopefully) invoke the correct visit methods (if any).
61 // For this to work, ALL MATCHES MUST BE EXHAUSTIVE IN FIELDS AND VARIANTS.
62 // That means you never write `..` to skip over fields, nor do you write `_`
63 // to skip over variants in a `match`.
65 // The only place that `_` is acceptable is to match a field (or
66 // variant argument) that does not require visiting, as in
67 // `is_cleanup` above.
69 macro_rules! make_mir_visitor {
70 ($visitor_trait_name:ident, $($mutability:ident)?) => {
71 pub trait $visitor_trait_name<'tcx> {
72 // Override these, and call `self.super_xxx` to revert back to the
75 fn visit_mir(&mut self, mir: & $($mutability)? Mir<'tcx>) {
79 fn visit_basic_block_data(&mut self,
81 data: & $($mutability)? BasicBlockData<'tcx>) {
82 self.super_basic_block_data(block, data);
85 fn visit_source_scope_data(&mut self,
86 scope_data: & $($mutability)? SourceScopeData) {
87 self.super_source_scope_data(scope_data);
90 fn visit_statement(&mut self,
92 statement: & $($mutability)? Statement<'tcx>,
94 self.super_statement(block, statement, location);
97 fn visit_assign(&mut self,
99 place: & $($mutability)? Place<'tcx>,
100 rvalue: & $($mutability)? Rvalue<'tcx>,
101 location: Location) {
102 self.super_assign(block, place, rvalue, location);
105 fn visit_terminator(&mut self,
107 terminator: & $($mutability)? Terminator<'tcx>,
108 location: Location) {
109 self.super_terminator(block, terminator, location);
112 fn visit_terminator_kind(&mut self,
114 kind: & $($mutability)? TerminatorKind<'tcx>,
115 location: Location) {
116 self.super_terminator_kind(block, kind, location);
119 fn visit_assert_message(&mut self,
120 msg: & $($mutability)? AssertMessage<'tcx>,
121 location: Location) {
122 self.super_assert_message(msg, location);
125 fn visit_rvalue(&mut self,
126 rvalue: & $($mutability)? Rvalue<'tcx>,
127 location: Location) {
128 self.super_rvalue(rvalue, location);
131 fn visit_operand(&mut self,
132 operand: & $($mutability)? Operand<'tcx>,
133 location: Location) {
134 self.super_operand(operand, location);
137 fn visit_ascribe_user_ty(&mut self,
138 place: & $($mutability)? Place<'tcx>,
139 variance: & $($mutability)? ty::Variance,
140 user_ty: & $($mutability)? UserTypeProjection<'tcx>,
141 location: Location) {
142 self.super_ascribe_user_ty(place, variance, user_ty, location);
145 fn visit_retag(&mut self,
146 kind: & $($mutability)? RetagKind,
147 place: & $($mutability)? Place<'tcx>,
148 location: Location) {
149 self.super_retag(kind, place, location);
152 fn visit_place(&mut self,
153 place: & $($mutability)? Place<'tcx>,
154 context: PlaceContext<'tcx>,
155 location: Location) {
156 self.super_place(place, context, location);
159 fn visit_projection(&mut self,
160 place: & $($mutability)? PlaceProjection<'tcx>,
161 context: PlaceContext<'tcx>,
162 location: Location) {
163 self.super_projection(place, context, location);
166 fn visit_projection_elem(&mut self,
167 place: & $($mutability)? PlaceElem<'tcx>,
168 location: Location) {
169 self.super_projection_elem(place, location);
172 fn visit_branch(&mut self,
174 target: BasicBlock) {
175 self.super_branch(source, target);
178 fn visit_constant(&mut self,
179 constant: & $($mutability)? Constant<'tcx>,
180 location: Location) {
181 self.super_constant(constant, location);
184 fn visit_def_id(&mut self,
185 def_id: & $($mutability)? DefId,
187 self.super_def_id(def_id);
190 fn visit_span(&mut self,
191 span: & $($mutability)? Span) {
192 self.super_span(span);
195 fn visit_source_info(&mut self,
196 source_info: & $($mutability)? SourceInfo) {
197 self.super_source_info(source_info);
200 fn visit_ty(&mut self,
201 ty: & $($mutability)? Ty<'tcx>,
206 fn visit_user_type_projection(
208 ty: & $($mutability)? UserTypeProjection<'tcx>,
210 self.super_user_type_projection(ty);
213 fn visit_user_type_annotation(
215 index: UserTypeAnnotationIndex,
216 ty: & $($mutability)? CanonicalUserTypeAnnotation<'tcx>,
218 self.super_user_type_annotation(index, ty);
221 fn visit_region(&mut self,
222 region: & $($mutability)? ty::Region<'tcx>,
224 self.super_region(region);
227 fn visit_const(&mut self,
228 constant: & $($mutability)? &'tcx ty::Const<'tcx>,
230 self.super_const(constant);
233 fn visit_substs(&mut self,
234 substs: & $($mutability)? SubstsRef<'tcx>,
236 self.super_substs(substs);
239 fn visit_closure_substs(&mut self,
240 substs: & $($mutability)? ClosureSubsts<'tcx>,
242 self.super_closure_substs(substs);
245 fn visit_generator_substs(&mut self,
246 substs: & $($mutability)? GeneratorSubsts<'tcx>,
248 self.super_generator_substs(substs);
251 fn visit_local_decl(&mut self,
253 local_decl: & $($mutability)? LocalDecl<'tcx>) {
254 self.super_local_decl(local, local_decl);
257 fn visit_local(&mut self,
258 _local: & $($mutability)? Local,
259 _context: PlaceContext<'tcx>,
260 _location: Location) {
263 fn visit_source_scope(&mut self,
264 scope: & $($mutability)? SourceScope) {
265 self.super_source_scope(scope);
268 // The `super_xxx` methods comprise the default behavior and are
269 // not meant to be overridden.
271 fn super_mir(&mut self,
272 mir: & $($mutability)? Mir<'tcx>) {
273 if let Some(yield_ty) = &$($mutability)? mir.yield_ty {
274 self.visit_ty(yield_ty, TyContext::YieldTy(SourceInfo {
276 scope: OUTERMOST_SOURCE_SCOPE,
280 // for best performance, we want to use an iterator rather
281 // than a for-loop, to avoid calling Mir::invalidate for
283 macro_rules! basic_blocks {
284 (mut) => (mir.basic_blocks_mut().iter_enumerated_mut());
285 () => (mir.basic_blocks().iter_enumerated());
287 for (bb, data) in basic_blocks!($($mutability)?) {
288 self.visit_basic_block_data(bb, data);
291 for scope in &$($mutability)? mir.source_scopes {
292 self.visit_source_scope_data(scope);
295 self.visit_ty(&$($mutability)? mir.return_ty(), TyContext::ReturnTy(SourceInfo {
297 scope: OUTERMOST_SOURCE_SCOPE,
300 for local in mir.local_decls.indices() {
301 self.visit_local_decl(local, & $($mutability)? mir.local_decls[local]);
304 macro_rules! type_annotations {
305 (mut) => (mir.user_type_annotations.iter_enumerated_mut());
306 () => (mir.user_type_annotations.iter_enumerated());
309 for (index, annotation) in type_annotations!($($mutability)?) {
310 self.visit_user_type_annotation(
315 self.visit_span(&$($mutability)? mir.span);
318 fn super_basic_block_data(&mut self,
320 data: & $($mutability)? BasicBlockData<'tcx>) {
328 for statement in statements {
329 let location = Location { block: block, statement_index: index };
330 self.visit_statement(block, statement, location);
334 if let Some(terminator) = terminator {
335 let location = Location { block: block, statement_index: index };
336 self.visit_terminator(block, terminator, location);
340 fn super_source_scope_data(&mut self, scope_data: & $($mutability)? SourceScopeData) {
341 let SourceScopeData {
346 self.visit_span(span);
347 if let Some(parent_scope) = parent_scope {
348 self.visit_source_scope(parent_scope);
352 fn super_statement(&mut self,
354 statement: & $($mutability)? Statement<'tcx>,
355 location: Location) {
361 self.visit_source_info(source_info);
363 StatementKind::Assign(place, rvalue) => {
364 self.visit_assign(block, place, rvalue, location);
366 StatementKind::FakeRead(_, place) => {
369 PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
373 StatementKind::SetDiscriminant { place, .. } => {
376 PlaceContext::MutatingUse(MutatingUseContext::Store),
380 StatementKind::StorageLive(local) => {
383 PlaceContext::NonUse(NonUseContext::StorageLive),
387 StatementKind::StorageDead(local) => {
390 PlaceContext::NonUse(NonUseContext::StorageDead),
394 StatementKind::InlineAsm { outputs, inputs, asm: _ } => {
395 for output in & $($mutability)? outputs[..] {
398 PlaceContext::MutatingUse(MutatingUseContext::AsmOutput),
402 for (span, input) in & $($mutability)? inputs[..] {
403 self.visit_span(span);
404 self.visit_operand(input, location);
407 StatementKind::Retag(kind, place) => {
408 self.visit_retag(kind, place, location);
410 StatementKind::AscribeUserType(place, variance, user_ty) => {
411 self.visit_ascribe_user_ty(place, variance, user_ty, location);
413 StatementKind::Nop => {}
417 fn super_assign(&mut self,
419 place: &$($mutability)? Place<'tcx>,
420 rvalue: &$($mutability)? Rvalue<'tcx>,
421 location: Location) {
424 PlaceContext::MutatingUse(MutatingUseContext::Store),
427 self.visit_rvalue(rvalue, location);
430 fn super_terminator(&mut self,
432 terminator: &$($mutability)? Terminator<'tcx>,
433 location: Location) {
434 let Terminator { source_info, kind } = terminator;
436 self.visit_source_info(source_info);
437 self.visit_terminator_kind(block, kind, location);
440 fn super_terminator_kind(&mut self,
442 kind: & $($mutability)? TerminatorKind<'tcx>,
443 source_location: Location) {
445 TerminatorKind::Goto { target } => {
446 self.visit_branch(block, *target);
449 TerminatorKind::SwitchInt {
455 self.visit_operand(discr, source_location);
456 self.visit_ty(switch_ty, TyContext::Location(source_location));
457 for target in targets {
458 self.visit_branch(block, *target);
462 TerminatorKind::Resume |
463 TerminatorKind::Abort |
464 TerminatorKind::Return |
465 TerminatorKind::GeneratorDrop |
466 TerminatorKind::Unreachable => {
469 TerminatorKind::Drop {
476 PlaceContext::MutatingUse(MutatingUseContext::Drop),
479 self.visit_branch(block, *target);
480 unwind.map(|t| self.visit_branch(block, t));
483 TerminatorKind::DropAndReplace {
491 PlaceContext::MutatingUse(MutatingUseContext::Drop),
494 self.visit_operand(value, source_location);
495 self.visit_branch(block, *target);
496 unwind.map(|t| self.visit_branch(block, t));
499 TerminatorKind::Call {
506 self.visit_operand(func, source_location);
508 self.visit_operand(arg, source_location);
510 if let Some((destination, target)) = destination {
513 PlaceContext::MutatingUse(MutatingUseContext::Call),
516 self.visit_branch(block, *target);
518 cleanup.map(|t| self.visit_branch(block, t));
521 TerminatorKind::Assert {
528 self.visit_operand(cond, source_location);
529 self.visit_assert_message(msg, source_location);
530 self.visit_branch(block, *target);
531 cleanup.map(|t| self.visit_branch(block, t));
534 TerminatorKind::Yield {
539 self.visit_operand(value, source_location);
540 self.visit_branch(block, *resume);
541 drop.map(|t| self.visit_branch(block, t));
544 TerminatorKind::FalseEdges { real_target, imaginary_targets } => {
545 self.visit_branch(block, *real_target);
546 for target in imaginary_targets {
547 self.visit_branch(block, *target);
551 TerminatorKind::FalseUnwind { real_target, unwind } => {
552 self.visit_branch(block, *real_target);
553 if let Some(unwind) = unwind {
554 self.visit_branch(block, *unwind);
560 fn super_assert_message(&mut self,
561 msg: & $($mutability)? AssertMessage<'tcx>,
562 location: Location) {
563 use crate::mir::interpret::InterpError::*;
564 if let BoundsCheck { len, index } = msg {
565 self.visit_operand(len, location);
566 self.visit_operand(index, location);
570 fn super_rvalue(&mut self,
571 rvalue: & $($mutability)? Rvalue<'tcx>,
572 location: Location) {
574 Rvalue::Use(operand) => {
575 self.visit_operand(operand, location);
578 Rvalue::Repeat(value, _) => {
579 self.visit_operand(value, location);
582 Rvalue::Ref(r, bk, path) => {
583 self.visit_region(r, location);
585 BorrowKind::Shared => PlaceContext::NonMutatingUse(
586 NonMutatingUseContext::SharedBorrow(*r)
588 BorrowKind::Shallow => PlaceContext::NonMutatingUse(
589 NonMutatingUseContext::ShallowBorrow(*r)
591 BorrowKind::Unique => PlaceContext::NonMutatingUse(
592 NonMutatingUseContext::UniqueBorrow(*r)
594 BorrowKind::Mut { .. } =>
595 PlaceContext::MutatingUse(MutatingUseContext::Borrow(*r)),
597 self.visit_place(path, ctx, location);
600 Rvalue::Len(path) => {
603 PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
608 Rvalue::Cast(_cast_kind, operand, ty) => {
609 self.visit_operand(operand, location);
610 self.visit_ty(ty, TyContext::Location(location));
613 Rvalue::BinaryOp(_bin_op, lhs, rhs)
614 | Rvalue::CheckedBinaryOp(_bin_op, lhs, rhs) => {
615 self.visit_operand(lhs, location);
616 self.visit_operand(rhs, location);
619 Rvalue::UnaryOp(_un_op, op) => {
620 self.visit_operand(op, location);
623 Rvalue::Discriminant(place) => {
626 PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
631 Rvalue::NullaryOp(_op, ty) => {
632 self.visit_ty(ty, TyContext::Location(location));
635 Rvalue::Aggregate(kind, operands) => {
636 let kind = &$($mutability)? **kind;
638 AggregateKind::Array(ty) => {
639 self.visit_ty(ty, TyContext::Location(location));
641 AggregateKind::Tuple => {
650 self.visit_substs(substs, location);
652 AggregateKind::Closure(
656 self.visit_def_id(def_id, location);
657 self.visit_closure_substs(closure_substs, location);
659 AggregateKind::Generator(
664 self.visit_def_id(def_id, location);
665 self.visit_generator_substs(generator_substs, location);
669 for operand in operands {
670 self.visit_operand(operand, location);
676 fn super_operand(&mut self,
677 operand: & $($mutability)? Operand<'tcx>,
678 location: Location) {
680 Operand::Copy(place) => {
683 PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
687 Operand::Move(place) => {
690 PlaceContext::NonMutatingUse(NonMutatingUseContext::Move),
694 Operand::Constant(constant) => {
695 self.visit_constant(constant, location);
700 fn super_ascribe_user_ty(&mut self,
701 place: & $($mutability)? Place<'tcx>,
702 _variance: & $($mutability)? ty::Variance,
703 user_ty: & $($mutability)? UserTypeProjection<'tcx>,
704 location: Location) {
707 PlaceContext::NonUse(NonUseContext::AscribeUserTy),
710 self.visit_user_type_projection(user_ty);
713 fn super_retag(&mut self,
714 _kind: & $($mutability)? RetagKind,
715 place: & $($mutability)? Place<'tcx>,
716 location: Location) {
719 PlaceContext::MutatingUse(MutatingUseContext::Retag),
724 fn super_place(&mut self,
725 place: & $($mutability)? Place<'tcx>,
726 context: PlaceContext<'tcx>,
727 location: Location) {
729 Place::Base(PlaceBase::Local(local)) => {
730 self.visit_local(local, context, location);
732 Place::Base(PlaceBase::Static(box Static { kind, ty })) => {
733 if let StaticKind::Static(def_id) = kind {
734 self.visit_def_id(& $($mutability)? *def_id, location)
736 self.visit_ty(& $($mutability)? *ty, TyContext::Location(location));
738 Place::Projection(proj) => {
739 self.visit_projection(proj, context, location);
744 fn super_projection(&mut self,
745 proj: & $($mutability)? PlaceProjection<'tcx>,
746 context: PlaceContext<'tcx>,
747 location: Location) {
748 let Projection { base, elem } = proj;
749 let context = if context.is_mutating_use() {
750 PlaceContext::MutatingUse(MutatingUseContext::Projection)
752 PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
754 self.visit_place(base, context, location);
755 self.visit_projection_elem(elem, location);
758 fn super_projection_elem(&mut self,
759 proj: & $($mutability)? PlaceElem<'tcx>,
760 location: Location) {
762 ProjectionElem::Deref => {
764 ProjectionElem::Subslice { from: _, to: _ } => {
766 ProjectionElem::Field(_field, ty) => {
767 self.visit_ty(ty, TyContext::Location(location));
769 ProjectionElem::Index(local) => {
772 PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
776 ProjectionElem::ConstantIndex { offset: _,
780 ProjectionElem::Downcast(_adt_def, _variant_index) => {
785 fn super_local_decl(&mut self,
787 local_decl: & $($mutability)? LocalDecl<'tcx>) {
800 self.visit_ty(ty, TyContext::LocalDecl {
802 source_info: *source_info,
804 for (user_ty, _) in & $($mutability)? user_ty.contents {
805 self.visit_user_type_projection(user_ty);
807 self.visit_source_info(source_info);
808 self.visit_source_scope(visibility_scope);
811 fn super_source_scope(&mut self,
812 _scope: & $($mutability)? SourceScope) {
815 fn super_branch(&mut self,
817 _target: BasicBlock) {
820 fn super_constant(&mut self,
821 constant: & $($mutability)? Constant<'tcx>,
822 location: Location) {
830 self.visit_span(span);
831 self.visit_ty(ty, TyContext::Location(location));
832 drop(user_ty); // no visit method for this
833 self.visit_const(literal, location);
836 fn super_def_id(&mut self, _def_id: & $($mutability)? DefId) {
839 fn super_span(&mut self, _span: & $($mutability)? Span) {
842 fn super_source_info(&mut self, source_info: & $($mutability)? SourceInfo) {
848 self.visit_span(span);
849 self.visit_source_scope(scope);
852 fn super_user_type_projection(
854 _ty: & $($mutability)? UserTypeProjection<'tcx>,
858 fn super_user_type_annotation(
860 _index: UserTypeAnnotationIndex,
861 ty: & $($mutability)? CanonicalUserTypeAnnotation<'tcx>,
863 self.visit_span(& $($mutability)? ty.span);
864 self.visit_ty(& $($mutability)? ty.inferred_ty, TyContext::UserTy(ty.span));
867 fn super_ty(&mut self, _ty: & $($mutability)? Ty<'tcx>) {
870 fn super_region(&mut self, _region: & $($mutability)? ty::Region<'tcx>) {
873 fn super_const(&mut self, _const: & $($mutability)? &'tcx ty::Const<'tcx>) {
876 fn super_substs(&mut self, _substs: & $($mutability)? SubstsRef<'tcx>) {
879 fn super_generator_substs(&mut self,
880 _substs: & $($mutability)? GeneratorSubsts<'tcx>) {
883 fn super_closure_substs(&mut self,
884 _substs: & $($mutability)? ClosureSubsts<'tcx>) {
887 // Convenience methods
889 fn visit_location(&mut self, mir: & $($mutability)? Mir<'tcx>, location: Location) {
890 let basic_block = & $($mutability)? mir[location.block];
891 if basic_block.statements.len() == location.statement_index {
892 if let Some(ref $($mutability)? terminator) = basic_block.terminator {
893 self.visit_terminator(location.block, terminator, location)
896 let statement = & $($mutability)?
897 basic_block.statements[location.statement_index];
898 self.visit_statement(location.block, statement, location)
905 make_mir_visitor!(Visitor,);
906 make_mir_visitor!(MutVisitor,mut);
908 pub trait MirVisitable<'tcx> {
909 fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>);
912 impl<'tcx> MirVisitable<'tcx> for Statement<'tcx> {
913 fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>)
915 visitor.visit_statement(location.block, self, location)
919 impl<'tcx> MirVisitable<'tcx> for Terminator<'tcx> {
920 fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>)
922 visitor.visit_terminator(location.block, self, location)
926 impl<'tcx> MirVisitable<'tcx> for Option<Terminator<'tcx>> {
927 fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>)
929 visitor.visit_terminator(location.block, self.as_ref().unwrap(), location)
933 /// Extra information passed to `visit_ty` and friends to give context
934 /// about where the type etc appears.
935 #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
938 /// The index of the local variable we are visiting.
941 /// The source location where this local variable was declared.
942 source_info: SourceInfo,
945 /// The inferred type of a user type annotation.
948 /// The return type of the function.
949 ReturnTy(SourceInfo),
953 /// A type found at some location.
957 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
958 pub enum NonMutatingUseContext<'tcx> {
959 /// Being inspected in some way, like loading a len.
961 /// Consumed as part of an operand.
963 /// Consumed as part of an operand.
966 SharedBorrow(Region<'tcx>),
968 ShallowBorrow(Region<'tcx>),
970 UniqueBorrow(Region<'tcx>),
971 /// Used as base for another place, e.g., `x` in `x.y`. Will not mutate the place.
972 /// For example, the projection `x.y` is not marked as a mutation in these cases:
980 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
981 pub enum MutatingUseContext<'tcx> {
982 /// Appears as LHS of an assignment.
984 /// Can often be treated as a `Store`, but needs to be separate because
985 /// ASM is allowed to read outputs as well, so a `Store`-`AsmOutput` sequence
986 /// cannot be simplified the way a `Store`-`Store` can be.
988 /// Destination of a call.
993 Borrow(Region<'tcx>),
994 /// Used as base for another place, e.g., `x` in `x.y`. Could potentially mutate the place.
995 /// For example, the projection `x.y` is marked as a mutation in these cases:
1001 /// Retagging, a "Stacked Borrows" shadow state operation
1005 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
1006 pub enum NonUseContext {
1007 /// Starting a storage live range.
1009 /// Ending a storage live range.
1011 /// User type annotation assertions for NLL.
1015 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
1016 pub enum PlaceContext<'tcx> {
1017 NonMutatingUse(NonMutatingUseContext<'tcx>),
1018 MutatingUse(MutatingUseContext<'tcx>),
1019 NonUse(NonUseContext),
1022 impl<'tcx> PlaceContext<'tcx> {
1023 /// Returns `true` if this place context represents a drop.
1024 pub fn is_drop(&self) -> bool {
1026 PlaceContext::MutatingUse(MutatingUseContext::Drop) => true,
1031 /// Returns `true` if this place context represents a borrow.
1032 pub fn is_borrow(&self) -> bool {
1034 PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow(..)) |
1035 PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow(..)) |
1036 PlaceContext::NonMutatingUse(NonMutatingUseContext::UniqueBorrow(..)) |
1037 PlaceContext::MutatingUse(MutatingUseContext::Borrow(..)) => true,
1042 /// Returns `true` if this place context represents a storage live or storage dead marker.
1043 pub fn is_storage_marker(&self) -> bool {
1045 PlaceContext::NonUse(NonUseContext::StorageLive) |
1046 PlaceContext::NonUse(NonUseContext::StorageDead) => true,
1051 /// Returns `true` if this place context represents a storage live marker.
1052 pub fn is_storage_live_marker(&self) -> bool {
1054 PlaceContext::NonUse(NonUseContext::StorageLive) => true,
1059 /// Returns `true` if this place context represents a storage dead marker.
1060 pub fn is_storage_dead_marker(&self) -> bool {
1062 PlaceContext::NonUse(NonUseContext::StorageDead) => true,
1067 /// Returns `true` if this place context represents a use that potentially changes the value.
1068 pub fn is_mutating_use(&self) -> bool {
1070 PlaceContext::MutatingUse(..) => true,
1075 /// Returns `true` if this place context represents a use that does not change the value.
1076 pub fn is_nonmutating_use(&self) -> bool {
1078 PlaceContext::NonMutatingUse(..) => true,
1083 /// Returns `true` if this place context represents a use.
1084 pub fn is_use(&self) -> bool {
1086 PlaceContext::NonUse(..) => false,
1091 /// Returns `true` if this place context represents an assignment statement.
1092 pub fn is_place_assignment(&self) -> bool {
1094 PlaceContext::MutatingUse(MutatingUseContext::Store) |
1095 PlaceContext::MutatingUse(MutatingUseContext::Call) |
1096 PlaceContext::MutatingUse(MutatingUseContext::AsmOutput) => true,