2 use crate::ty::subst::SubstsRef;
3 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
76 body: &$($mutability)? Body<'tcx>,
78 self.super_body(body);
81 fn visit_basic_block_data(&mut self,
83 data: & $($mutability)? BasicBlockData<'tcx>) {
84 self.super_basic_block_data(block, data);
87 fn visit_source_scope_data(&mut self,
88 scope_data: & $($mutability)? SourceScopeData) {
89 self.super_source_scope_data(scope_data);
92 fn visit_statement(&mut self,
93 statement: & $($mutability)? Statement<'tcx>,
95 self.super_statement(statement, location);
98 fn visit_assign(&mut self,
99 place: & $($mutability)? Place<'tcx>,
100 rvalue: & $($mutability)? Rvalue<'tcx>,
101 location: Location) {
102 self.super_assign(place, rvalue, location);
105 fn visit_terminator(&mut self,
106 terminator: & $($mutability)? Terminator<'tcx>,
107 location: Location) {
108 self.super_terminator(terminator, location);
111 fn visit_terminator_kind(&mut self,
112 kind: & $($mutability)? TerminatorKind<'tcx>,
113 location: Location) {
114 self.super_terminator_kind(kind, location);
117 fn visit_assert_message(&mut self,
118 msg: & $($mutability)? AssertMessage<'tcx>,
119 location: Location) {
120 self.super_assert_message(msg, location);
123 fn visit_rvalue(&mut self,
124 rvalue: & $($mutability)? Rvalue<'tcx>,
125 location: Location) {
126 self.super_rvalue(rvalue, location);
129 fn visit_operand(&mut self,
130 operand: & $($mutability)? Operand<'tcx>,
131 location: Location) {
132 self.super_operand(operand, location);
135 fn visit_ascribe_user_ty(&mut self,
136 place: & $($mutability)? Place<'tcx>,
137 variance: & $($mutability)? ty::Variance,
138 user_ty: & $($mutability)? UserTypeProjection,
139 location: Location) {
140 self.super_ascribe_user_ty(place, variance, user_ty, location);
143 fn visit_retag(&mut self,
144 kind: & $($mutability)? RetagKind,
145 place: & $($mutability)? Place<'tcx>,
146 location: Location) {
147 self.super_retag(kind, place, location);
150 fn visit_place(&mut self,
151 place: & $($mutability)? Place<'tcx>,
152 context: PlaceContext,
153 location: Location) {
154 self.super_place(place, context, location);
157 visit_place_fns!($($mutability)?);
159 fn visit_constant(&mut self,
160 constant: & $($mutability)? Constant<'tcx>,
161 location: Location) {
162 self.super_constant(constant, location);
165 fn visit_span(&mut self,
166 span: & $($mutability)? Span) {
167 self.super_span(span);
170 fn visit_source_info(&mut self,
171 source_info: & $($mutability)? SourceInfo) {
172 self.super_source_info(source_info);
175 fn visit_ty(&mut self,
176 ty: $(& $mutability)? Ty<'tcx>,
181 fn visit_user_type_projection(
183 ty: & $($mutability)? UserTypeProjection,
185 self.super_user_type_projection(ty);
188 fn visit_user_type_annotation(
190 index: UserTypeAnnotationIndex,
191 ty: & $($mutability)? CanonicalUserTypeAnnotation<'tcx>,
193 self.super_user_type_annotation(index, ty);
196 fn visit_region(&mut self,
197 region: & $($mutability)? ty::Region<'tcx>,
199 self.super_region(region);
202 fn visit_const(&mut self,
203 constant: & $($mutability)? &'tcx ty::Const<'tcx>,
205 self.super_const(constant);
208 fn visit_substs(&mut self,
209 substs: & $($mutability)? SubstsRef<'tcx>,
211 self.super_substs(substs);
214 fn visit_local_decl(&mut self,
216 local_decl: & $($mutability)? LocalDecl<'tcx>) {
217 self.super_local_decl(local, local_decl);
220 fn visit_var_debug_info(&mut self,
221 var_debug_info: & $($mutability)* VarDebugInfo<'tcx>) {
222 self.super_var_debug_info(var_debug_info);
225 fn visit_local(&mut self,
226 _local: & $($mutability)? Local,
227 _context: PlaceContext,
228 _location: Location) {
231 fn visit_source_scope(&mut self,
232 scope: & $($mutability)? SourceScope) {
233 self.super_source_scope(scope);
236 // The `super_xxx` methods comprise the default behavior and are
237 // not meant to be overridden.
241 body: &$($mutability)? Body<'tcx>,
243 let span = body.span;
244 if let Some(yield_ty) = &$($mutability)? body.yield_ty {
245 self.visit_ty(yield_ty, TyContext::YieldTy(SourceInfo {
247 scope: OUTERMOST_SOURCE_SCOPE,
251 // for best performance, we want to use an iterator rather
252 // than a for-loop, to avoid calling `body::Body::invalidate` for
254 macro_rules! basic_blocks {
255 (mut) => (body.basic_blocks_mut().iter_enumerated_mut());
256 () => (body.basic_blocks().iter_enumerated());
258 for (bb, data) in basic_blocks!($($mutability)?) {
259 self.visit_basic_block_data(bb, data);
262 for scope in &$($mutability)? body.source_scopes {
263 self.visit_source_scope_data(scope);
266 self.visit_ty(&$($mutability)? body.return_ty(), TyContext::ReturnTy(SourceInfo {
268 scope: OUTERMOST_SOURCE_SCOPE,
271 for local in body.local_decls.indices() {
272 self.visit_local_decl(local, & $($mutability)? body.local_decls[local]);
275 macro_rules! type_annotations {
276 (mut) => (body.user_type_annotations.iter_enumerated_mut());
277 () => (body.user_type_annotations.iter_enumerated());
280 for (index, annotation) in type_annotations!($($mutability)?) {
281 self.visit_user_type_annotation(
286 for var_debug_info in &$($mutability)? body.var_debug_info {
287 self.visit_var_debug_info(var_debug_info);
290 self.visit_span(&$($mutability)? body.span);
293 fn super_basic_block_data(&mut self,
295 data: & $($mutability)? BasicBlockData<'tcx>) {
303 for statement in statements {
304 let location = Location { block: block, statement_index: index };
305 self.visit_statement(statement, location);
309 if let Some(terminator) = terminator {
310 let location = Location { block: block, statement_index: index };
311 self.visit_terminator(terminator, location);
315 fn super_source_scope_data(&mut self, scope_data: & $($mutability)? SourceScopeData) {
316 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::LlvmInlineAsm(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 {
505 self.visit_operand(value, source_location);
508 PlaceContext::MutatingUse(MutatingUseContext::Store),
516 fn super_assert_message(&mut self,
517 msg: & $($mutability)? AssertMessage<'tcx>,
518 location: Location) {
519 use crate::mir::AssertKind::*;
521 BoundsCheck { len, index } => {
522 self.visit_operand(len, location);
523 self.visit_operand(index, location);
525 Overflow(_) | OverflowNeg | DivisionByZero | RemainderByZero |
526 ResumedAfterReturn(_) | ResumedAfterPanic(_) => {
532 fn super_rvalue(&mut self,
533 rvalue: & $($mutability)? Rvalue<'tcx>,
534 location: Location) {
536 Rvalue::Use(operand) => {
537 self.visit_operand(operand, location);
540 Rvalue::Repeat(value, _) => {
541 self.visit_operand(value, location);
544 Rvalue::Ref(r, bk, path) => {
545 self.visit_region(r, location);
547 BorrowKind::Shared => PlaceContext::NonMutatingUse(
548 NonMutatingUseContext::SharedBorrow
550 BorrowKind::Shallow => PlaceContext::NonMutatingUse(
551 NonMutatingUseContext::ShallowBorrow
553 BorrowKind::Unique => PlaceContext::NonMutatingUse(
554 NonMutatingUseContext::UniqueBorrow
556 BorrowKind::Mut { .. } =>
557 PlaceContext::MutatingUse(MutatingUseContext::Borrow),
559 self.visit_place(path, ctx, location);
562 Rvalue::AddressOf(m, path) => {
564 Mutability::Mut => PlaceContext::MutatingUse(
565 MutatingUseContext::AddressOf
567 Mutability::Not => PlaceContext::NonMutatingUse(
568 NonMutatingUseContext::AddressOf
571 self.visit_place(path, ctx, location);
574 Rvalue::Len(path) => {
577 PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
582 Rvalue::Cast(_cast_kind, operand, ty) => {
583 self.visit_operand(operand, location);
584 self.visit_ty(ty, TyContext::Location(location));
587 Rvalue::BinaryOp(_bin_op, lhs, rhs)
588 | Rvalue::CheckedBinaryOp(_bin_op, lhs, rhs) => {
589 self.visit_operand(lhs, location);
590 self.visit_operand(rhs, location);
593 Rvalue::UnaryOp(_un_op, op) => {
594 self.visit_operand(op, location);
597 Rvalue::Discriminant(place) => {
600 PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
605 Rvalue::NullaryOp(_op, ty) => {
606 self.visit_ty(ty, TyContext::Location(location));
609 Rvalue::Aggregate(kind, operands) => {
610 let kind = &$($mutability)? **kind;
612 AggregateKind::Array(ty) => {
613 self.visit_ty(ty, TyContext::Location(location));
615 AggregateKind::Tuple => {
624 self.visit_substs(substs, location);
626 AggregateKind::Closure(
630 self.visit_substs(closure_substs, location);
632 AggregateKind::Generator(
637 self.visit_substs(generator_substs, location);
641 for operand in operands {
642 self.visit_operand(operand, location);
648 fn super_operand(&mut self,
649 operand: & $($mutability)? Operand<'tcx>,
650 location: Location) {
652 Operand::Copy(place) => {
655 PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
659 Operand::Move(place) => {
662 PlaceContext::NonMutatingUse(NonMutatingUseContext::Move),
666 Operand::Constant(constant) => {
667 self.visit_constant(constant, location);
672 fn super_ascribe_user_ty(&mut self,
673 place: & $($mutability)? Place<'tcx>,
674 _variance: & $($mutability)? ty::Variance,
675 user_ty: & $($mutability)? UserTypeProjection,
676 location: Location) {
679 PlaceContext::NonUse(NonUseContext::AscribeUserTy),
682 self.visit_user_type_projection(user_ty);
685 fn super_retag(&mut self,
686 _kind: & $($mutability)? RetagKind,
687 place: & $($mutability)? Place<'tcx>,
688 location: Location) {
691 PlaceContext::MutatingUse(MutatingUseContext::Retag),
696 fn super_local_decl(&mut self,
698 local_decl: & $($mutability)? LocalDecl<'tcx>) {
709 self.visit_ty(ty, TyContext::LocalDecl {
711 source_info: *source_info,
713 for (user_ty, _) in & $($mutability)? user_ty.contents {
714 self.visit_user_type_projection(user_ty);
716 self.visit_source_info(source_info);
719 fn super_var_debug_info(&mut self,
720 var_debug_info: & $($mutability)? VarDebugInfo<'tcx>) {
727 self.visit_source_info(source_info);
728 let location = START_BLOCK.start_location();
731 PlaceContext::NonUse(NonUseContext::VarDebugInfo),
736 fn super_source_scope(&mut self,
737 _scope: & $($mutability)? SourceScope) {
740 fn super_constant(&mut self,
741 constant: & $($mutability)? Constant<'tcx>,
742 location: Location) {
749 self.visit_span(span);
750 drop(user_ty); // no visit method for this
751 self.visit_const(literal, location);
754 fn super_span(&mut self, _span: & $($mutability)? Span) {
757 fn super_source_info(&mut self, source_info: & $($mutability)? SourceInfo) {
763 self.visit_span(span);
764 self.visit_source_scope(scope);
767 fn super_user_type_projection(
769 _ty: & $($mutability)? UserTypeProjection,
773 fn super_user_type_annotation(
775 _index: UserTypeAnnotationIndex,
776 ty: & $($mutability)? CanonicalUserTypeAnnotation<'tcx>,
778 self.visit_span(& $($mutability)? ty.span);
779 self.visit_ty(& $($mutability)? ty.inferred_ty, TyContext::UserTy(ty.span));
782 fn super_ty(&mut self, _ty: $(& $mutability)? Ty<'tcx>) {
785 fn super_region(&mut self, _region: & $($mutability)? ty::Region<'tcx>) {
788 fn super_const(&mut self, _const: & $($mutability)? &'tcx ty::Const<'tcx>) {
791 fn super_substs(&mut self, _substs: & $($mutability)? SubstsRef<'tcx>) {
794 // Convenience methods
798 body: &$($mutability)? Body<'tcx>,
801 macro_rules! basic_blocks {
802 (mut) => (body.basic_blocks_mut());
803 () => (body.basic_blocks());
805 let basic_block = & $($mutability)? basic_blocks!($($mutability)?)[location.block];
806 if basic_block.statements.len() == location.statement_index {
807 if let Some(ref $($mutability)? terminator) = basic_block.terminator {
808 self.visit_terminator(terminator, location)
811 let statement = & $($mutability)?
812 basic_block.statements[location.statement_index];
813 self.visit_statement(statement, location)
820 macro_rules! visit_place_fns {
822 fn tcx<'a>(&'a self) -> TyCtxt<'tcx>;
826 place: &mut Place<'tcx>,
827 context: PlaceContext,
830 self.visit_local(&mut place.local, context, location);
832 if let Some(new_projection) = self.process_projection(&place.projection, location) {
833 place.projection = self.tcx().intern_place_elems(&new_projection);
837 fn process_projection(
839 projection: &'a [PlaceElem<'tcx>],
841 ) -> Option<Vec<PlaceElem<'tcx>>> {
842 let mut projection = Cow::Borrowed(projection);
844 for i in 0..projection.len() {
845 if let Some(elem) = projection.get(i) {
846 if let Some(elem) = self.process_projection_elem(elem, location) {
847 // This converts the borrowed projection into `Cow::Owned(_)` and returns a
848 // clone of the projection so we can mutate and reintern later.
849 let vec = projection.to_mut();
856 Cow::Borrowed(_) => None,
857 Cow::Owned(vec) => Some(vec),
861 fn process_projection_elem(
863 elem: &PlaceElem<'tcx>,
865 ) -> Option<PlaceElem<'tcx>> {
867 PlaceElem::Index(local) => {
868 let mut new_local = *local;
871 PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
875 if new_local == *local { None } else { Some(PlaceElem::Index(new_local)) }
878 | PlaceElem::Field(..)
879 | PlaceElem::ConstantIndex { .. }
880 | PlaceElem::Subslice { .. }
881 | PlaceElem::Downcast(..) => None,
890 projection: &[PlaceElem<'tcx>],
891 context: PlaceContext,
894 self.super_projection(local, projection, context, location);
897 fn visit_projection_elem(
900 proj_base: &[PlaceElem<'tcx>],
901 elem: &PlaceElem<'tcx>,
902 context: PlaceContext,
905 self.super_projection_elem(local, proj_base, elem, context, location);
908 fn super_place(&mut self, place: &Place<'tcx>, context: PlaceContext, location: Location) {
909 let mut context = context;
911 if !place.projection.is_empty() {
912 context = if context.is_mutating_use() {
913 PlaceContext::MutatingUse(MutatingUseContext::Projection)
915 PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
919 self.visit_local(&place.local, context, location);
921 self.visit_projection(place.local, &place.projection, context, location);
927 projection: &[PlaceElem<'tcx>],
928 context: PlaceContext,
931 let mut cursor = projection;
932 while let [proj_base @ .., elem] = cursor {
934 self.visit_projection_elem(local, cursor, elem, context, location);
938 fn super_projection_elem(
941 _proj_base: &[PlaceElem<'tcx>],
942 elem: &PlaceElem<'tcx>,
943 _context: PlaceContext,
947 ProjectionElem::Field(_field, ty) => {
948 self.visit_ty(ty, TyContext::Location(location));
950 ProjectionElem::Index(local) => {
953 PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
957 ProjectionElem::Deref
958 | ProjectionElem::Subslice { from: _, to: _, from_end: _ }
959 | ProjectionElem::ConstantIndex { offset: _, min_length: _, from_end: _ }
960 | ProjectionElem::Downcast(_, _) => {}
966 make_mir_visitor!(Visitor,);
967 make_mir_visitor!(MutVisitor, mut);
969 pub trait MirVisitable<'tcx> {
970 fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>);
973 impl<'tcx> MirVisitable<'tcx> for Statement<'tcx> {
974 fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>) {
975 visitor.visit_statement(self, location)
979 impl<'tcx> MirVisitable<'tcx> for Terminator<'tcx> {
980 fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>) {
981 visitor.visit_terminator(self, location)
985 impl<'tcx> MirVisitable<'tcx> for Option<Terminator<'tcx>> {
986 fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>) {
987 visitor.visit_terminator(self.as_ref().unwrap(), location)
991 /// Extra information passed to `visit_ty` and friends to give context
992 /// about where the type etc appears.
996 /// The index of the local variable we are visiting.
999 /// The source location where this local variable was declared.
1000 source_info: SourceInfo,
1003 /// The inferred type of a user type annotation.
1006 /// The return type of the function.
1007 ReturnTy(SourceInfo),
1009 YieldTy(SourceInfo),
1011 /// A type found at some location.
1015 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
1016 pub enum NonMutatingUseContext {
1017 /// Being inspected in some way, like loading a len.
1019 /// Consumed as part of an operand.
1021 /// Consumed as part of an operand.
1029 /// AddressOf for *const pointer.
1031 /// Used as base for another place, e.g., `x` in `x.y`. Will not mutate the place.
1032 /// For example, the projection `x.y` is not marked as a mutation in these cases:
1040 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
1041 pub enum MutatingUseContext {
1042 /// Appears as LHS of an assignment.
1044 /// Can often be treated as a `Store`, but needs to be separate because
1045 /// ASM is allowed to read outputs as well, so a `Store`-`AsmOutput` sequence
1046 /// cannot be simplified the way a `Store`-`Store` can be.
1048 /// Destination of a call.
1054 /// AddressOf for *mut pointer.
1056 /// Used as base for another place, e.g., `x` in `x.y`. Could potentially mutate the place.
1057 /// For example, the projection `x.y` is marked as a mutation in these cases:
1063 /// Retagging, a "Stacked Borrows" shadow state operation
1067 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
1068 pub enum NonUseContext {
1069 /// Starting a storage live range.
1071 /// Ending a storage live range.
1073 /// User type annotation assertions for NLL.
1075 /// The data of an user variable, for debug info.
1079 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
1080 pub enum PlaceContext {
1081 NonMutatingUse(NonMutatingUseContext),
1082 MutatingUse(MutatingUseContext),
1083 NonUse(NonUseContext),
1087 /// Returns `true` if this place context represents a drop.
1088 pub fn is_drop(&self) -> bool {
1090 PlaceContext::MutatingUse(MutatingUseContext::Drop) => true,
1095 /// Returns `true` if this place context represents a borrow.
1096 pub fn is_borrow(&self) -> bool {
1098 PlaceContext::NonMutatingUse(
1099 NonMutatingUseContext::SharedBorrow
1100 | NonMutatingUseContext::ShallowBorrow
1101 | NonMutatingUseContext::UniqueBorrow,
1103 | PlaceContext::MutatingUse(MutatingUseContext::Borrow) => true,
1108 /// Returns `true` if this place context represents a storage live or storage dead marker.
1109 pub fn is_storage_marker(&self) -> bool {
1111 PlaceContext::NonUse(NonUseContext::StorageLive | NonUseContext::StorageDead) => true,
1116 /// Returns `true` if this place context represents a storage live marker.
1117 pub fn is_storage_live_marker(&self) -> bool {
1119 PlaceContext::NonUse(NonUseContext::StorageLive) => true,
1124 /// Returns `true` if this place context represents a storage dead marker.
1125 pub fn is_storage_dead_marker(&self) -> bool {
1127 PlaceContext::NonUse(NonUseContext::StorageDead) => true,
1132 /// Returns `true` if this place context represents a use that potentially changes the value.
1133 pub fn is_mutating_use(&self) -> bool {
1135 PlaceContext::MutatingUse(..) => true,
1140 /// Returns `true` if this place context represents a use that does not change the value.
1141 pub fn is_nonmutating_use(&self) -> bool {
1143 PlaceContext::NonMutatingUse(..) => true,
1148 /// Returns `true` if this place context represents a use.
1149 pub fn is_use(&self) -> bool {
1151 PlaceContext::NonUse(..) => false,
1156 /// Returns `true` if this place context represents an assignment statement.
1157 pub fn is_place_assignment(&self) -> bool {
1159 PlaceContext::MutatingUse(
1160 MutatingUseContext::Store
1161 | MutatingUseContext::Call
1162 | MutatingUseContext::AsmOutput,