1 use crate::ty::subst::SubstsRef;
2 use crate::ty::{CanonicalUserTypeAnnotation, Ty};
10 // There are two visitors, one for immutable and one for mutable references,
11 // but both are generated by the following macro. The code is written according
12 // to the following conventions:
14 // - introduce a `visit_foo` and a `super_foo` method for every MIR type
15 // - `visit_foo`, by default, calls `super_foo`
16 // - `super_foo`, by default, destructures the `foo` and calls `visit_foo`
18 // This allows you as a user to override `visit_foo` for types are
19 // interested in, and invoke (within that method) call
20 // `self.super_foo` to get the default behavior. Just as in an OO
21 // language, you should never call `super` methods ordinarily except
22 // in that circumstance.
24 // For the most part, we do not destructure things external to the
25 // MIR, e.g., types, spans, etc, but simply visit them and stop. This
26 // avoids duplication with other visitors like `TypeFoldable`.
30 // The code is written in a very deliberate style intended to minimize
31 // the chance of things being overlooked. You'll notice that we always
32 // use pattern matching to reference fields and we ensure that all
33 // matches are exhaustive.
35 // For example, the `super_basic_block_data` method begins like this:
38 // fn super_basic_block_data(&mut self,
40 // data: & $($mutability)? BasicBlockData<'tcx>) {
41 // let BasicBlockData {
47 // for statement in statements {
48 // self.visit_statement(block, statement);
55 // Here we used `let BasicBlockData { <fields> } = *data` deliberately,
56 // rather than writing `data.statements` in the body. This is because if one
57 // adds a new field to `BasicBlockData`, one will be forced to revise this code,
58 // and hence one will (hopefully) invoke the correct visit methods (if any).
60 // For this to work, ALL MATCHES MUST BE EXHAUSTIVE IN FIELDS AND VARIANTS.
61 // That means you never write `..` to skip over fields, nor do you write `_`
62 // to skip over variants in a `match`.
64 // The only place that `_` is acceptable is to match a field (or
65 // variant argument) that does not require visiting, as in
66 // `is_cleanup` above.
68 macro_rules! make_mir_visitor {
69 ($visitor_trait_name:ident, $($mutability:ident)?) => {
70 pub trait $visitor_trait_name<'tcx> {
71 // Override these, and call `self.super_xxx` to revert back to the
74 fn visit_body(&mut self, body: & $($mutability)? Body<'tcx>) {
75 self.super_body(body);
78 fn visit_basic_block_data(&mut self,
80 data: & $($mutability)? BasicBlockData<'tcx>) {
81 self.super_basic_block_data(block, data);
84 fn visit_source_scope_data(&mut self,
85 scope_data: & $($mutability)? SourceScopeData) {
86 self.super_source_scope_data(scope_data);
89 fn visit_statement(&mut self,
90 statement: & $($mutability)? Statement<'tcx>,
92 self.super_statement(statement, location);
95 fn visit_assign(&mut self,
96 place: & $($mutability)? Place<'tcx>,
97 rvalue: & $($mutability)? Rvalue<'tcx>,
99 self.super_assign(place, rvalue, location);
102 fn visit_terminator(&mut self,
103 terminator: & $($mutability)? Terminator<'tcx>,
104 location: Location) {
105 self.super_terminator(terminator, location);
108 fn visit_terminator_kind(&mut self,
109 kind: & $($mutability)? TerminatorKind<'tcx>,
110 location: Location) {
111 self.super_terminator_kind(kind, location);
114 fn visit_assert_message(&mut self,
115 msg: & $($mutability)? AssertMessage<'tcx>,
116 location: Location) {
117 self.super_assert_message(msg, location);
120 fn visit_rvalue(&mut self,
121 rvalue: & $($mutability)? Rvalue<'tcx>,
122 location: Location) {
123 self.super_rvalue(rvalue, location);
126 fn visit_operand(&mut self,
127 operand: & $($mutability)? Operand<'tcx>,
128 location: Location) {
129 self.super_operand(operand, location);
132 fn visit_ascribe_user_ty(&mut self,
133 place: & $($mutability)? Place<'tcx>,
134 variance: & $($mutability)? ty::Variance,
135 user_ty: & $($mutability)? UserTypeProjection,
136 location: Location) {
137 self.super_ascribe_user_ty(place, variance, user_ty, location);
140 fn visit_retag(&mut self,
141 kind: & $($mutability)? RetagKind,
142 place: & $($mutability)? Place<'tcx>,
143 location: Location) {
144 self.super_retag(kind, place, location);
147 fn visit_place(&mut self,
148 place: & $($mutability)? Place<'tcx>,
149 context: PlaceContext,
150 location: Location) {
151 self.super_place(place, context, location);
154 fn visit_place_base(&mut self,
155 base: & $($mutability)? PlaceBase<'tcx>,
156 context: PlaceContext,
157 location: Location) {
158 self.super_place_base(base, context, location);
161 visit_place_fns!($($mutability)?);
163 fn visit_constant(&mut self,
164 constant: & $($mutability)? Constant<'tcx>,
165 location: Location) {
166 self.super_constant(constant, location);
169 fn visit_span(&mut self,
170 span: & $($mutability)? Span) {
171 self.super_span(span);
174 fn visit_source_info(&mut self,
175 source_info: & $($mutability)? SourceInfo) {
176 self.super_source_info(source_info);
179 fn visit_ty(&mut self,
180 ty: $(& $mutability)? Ty<'tcx>,
185 fn visit_user_type_projection(
187 ty: & $($mutability)? UserTypeProjection,
189 self.super_user_type_projection(ty);
192 fn visit_user_type_annotation(
194 index: UserTypeAnnotationIndex,
195 ty: & $($mutability)? CanonicalUserTypeAnnotation<'tcx>,
197 self.super_user_type_annotation(index, ty);
200 fn visit_region(&mut self,
201 region: & $($mutability)? ty::Region<'tcx>,
203 self.super_region(region);
206 fn visit_const(&mut self,
207 constant: & $($mutability)? &'tcx ty::Const<'tcx>,
209 self.super_const(constant);
212 fn visit_substs(&mut self,
213 substs: & $($mutability)? SubstsRef<'tcx>,
215 self.super_substs(substs);
218 fn visit_local_decl(&mut self,
220 local_decl: & $($mutability)? LocalDecl<'tcx>) {
221 self.super_local_decl(local, local_decl);
224 fn visit_var_debug_info(&mut self,
225 var_debug_info: & $($mutability)* VarDebugInfo<'tcx>) {
226 self.super_var_debug_info(var_debug_info);
229 fn visit_local(&mut self,
230 _local: & $($mutability)? Local,
231 _context: PlaceContext,
232 _location: Location) {
235 fn visit_source_scope(&mut self,
236 scope: & $($mutability)? SourceScope) {
237 self.super_source_scope(scope);
240 // The `super_xxx` methods comprise the default behavior and are
241 // not meant to be overridden.
243 fn super_body(&mut self,
244 body: & $($mutability)? Body<'tcx>) {
245 if let Some(yield_ty) = &$($mutability)? body.yield_ty {
246 self.visit_ty(yield_ty, TyContext::YieldTy(SourceInfo {
248 scope: OUTERMOST_SOURCE_SCOPE,
252 // for best performance, we want to use an iterator rather
253 // than a for-loop, to avoid calling `body::Body::invalidate` for
255 macro_rules! basic_blocks {
256 (mut) => (body.basic_blocks_mut().iter_enumerated_mut());
257 () => (body.basic_blocks().iter_enumerated());
259 for (bb, data) in basic_blocks!($($mutability)?) {
260 self.visit_basic_block_data(bb, data);
263 for scope in &$($mutability)? body.source_scopes {
264 self.visit_source_scope_data(scope);
267 self.visit_ty(&$($mutability)? body.return_ty(), TyContext::ReturnTy(SourceInfo {
269 scope: OUTERMOST_SOURCE_SCOPE,
272 for local in body.local_decls.indices() {
273 self.visit_local_decl(local, & $($mutability)? body.local_decls[local]);
276 macro_rules! type_annotations {
277 (mut) => (body.user_type_annotations.iter_enumerated_mut());
278 () => (body.user_type_annotations.iter_enumerated());
281 for (index, annotation) in type_annotations!($($mutability)?) {
282 self.visit_user_type_annotation(
287 for var_debug_info in &$($mutability)? body.var_debug_info {
288 self.visit_var_debug_info(var_debug_info);
291 self.visit_span(&$($mutability)? body.span);
294 fn super_basic_block_data(&mut self,
296 data: & $($mutability)? BasicBlockData<'tcx>) {
304 for statement in statements {
305 let location = Location { block: block, statement_index: index };
306 self.visit_statement(statement, location);
310 if let Some(terminator) = terminator {
311 let location = Location { block: block, statement_index: index };
312 self.visit_terminator(terminator, location);
316 fn super_source_scope_data(&mut self, scope_data: & $($mutability)? SourceScopeData) {
317 let SourceScopeData {
322 self.visit_span(span);
323 if let Some(parent_scope) = parent_scope {
324 self.visit_source_scope(parent_scope);
328 fn super_statement(&mut self,
329 statement: & $($mutability)? Statement<'tcx>,
330 location: Location) {
336 self.visit_source_info(source_info);
338 StatementKind::Assign(
339 box(ref $($mutability)? place, ref $($mutability)? rvalue)
341 self.visit_assign(place, rvalue, location);
343 StatementKind::FakeRead(_, place) => {
346 PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
350 StatementKind::SetDiscriminant { place, .. } => {
353 PlaceContext::MutatingUse(MutatingUseContext::Store),
357 StatementKind::StorageLive(local) => {
360 PlaceContext::NonUse(NonUseContext::StorageLive),
364 StatementKind::StorageDead(local) => {
367 PlaceContext::NonUse(NonUseContext::StorageDead),
371 StatementKind::InlineAsm(asm) => {
372 for output in & $($mutability)? asm.outputs[..] {
375 PlaceContext::MutatingUse(MutatingUseContext::AsmOutput),
379 for (span, input) in & $($mutability)? asm.inputs[..] {
380 self.visit_span(span);
381 self.visit_operand(input, location);
384 StatementKind::Retag(kind, place) => {
385 self.visit_retag(kind, place, location);
387 StatementKind::AscribeUserType(
388 box(ref $($mutability)? place, ref $($mutability)? user_ty),
391 self.visit_ascribe_user_ty(place, variance, user_ty, location);
393 StatementKind::Nop => {}
397 fn super_assign(&mut self,
398 place: &$($mutability)? Place<'tcx>,
399 rvalue: &$($mutability)? Rvalue<'tcx>,
400 location: Location) {
403 PlaceContext::MutatingUse(MutatingUseContext::Store),
406 self.visit_rvalue(rvalue, location);
409 fn super_terminator(&mut self,
410 terminator: &$($mutability)? Terminator<'tcx>,
411 location: Location) {
412 let Terminator { source_info, kind } = terminator;
414 self.visit_source_info(source_info);
415 self.visit_terminator_kind(kind, location);
418 fn super_terminator_kind(&mut self,
419 kind: & $($mutability)? TerminatorKind<'tcx>,
420 source_location: Location) {
422 TerminatorKind::Goto { .. } |
423 TerminatorKind::Resume |
424 TerminatorKind::Abort |
425 TerminatorKind::Return |
426 TerminatorKind::GeneratorDrop |
427 TerminatorKind::Unreachable |
428 TerminatorKind::FalseEdges { .. } |
429 TerminatorKind::FalseUnwind { .. } => {
432 TerminatorKind::SwitchInt {
438 self.visit_operand(discr, source_location);
439 self.visit_ty(switch_ty, TyContext::Location(source_location));
442 TerminatorKind::Drop {
449 PlaceContext::MutatingUse(MutatingUseContext::Drop),
454 TerminatorKind::DropAndReplace {
462 PlaceContext::MutatingUse(MutatingUseContext::Drop),
465 self.visit_operand(value, source_location);
468 TerminatorKind::Call {
475 self.visit_operand(func, source_location);
477 self.visit_operand(arg, source_location);
479 if let Some((destination, _)) = destination {
482 PlaceContext::MutatingUse(MutatingUseContext::Call),
488 TerminatorKind::Assert {
495 self.visit_operand(cond, source_location);
496 self.visit_assert_message(msg, source_location);
499 TerminatorKind::Yield {
504 self.visit_operand(value, source_location);
510 fn super_assert_message(&mut self,
511 msg: & $($mutability)? AssertMessage<'tcx>,
512 location: Location) {
513 use crate::mir::interpret::PanicInfo::*;
515 BoundsCheck { len, index } => {
516 self.visit_operand(len, location);
517 self.visit_operand(index, location);
519 Panic { .. } | Overflow(_) | OverflowNeg | DivisionByZero | RemainderByZero |
520 GeneratorResumedAfterReturn | GeneratorResumedAfterPanic |
521 AsyncResumedAfterReturn | AsyncResumedAfterPanic => {
527 fn super_rvalue(&mut self,
528 rvalue: & $($mutability)? Rvalue<'tcx>,
529 location: Location) {
531 Rvalue::Use(operand) => {
532 self.visit_operand(operand, location);
535 Rvalue::Repeat(value, _) => {
536 self.visit_operand(value, location);
539 Rvalue::Ref(r, bk, path) => {
540 self.visit_region(r, location);
542 BorrowKind::Shared => PlaceContext::NonMutatingUse(
543 NonMutatingUseContext::SharedBorrow
545 BorrowKind::Shallow => PlaceContext::NonMutatingUse(
546 NonMutatingUseContext::ShallowBorrow
548 BorrowKind::Unique => PlaceContext::NonMutatingUse(
549 NonMutatingUseContext::UniqueBorrow
551 BorrowKind::Mut { .. } =>
552 PlaceContext::MutatingUse(MutatingUseContext::Borrow),
554 self.visit_place(path, ctx, location);
557 Rvalue::Len(path) => {
560 PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
565 Rvalue::Cast(_cast_kind, operand, ty) => {
566 self.visit_operand(operand, location);
567 self.visit_ty(ty, TyContext::Location(location));
570 Rvalue::BinaryOp(_bin_op, lhs, rhs)
571 | Rvalue::CheckedBinaryOp(_bin_op, lhs, rhs) => {
572 self.visit_operand(lhs, location);
573 self.visit_operand(rhs, location);
576 Rvalue::UnaryOp(_un_op, op) => {
577 self.visit_operand(op, location);
580 Rvalue::Discriminant(place) => {
583 PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
588 Rvalue::NullaryOp(_op, ty) => {
589 self.visit_ty(ty, TyContext::Location(location));
592 Rvalue::Aggregate(kind, operands) => {
593 let kind = &$($mutability)? **kind;
595 AggregateKind::Array(ty) => {
596 self.visit_ty(ty, TyContext::Location(location));
598 AggregateKind::Tuple => {
607 self.visit_substs(substs, location);
609 AggregateKind::Closure(
613 self.visit_substs(closure_substs, location);
615 AggregateKind::Generator(
620 self.visit_substs(generator_substs, location);
624 for operand in operands {
625 self.visit_operand(operand, location);
631 fn super_operand(&mut self,
632 operand: & $($mutability)? Operand<'tcx>,
633 location: Location) {
635 Operand::Copy(place) => {
638 PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
642 Operand::Move(place) => {
645 PlaceContext::NonMutatingUse(NonMutatingUseContext::Move),
649 Operand::Constant(constant) => {
650 self.visit_constant(constant, location);
655 fn super_ascribe_user_ty(&mut self,
656 place: & $($mutability)? Place<'tcx>,
657 _variance: & $($mutability)? ty::Variance,
658 user_ty: & $($mutability)? UserTypeProjection,
659 location: Location) {
662 PlaceContext::NonUse(NonUseContext::AscribeUserTy),
665 self.visit_user_type_projection(user_ty);
668 fn super_retag(&mut self,
669 _kind: & $($mutability)? RetagKind,
670 place: & $($mutability)? Place<'tcx>,
671 location: Location) {
674 PlaceContext::MutatingUse(MutatingUseContext::Retag),
679 fn super_place_base(&mut self,
680 place_base: & $($mutability)? PlaceBase<'tcx>,
681 context: PlaceContext,
682 location: Location) {
684 PlaceBase::Local(local) => {
685 self.visit_local(local, context, location);
687 PlaceBase::Static(box Static { kind: _, ty, def_id: _ }) => {
688 self.visit_ty(& $($mutability)? *ty, TyContext::Location(location));
693 fn super_local_decl(&mut self,
695 local_decl: & $($mutability)? LocalDecl<'tcx>) {
706 self.visit_ty(ty, TyContext::LocalDecl {
708 source_info: *source_info,
710 for (user_ty, _) in & $($mutability)? user_ty.contents {
711 self.visit_user_type_projection(user_ty);
713 self.visit_source_info(source_info);
716 fn super_var_debug_info(&mut self,
717 var_debug_info: & $($mutability)? VarDebugInfo<'tcx>) {
724 self.visit_source_info(source_info);
725 let location = START_BLOCK.start_location();
728 PlaceContext::NonUse(NonUseContext::VarDebugInfo),
733 fn super_source_scope(&mut self,
734 _scope: & $($mutability)? SourceScope) {
737 fn super_constant(&mut self,
738 constant: & $($mutability)? Constant<'tcx>,
739 location: Location) {
746 self.visit_span(span);
747 drop(user_ty); // no visit method for this
748 self.visit_const(literal, location);
751 fn super_span(&mut self, _span: & $($mutability)? Span) {
754 fn super_source_info(&mut self, source_info: & $($mutability)? SourceInfo) {
760 self.visit_span(span);
761 self.visit_source_scope(scope);
764 fn super_user_type_projection(
766 _ty: & $($mutability)? UserTypeProjection,
770 fn super_user_type_annotation(
772 _index: UserTypeAnnotationIndex,
773 ty: & $($mutability)? CanonicalUserTypeAnnotation<'tcx>,
775 self.visit_span(& $($mutability)? ty.span);
776 self.visit_ty(& $($mutability)? ty.inferred_ty, TyContext::UserTy(ty.span));
779 fn super_ty(&mut self, _ty: $(& $mutability)? Ty<'tcx>) {
782 fn super_region(&mut self, _region: & $($mutability)? ty::Region<'tcx>) {
785 fn super_const(&mut self, _const: & $($mutability)? &'tcx ty::Const<'tcx>) {
788 fn super_substs(&mut self, _substs: & $($mutability)? SubstsRef<'tcx>) {
791 // Convenience methods
793 fn visit_location(&mut self, body: & $($mutability)? Body<'tcx>, location: Location) {
794 let basic_block = & $($mutability)? body[location.block];
795 if basic_block.statements.len() == location.statement_index {
796 if let Some(ref $($mutability)? terminator) = basic_block.terminator {
797 self.visit_terminator(terminator, location)
800 let statement = & $($mutability)?
801 basic_block.statements[location.statement_index];
802 self.visit_statement(statement, location)
809 macro_rules! visit_place_fns {
811 fn tcx<'a>(&'a self) -> TyCtxt<'tcx>;
815 place: &mut Place<'tcx>,
816 context: PlaceContext,
819 self.visit_place_base(&mut place.base, context, location);
821 if let Some(new_projection) = self.process_projection(&place.projection) {
822 place.projection = self.tcx().intern_place_elems(&new_projection);
826 fn process_projection(
828 projection: &'a [PlaceElem<'tcx>],
829 ) -> Option<Vec<PlaceElem<'tcx>>> {
830 let mut projection = Cow::Borrowed(projection);
832 for i in 0..projection.len() {
833 if let Some(elem) = projection.get(i) {
834 if let Some(elem) = self.process_projection_elem(elem) {
835 // This converts the borrowed projection into `Cow::Owned(_)` and returns a
836 // clone of the projection so we can mutate and reintern later.
837 let vec = projection.to_mut();
844 Cow::Borrowed(_) => None,
845 Cow::Owned(vec) => Some(vec),
849 fn process_projection_elem(
851 _elem: &PlaceElem<'tcx>,
852 ) -> Option<PlaceElem<'tcx>> {
860 base: &PlaceBase<'tcx>,
861 projection: &[PlaceElem<'tcx>],
862 context: PlaceContext,
865 self.super_projection(base, projection, context, location);
868 fn visit_projection_elem(
870 base: &PlaceBase<'tcx>,
871 proj_base: &[PlaceElem<'tcx>],
872 elem: &PlaceElem<'tcx>,
873 context: PlaceContext,
876 self.super_projection_elem(base, proj_base, elem, context, location);
882 context: PlaceContext,
885 let mut context = context;
887 if !place.projection.is_empty() {
888 context = if context.is_mutating_use() {
889 PlaceContext::MutatingUse(MutatingUseContext::Projection)
891 PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
895 self.visit_place_base(&place.base, context, location);
897 self.visit_projection(&place.base,
905 base: &PlaceBase<'tcx>,
906 projection: &[PlaceElem<'tcx>],
907 context: PlaceContext,
910 let mut cursor = projection;
911 while let [proj_base @ .., elem] = cursor {
913 self.visit_projection_elem(base, cursor, elem, context, location);
917 fn super_projection_elem(
919 _base: &PlaceBase<'tcx>,
920 _proj_base: &[PlaceElem<'tcx>],
921 elem: &PlaceElem<'tcx>,
922 _context: PlaceContext,
926 ProjectionElem::Field(_field, ty) => {
927 self.visit_ty(ty, TyContext::Location(location));
929 ProjectionElem::Index(local) => {
932 PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
936 ProjectionElem::Deref |
937 ProjectionElem::Subslice { from: _, to: _ } |
938 ProjectionElem::ConstantIndex { offset: _,
941 ProjectionElem::Downcast(_, _) => {
948 make_mir_visitor!(Visitor,);
949 make_mir_visitor!(MutVisitor,mut);
951 pub trait MirVisitable<'tcx> {
952 fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>);
955 impl<'tcx> MirVisitable<'tcx> for Statement<'tcx> {
956 fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>)
958 visitor.visit_statement(self, location)
962 impl<'tcx> MirVisitable<'tcx> for Terminator<'tcx> {
963 fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>)
965 visitor.visit_terminator(self, location)
969 impl<'tcx> MirVisitable<'tcx> for Option<Terminator<'tcx>> {
970 fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>)
972 visitor.visit_terminator(self.as_ref().unwrap(), location)
976 /// Extra information passed to `visit_ty` and friends to give context
977 /// about where the type etc appears.
981 /// The index of the local variable we are visiting.
984 /// The source location where this local variable was declared.
985 source_info: SourceInfo,
988 /// The inferred type of a user type annotation.
991 /// The return type of the function.
992 ReturnTy(SourceInfo),
996 /// A type found at some location.
1000 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
1001 pub enum NonMutatingUseContext {
1002 /// Being inspected in some way, like loading a len.
1004 /// Consumed as part of an operand.
1006 /// Consumed as part of an operand.
1014 /// Used as base for another place, e.g., `x` in `x.y`. Will not mutate the place.
1015 /// For example, the projection `x.y` is not marked as a mutation in these cases:
1023 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
1024 pub enum MutatingUseContext {
1025 /// Appears as LHS of an assignment.
1027 /// Can often be treated as a `Store`, but needs to be separate because
1028 /// ASM is allowed to read outputs as well, so a `Store`-`AsmOutput` sequence
1029 /// cannot be simplified the way a `Store`-`Store` can be.
1031 /// Destination of a call.
1037 /// Used as base for another place, e.g., `x` in `x.y`. Could potentially mutate the place.
1038 /// For example, the projection `x.y` is marked as a mutation in these cases:
1044 /// Retagging, a "Stacked Borrows" shadow state operation
1048 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
1049 pub enum NonUseContext {
1050 /// Starting a storage live range.
1052 /// Ending a storage live range.
1054 /// User type annotation assertions for NLL.
1056 /// The data of an user variable, for debug info.
1060 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
1061 pub enum PlaceContext {
1062 NonMutatingUse(NonMutatingUseContext),
1063 MutatingUse(MutatingUseContext),
1064 NonUse(NonUseContext),
1068 /// Returns `true` if this place context represents a drop.
1069 pub fn is_drop(&self) -> bool {
1071 PlaceContext::MutatingUse(MutatingUseContext::Drop) => true,
1076 /// Returns `true` if this place context represents a borrow.
1077 pub fn is_borrow(&self) -> bool {
1079 PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow) |
1080 PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow) |
1081 PlaceContext::NonMutatingUse(NonMutatingUseContext::UniqueBorrow) |
1082 PlaceContext::MutatingUse(MutatingUseContext::Borrow) => true,
1087 /// Returns `true` if this place context represents a storage live or storage dead marker.
1088 pub fn is_storage_marker(&self) -> bool {
1090 PlaceContext::NonUse(NonUseContext::StorageLive) |
1091 PlaceContext::NonUse(NonUseContext::StorageDead) => true,
1096 /// Returns `true` if this place context represents a storage live marker.
1097 pub fn is_storage_live_marker(&self) -> bool {
1099 PlaceContext::NonUse(NonUseContext::StorageLive) => true,
1104 /// Returns `true` if this place context represents a storage dead marker.
1105 pub fn is_storage_dead_marker(&self) -> bool {
1107 PlaceContext::NonUse(NonUseContext::StorageDead) => true,
1112 /// Returns `true` if this place context represents a use that potentially changes the value.
1113 pub fn is_mutating_use(&self) -> bool {
1115 PlaceContext::MutatingUse(..) => true,
1120 /// Returns `true` if this place context represents a use that does not change the value.
1121 pub fn is_nonmutating_use(&self) -> bool {
1123 PlaceContext::NonMutatingUse(..) => true,
1128 /// Returns `true` if this place context represents a use.
1129 pub fn is_use(&self) -> bool {
1131 PlaceContext::NonUse(..) => false,
1136 /// Returns `true` if this place context represents an assignment statement.
1137 pub fn is_place_assignment(&self) -> bool {
1139 PlaceContext::MutatingUse(MutatingUseContext::Store) |
1140 PlaceContext::MutatingUse(MutatingUseContext::Call) |
1141 PlaceContext::MutatingUse(MutatingUseContext::AsmOutput) => true,