2019-02-09 22:11:53 +08:00
|
|
|
use crate::ty::subst::SubstsRef;
|
2019-10-03 21:30:26 +08:00
|
|
|
use crate::ty::{CanonicalUserTypeAnnotation, Ty};
|
2019-02-05 11:20:45 -06:00
|
|
|
use crate::mir::*;
|
2019-10-09 23:22:58 -04:00
|
|
|
use crate::mir::cache::*;
|
2016-06-21 18:08:13 -04:00
|
|
|
use syntax_pos::Span;
|
2015-11-03 06:33:59 -05:00
|
|
|
|
2016-03-24 06:12:19 -04:00
|
|
|
// # The MIR Visitor
|
|
|
|
//
|
|
|
|
// ## Overview
|
|
|
|
//
|
|
|
|
// There are two visitors, one for immutable and one for mutable references,
|
|
|
|
// but both are generated by the following macro. The code is written according
|
|
|
|
// to the following conventions:
|
|
|
|
//
|
|
|
|
// - introduce a `visit_foo` and a `super_foo` method for every MIR type
|
|
|
|
// - `visit_foo`, by default, calls `super_foo`
|
|
|
|
// - `super_foo`, by default, destructures the `foo` and calls `visit_foo`
|
|
|
|
//
|
|
|
|
// This allows you as a user to override `visit_foo` for types are
|
|
|
|
// interested in, and invoke (within that method) call
|
|
|
|
// `self.super_foo` to get the default behavior. Just as in an OO
|
|
|
|
// language, you should never call `super` methods ordinarily except
|
|
|
|
// in that circumstance.
|
|
|
|
//
|
|
|
|
// For the most part, we do not destructure things external to the
|
2018-11-27 02:59:49 +00:00
|
|
|
// MIR, e.g., types, spans, etc, but simply visit them and stop. This
|
2016-07-31 22:33:41 +08:00
|
|
|
// avoids duplication with other visitors like `TypeFoldable`.
|
2016-03-24 06:12:19 -04:00
|
|
|
//
|
|
|
|
// ## Updating
|
|
|
|
//
|
|
|
|
// The code is written in a very deliberate style intended to minimize
|
|
|
|
// the chance of things being overlooked. You'll notice that we always
|
|
|
|
// use pattern matching to reference fields and we ensure that all
|
|
|
|
// matches are exhaustive.
|
|
|
|
//
|
|
|
|
// For example, the `super_basic_block_data` method begins like this:
|
|
|
|
//
|
|
|
|
// ```rust
|
|
|
|
// fn super_basic_block_data(&mut self,
|
|
|
|
// block: BasicBlock,
|
2019-02-09 16:29:31 +00:00
|
|
|
// data: & $($mutability)? BasicBlockData<'tcx>) {
|
2016-03-24 06:12:19 -04:00
|
|
|
// let BasicBlockData {
|
2019-02-09 16:29:31 +00:00
|
|
|
// statements,
|
|
|
|
// terminator,
|
2016-03-24 06:12:19 -04:00
|
|
|
// is_cleanup: _
|
|
|
|
// } = *data;
|
|
|
|
//
|
|
|
|
// for statement in statements {
|
|
|
|
// self.visit_statement(block, statement);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// ...
|
|
|
|
// }
|
|
|
|
// ```
|
|
|
|
//
|
|
|
|
// Here we used `let BasicBlockData { <fields> } = *data` deliberately,
|
|
|
|
// rather than writing `data.statements` in the body. This is because if one
|
|
|
|
// adds a new field to `BasicBlockData`, one will be forced to revise this code,
|
|
|
|
// and hence one will (hopefully) invoke the correct visit methods (if any).
|
|
|
|
//
|
|
|
|
// For this to work, ALL MATCHES MUST BE EXHAUSTIVE IN FIELDS AND VARIANTS.
|
|
|
|
// That means you never write `..` to skip over fields, nor do you write `_`
|
|
|
|
// to skip over variants in a `match`.
|
|
|
|
//
|
|
|
|
// The only place that `_` is acceptable is to match a field (or
|
|
|
|
// variant argument) that does not require visiting, as in
|
|
|
|
// `is_cleanup` above.
|
|
|
|
|
2016-01-07 05:49:46 -05:00
|
|
|
macro_rules! make_mir_visitor {
|
2019-02-09 16:29:31 +00:00
|
|
|
($visitor_trait_name:ident, $($mutability:ident)?) => {
|
2016-01-07 05:49:46 -05:00
|
|
|
pub trait $visitor_trait_name<'tcx> {
|
|
|
|
// Override these, and call `self.super_xxx` to revert back to the
|
|
|
|
// default behavior.
|
2015-11-03 06:33:59 -05:00
|
|
|
|
2019-10-09 23:22:58 -04:00
|
|
|
fn visit_body(&mut self, body_cache: & $($mutability)? cache_type!('tcx $($mutability)?)) {
|
|
|
|
self.super_body(body_cache);
|
2015-11-03 06:33:59 -05:00
|
|
|
}
|
|
|
|
|
2016-01-07 05:49:46 -05:00
|
|
|
fn visit_basic_block_data(&mut self,
|
|
|
|
block: BasicBlock,
|
2019-02-09 16:29:31 +00:00
|
|
|
data: & $($mutability)? BasicBlockData<'tcx>) {
|
2016-01-07 05:49:46 -05:00
|
|
|
self.super_basic_block_data(block, data);
|
2015-11-03 06:33:59 -05:00
|
|
|
}
|
|
|
|
|
2018-05-28 14:16:09 +03:00
|
|
|
fn visit_source_scope_data(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
scope_data: & $($mutability)? SourceScopeData) {
|
2018-05-28 14:16:09 +03:00
|
|
|
self.super_source_scope_data(scope_data);
|
2016-03-24 06:12:19 -04:00
|
|
|
}
|
|
|
|
|
2016-01-07 05:49:46 -05:00
|
|
|
fn visit_statement(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
statement: & $($mutability)? Statement<'tcx>,
|
2016-08-08 18:46:06 -07:00
|
|
|
location: Location) {
|
2019-04-22 21:07:14 +01:00
|
|
|
self.super_statement(statement, location);
|
2015-11-03 06:33:59 -05:00
|
|
|
}
|
|
|
|
|
2016-01-07 05:49:46 -05:00
|
|
|
fn visit_assign(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
place: & $($mutability)? Place<'tcx>,
|
|
|
|
rvalue: & $($mutability)? Rvalue<'tcx>,
|
2016-08-08 18:46:06 -07:00
|
|
|
location: Location) {
|
2019-04-22 21:07:14 +01:00
|
|
|
self.super_assign(place, rvalue, location);
|
2015-11-03 06:33:59 -05:00
|
|
|
}
|
|
|
|
|
2016-01-07 05:49:46 -05:00
|
|
|
fn visit_terminator(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
terminator: & $($mutability)? Terminator<'tcx>,
|
2016-08-08 18:46:06 -07:00
|
|
|
location: Location) {
|
2019-04-22 21:07:14 +01:00
|
|
|
self.super_terminator(terminator, location);
|
2015-10-26 14:35:18 -04:00
|
|
|
}
|
|
|
|
|
2016-03-24 06:12:19 -04:00
|
|
|
fn visit_terminator_kind(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
kind: & $($mutability)? TerminatorKind<'tcx>,
|
2016-08-08 18:46:06 -07:00
|
|
|
location: Location) {
|
2019-04-22 21:07:14 +01:00
|
|
|
self.super_terminator_kind(kind, location);
|
2016-03-24 06:12:19 -04:00
|
|
|
}
|
|
|
|
|
2016-05-25 08:39:32 +03:00
|
|
|
fn visit_assert_message(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
msg: & $($mutability)? AssertMessage<'tcx>,
|
2016-08-08 18:46:06 -07:00
|
|
|
location: Location) {
|
|
|
|
self.super_assert_message(msg, location);
|
2016-05-25 08:39:32 +03:00
|
|
|
}
|
|
|
|
|
2016-01-07 05:49:46 -05:00
|
|
|
fn visit_rvalue(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
rvalue: & $($mutability)? Rvalue<'tcx>,
|
2016-08-08 18:46:06 -07:00
|
|
|
location: Location) {
|
|
|
|
self.super_rvalue(rvalue, location);
|
2015-11-03 06:33:59 -05:00
|
|
|
}
|
|
|
|
|
2016-01-07 05:49:46 -05:00
|
|
|
fn visit_operand(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
operand: & $($mutability)? Operand<'tcx>,
|
2016-08-08 18:46:06 -07:00
|
|
|
location: Location) {
|
|
|
|
self.super_operand(operand, location);
|
2015-12-14 23:27:58 +02:00
|
|
|
}
|
2015-11-03 06:33:59 -05:00
|
|
|
|
2018-08-31 18:59:35 -04:00
|
|
|
fn visit_ascribe_user_ty(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
place: & $($mutability)? Place<'tcx>,
|
|
|
|
variance: & $($mutability)? ty::Variance,
|
2019-03-28 18:00:17 -07:00
|
|
|
user_ty: & $($mutability)? UserTypeProjection,
|
2018-08-31 18:59:35 -04:00
|
|
|
location: Location) {
|
2018-10-10 17:07:10 -04:00
|
|
|
self.super_ascribe_user_ty(place, variance, user_ty, location);
|
2018-02-23 20:52:05 +00:00
|
|
|
}
|
|
|
|
|
2018-10-24 13:47:48 +02:00
|
|
|
fn visit_retag(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
kind: & $($mutability)? RetagKind,
|
|
|
|
place: & $($mutability)? Place<'tcx>,
|
2018-10-24 13:47:48 +02:00
|
|
|
location: Location) {
|
2018-12-11 19:54:38 +01:00
|
|
|
self.super_retag(kind, place, location);
|
2018-10-24 13:47:48 +02:00
|
|
|
}
|
|
|
|
|
2017-12-01 14:39:51 +02:00
|
|
|
fn visit_place(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
place: & $($mutability)? Place<'tcx>,
|
2019-04-24 19:41:43 +01:00
|
|
|
context: PlaceContext,
|
2016-08-08 18:46:06 -07:00
|
|
|
location: Location) {
|
2017-12-01 14:39:51 +02:00
|
|
|
self.super_place(place, context, location);
|
2015-11-03 06:33:59 -05:00
|
|
|
}
|
|
|
|
|
2019-06-05 19:56:11 +02:00
|
|
|
fn visit_place_base(&mut self,
|
2019-07-30 00:07:28 +02:00
|
|
|
base: & $($mutability)? PlaceBase<'tcx>,
|
2019-04-24 19:41:43 +01:00
|
|
|
context: PlaceContext,
|
2016-08-08 18:46:06 -07:00
|
|
|
location: Location) {
|
2019-07-30 00:07:28 +02:00
|
|
|
self.super_place_base(base, context, location);
|
2016-03-24 06:12:19 -04:00
|
|
|
}
|
|
|
|
|
2019-10-08 12:16:26 -03:00
|
|
|
visit_place_fns!($($mutability)?);
|
2019-10-02 18:03:23 -03:00
|
|
|
|
2016-01-07 05:49:46 -05:00
|
|
|
fn visit_constant(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
constant: & $($mutability)? Constant<'tcx>,
|
2016-08-08 18:46:06 -07:00
|
|
|
location: Location) {
|
|
|
|
self.super_constant(constant, location);
|
2015-11-03 06:33:59 -05:00
|
|
|
}
|
|
|
|
|
2016-01-07 05:49:46 -05:00
|
|
|
fn visit_span(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
span: & $($mutability)? Span) {
|
2016-01-07 05:49:46 -05:00
|
|
|
self.super_span(span);
|
2015-11-03 06:33:59 -05:00
|
|
|
}
|
|
|
|
|
2016-06-07 19:21:56 +03:00
|
|
|
fn visit_source_info(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
source_info: & $($mutability)? SourceInfo) {
|
2016-06-07 19:21:56 +03:00
|
|
|
self.super_source_info(source_info);
|
|
|
|
}
|
|
|
|
|
2016-03-24 06:12:19 -04:00
|
|
|
fn visit_ty(&mut self,
|
2019-04-25 22:54:19 +02:00
|
|
|
ty: $(& $mutability)? Ty<'tcx>,
|
2017-10-26 19:53:31 -04:00
|
|
|
_: TyContext) {
|
2016-03-24 06:12:19 -04:00
|
|
|
self.super_ty(ty);
|
|
|
|
}
|
|
|
|
|
2018-10-22 11:58:06 +02:00
|
|
|
fn visit_user_type_projection(
|
|
|
|
&mut self,
|
2019-03-28 18:00:17 -07:00
|
|
|
ty: & $($mutability)? UserTypeProjection,
|
2018-10-22 11:58:06 +02:00
|
|
|
) {
|
|
|
|
self.super_user_type_projection(ty);
|
|
|
|
}
|
|
|
|
|
2018-10-15 09:31:38 -04:00
|
|
|
fn visit_user_type_annotation(
|
|
|
|
&mut self,
|
2018-11-16 22:56:18 +01:00
|
|
|
index: UserTypeAnnotationIndex,
|
2019-02-09 16:29:31 +00:00
|
|
|
ty: & $($mutability)? CanonicalUserTypeAnnotation<'tcx>,
|
2018-10-15 09:31:38 -04:00
|
|
|
) {
|
2018-11-16 22:56:18 +01:00
|
|
|
self.super_user_type_annotation(index, ty);
|
2018-08-09 06:18:00 -04:00
|
|
|
}
|
|
|
|
|
2017-08-04 11:25:13 +03:00
|
|
|
fn visit_region(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
region: & $($mutability)? ty::Region<'tcx>,
|
2017-08-04 11:25:13 +03:00
|
|
|
_: Location) {
|
|
|
|
self.super_region(region);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_const(&mut self,
|
2019-03-14 10:19:31 +01:00
|
|
|
constant: & $($mutability)? &'tcx ty::Const<'tcx>,
|
2017-08-04 11:25:13 +03:00
|
|
|
_: Location) {
|
|
|
|
self.super_const(constant);
|
|
|
|
}
|
|
|
|
|
2016-03-24 06:12:19 -04:00
|
|
|
fn visit_substs(&mut self,
|
2019-02-09 22:11:53 +08:00
|
|
|
substs: & $($mutability)? SubstsRef<'tcx>,
|
2017-07-18 22:31:38 -04:00
|
|
|
_: Location) {
|
2016-03-24 06:12:19 -04:00
|
|
|
self.super_substs(substs);
|
|
|
|
}
|
|
|
|
|
2016-09-25 01:38:27 +02:00
|
|
|
fn visit_local_decl(&mut self,
|
2017-10-26 19:53:31 -04:00
|
|
|
local: Local,
|
2019-02-09 16:29:31 +00:00
|
|
|
local_decl: & $($mutability)? LocalDecl<'tcx>) {
|
2017-10-26 19:53:31 -04:00
|
|
|
self.super_local_decl(local, local_decl);
|
2016-03-24 06:12:19 -04:00
|
|
|
}
|
|
|
|
|
2018-05-16 18:58:54 +03:00
|
|
|
fn visit_var_debug_info(&mut self,
|
|
|
|
var_debug_info: & $($mutability)* VarDebugInfo<'tcx>) {
|
|
|
|
self.super_var_debug_info(var_debug_info);
|
|
|
|
}
|
|
|
|
|
2016-12-26 14:34:03 +01:00
|
|
|
fn visit_local(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
_local: & $($mutability)? Local,
|
2019-04-24 19:41:43 +01:00
|
|
|
_context: PlaceContext,
|
2017-09-03 19:14:31 +03:00
|
|
|
_location: Location) {
|
2016-12-26 14:34:03 +01:00
|
|
|
}
|
|
|
|
|
2018-05-28 14:16:09 +03:00
|
|
|
fn visit_source_scope(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
scope: & $($mutability)? SourceScope) {
|
2018-05-28 14:16:09 +03:00
|
|
|
self.super_source_scope(scope);
|
2016-03-24 06:12:19 -04:00
|
|
|
}
|
|
|
|
|
2016-01-07 05:49:46 -05:00
|
|
|
// The `super_xxx` methods comprise the default behavior and are
|
2016-02-09 11:52:39 -05:00
|
|
|
// not meant to be overridden.
|
2015-11-03 06:33:59 -05:00
|
|
|
|
2019-05-17 23:55:04 +02:00
|
|
|
fn super_body(&mut self,
|
2019-10-09 23:22:58 -04:00
|
|
|
body_cache: & $($mutability)? cache_type!('tcx $($mutability)?)) {
|
|
|
|
let span = body_cache.body().span;
|
|
|
|
if let Some(yield_ty) = &$($mutability)? body_cache.body().yield_ty {
|
2018-01-19 19:18:02 -03:00
|
|
|
self.visit_ty(yield_ty, TyContext::YieldTy(SourceInfo {
|
2019-10-09 23:22:58 -04:00
|
|
|
span,
|
2018-05-28 14:16:09 +03:00
|
|
|
scope: OUTERMOST_SOURCE_SCOPE,
|
2018-01-19 19:18:02 -03:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2017-08-01 00:09:32 +03:00
|
|
|
// for best performance, we want to use an iterator rather
|
2019-06-03 18:26:48 -04:00
|
|
|
// than a for-loop, to avoid calling `body::Body::invalidate` for
|
2017-08-01 00:09:32 +03:00
|
|
|
// each basic block.
|
|
|
|
macro_rules! basic_blocks {
|
2019-10-09 23:22:58 -04:00
|
|
|
(mut) => (body_cache.basic_blocks_mut().iter_enumerated_mut());
|
|
|
|
() => (body_cache.basic_blocks().iter_enumerated());
|
2017-08-01 00:09:32 +03:00
|
|
|
};
|
2019-02-09 16:29:31 +00:00
|
|
|
for (bb, data) in basic_blocks!($($mutability)?) {
|
2017-08-01 00:09:32 +03:00
|
|
|
self.visit_basic_block_data(bb, data);
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
2016-03-24 06:12:19 -04:00
|
|
|
|
2019-10-09 23:22:58 -04:00
|
|
|
let body = body_cache.body();
|
2019-06-03 18:26:48 -04:00
|
|
|
for scope in &$($mutability)? body.source_scopes {
|
2018-05-28 14:16:09 +03:00
|
|
|
self.visit_source_scope_data(scope);
|
2016-03-24 06:12:19 -04:00
|
|
|
}
|
|
|
|
|
2019-06-03 18:26:48 -04:00
|
|
|
self.visit_ty(&$($mutability)? body.return_ty(), TyContext::ReturnTy(SourceInfo {
|
|
|
|
span: body.span,
|
2018-05-28 14:16:09 +03:00
|
|
|
scope: OUTERMOST_SOURCE_SCOPE,
|
2017-11-07 04:30:06 -05:00
|
|
|
}));
|
2016-03-24 06:12:19 -04:00
|
|
|
|
2019-06-03 18:26:48 -04:00
|
|
|
for local in body.local_decls.indices() {
|
|
|
|
self.visit_local_decl(local, & $($mutability)? body.local_decls[local]);
|
2016-03-24 06:12:19 -04:00
|
|
|
}
|
|
|
|
|
2019-01-06 17:10:53 +00:00
|
|
|
macro_rules! type_annotations {
|
2019-06-03 18:26:48 -04:00
|
|
|
(mut) => (body.user_type_annotations.iter_enumerated_mut());
|
|
|
|
() => (body.user_type_annotations.iter_enumerated());
|
2019-01-06 17:10:53 +00:00
|
|
|
};
|
|
|
|
|
2019-02-09 16:29:31 +00:00
|
|
|
for (index, annotation) in type_annotations!($($mutability)?) {
|
2018-11-16 22:56:18 +01:00
|
|
|
self.visit_user_type_annotation(
|
|
|
|
index, annotation
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-05-16 18:58:54 +03:00
|
|
|
for var_debug_info in &$($mutability)? body.var_debug_info {
|
|
|
|
self.visit_var_debug_info(var_debug_info);
|
|
|
|
}
|
|
|
|
|
2019-06-03 18:26:48 -04:00
|
|
|
self.visit_span(&$($mutability)? body.span);
|
2015-11-03 06:33:59 -05:00
|
|
|
}
|
|
|
|
|
2016-01-07 05:49:46 -05:00
|
|
|
fn super_basic_block_data(&mut self,
|
|
|
|
block: BasicBlock,
|
2019-02-09 16:29:31 +00:00
|
|
|
data: & $($mutability)? BasicBlockData<'tcx>) {
|
2016-03-24 06:12:19 -04:00
|
|
|
let BasicBlockData {
|
2019-02-09 16:29:31 +00:00
|
|
|
statements,
|
|
|
|
terminator,
|
2016-03-24 06:12:19 -04:00
|
|
|
is_cleanup: _
|
2019-02-09 16:29:31 +00:00
|
|
|
} = data;
|
2016-03-24 06:12:19 -04:00
|
|
|
|
2016-08-08 18:46:06 -07:00
|
|
|
let mut index = 0;
|
2016-03-24 06:12:19 -04:00
|
|
|
for statement in statements {
|
2016-08-08 18:46:06 -07:00
|
|
|
let location = Location { block: block, statement_index: index };
|
2019-04-22 21:07:14 +01:00
|
|
|
self.visit_statement(statement, location);
|
2016-08-08 18:46:06 -07:00
|
|
|
index += 1;
|
2015-11-03 06:33:59 -05:00
|
|
|
}
|
|
|
|
|
2019-02-09 16:29:31 +00:00
|
|
|
if let Some(terminator) = terminator {
|
2016-08-08 18:46:06 -07:00
|
|
|
let location = Location { block: block, statement_index: index };
|
2019-04-22 21:07:14 +01:00
|
|
|
self.visit_terminator(terminator, location);
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
2015-11-03 06:33:59 -05:00
|
|
|
}
|
|
|
|
|
2019-02-09 16:29:31 +00:00
|
|
|
fn super_source_scope_data(&mut self, scope_data: & $($mutability)? SourceScopeData) {
|
2018-05-28 14:16:09 +03:00
|
|
|
let SourceScopeData {
|
2019-02-09 16:29:31 +00:00
|
|
|
span,
|
|
|
|
parent_scope,
|
2019-11-26 22:17:35 +02:00
|
|
|
local_data: _,
|
2019-02-09 16:29:31 +00:00
|
|
|
} = scope_data;
|
2016-03-24 06:12:19 -04:00
|
|
|
|
2016-04-06 17:17:12 +03:00
|
|
|
self.visit_span(span);
|
2019-02-09 16:29:31 +00:00
|
|
|
if let Some(parent_scope) = parent_scope {
|
2018-05-28 14:16:09 +03:00
|
|
|
self.visit_source_scope(parent_scope);
|
2016-03-24 06:12:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-07 05:49:46 -05:00
|
|
|
fn super_statement(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
statement: & $($mutability)? Statement<'tcx>,
|
2016-08-08 18:46:06 -07:00
|
|
|
location: Location) {
|
2016-03-24 06:12:19 -04:00
|
|
|
let Statement {
|
2019-02-09 16:29:31 +00:00
|
|
|
source_info,
|
|
|
|
kind,
|
|
|
|
} = statement;
|
2016-03-24 06:12:19 -04:00
|
|
|
|
2016-06-07 19:21:56 +03:00
|
|
|
self.visit_source_info(source_info);
|
2019-02-09 16:29:31 +00:00
|
|
|
match kind {
|
2019-09-11 16:05:45 -03:00
|
|
|
StatementKind::Assign(
|
|
|
|
box(ref $($mutability)? place, ref $($mutability)? rvalue)
|
|
|
|
) => {
|
2019-04-22 21:07:14 +01:00
|
|
|
self.visit_assign(place, rvalue, location);
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
2019-02-09 16:29:31 +00:00
|
|
|
StatementKind::FakeRead(_, place) => {
|
2018-10-26 13:22:45 +02:00
|
|
|
self.visit_place(
|
|
|
|
place,
|
|
|
|
PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
|
|
|
|
location
|
|
|
|
);
|
2018-05-04 12:04:33 +02:00
|
|
|
}
|
2019-02-09 16:29:31 +00:00
|
|
|
StatementKind::SetDiscriminant { place, .. } => {
|
2018-10-26 13:22:45 +02:00
|
|
|
self.visit_place(
|
|
|
|
place,
|
|
|
|
PlaceContext::MutatingUse(MutatingUseContext::Store),
|
|
|
|
location
|
|
|
|
);
|
2016-08-04 16:14:33 -07:00
|
|
|
}
|
2019-02-09 16:29:31 +00:00
|
|
|
StatementKind::StorageLive(local) => {
|
2018-10-26 13:22:45 +02:00
|
|
|
self.visit_local(
|
|
|
|
local,
|
|
|
|
PlaceContext::NonUse(NonUseContext::StorageLive),
|
|
|
|
location
|
|
|
|
);
|
2016-08-14 06:34:14 +03:00
|
|
|
}
|
2019-02-09 16:29:31 +00:00
|
|
|
StatementKind::StorageDead(local) => {
|
2018-10-26 13:22:45 +02:00
|
|
|
self.visit_local(
|
|
|
|
local,
|
|
|
|
PlaceContext::NonUse(NonUseContext::StorageDead),
|
|
|
|
location
|
|
|
|
);
|
2016-08-14 06:34:14 +03:00
|
|
|
}
|
2019-04-02 20:07:09 +11:00
|
|
|
StatementKind::InlineAsm(asm) => {
|
|
|
|
for output in & $($mutability)? asm.outputs[..] {
|
2018-10-26 13:22:45 +02:00
|
|
|
self.visit_place(
|
|
|
|
output,
|
|
|
|
PlaceContext::MutatingUse(MutatingUseContext::AsmOutput),
|
|
|
|
location
|
|
|
|
);
|
2017-02-15 21:21:36 +02:00
|
|
|
}
|
2019-04-02 20:07:09 +11:00
|
|
|
for (span, input) in & $($mutability)? asm.inputs[..] {
|
2018-10-15 00:00:53 +02:00
|
|
|
self.visit_span(span);
|
2017-02-15 21:21:36 +02:00
|
|
|
self.visit_operand(input, location);
|
|
|
|
}
|
|
|
|
}
|
2019-02-09 16:29:31 +00:00
|
|
|
StatementKind::Retag(kind, place) => {
|
2018-12-11 19:54:38 +01:00
|
|
|
self.visit_retag(kind, place, location);
|
2018-10-24 13:47:48 +02:00
|
|
|
}
|
2019-09-11 16:05:45 -03:00
|
|
|
StatementKind::AscribeUserType(
|
|
|
|
box(ref $($mutability)? place, ref $($mutability)? user_ty),
|
|
|
|
variance
|
|
|
|
) => {
|
2018-10-10 17:07:10 -04:00
|
|
|
self.visit_ascribe_user_ty(place, variance, user_ty, location);
|
2018-02-23 20:52:05 +00:00
|
|
|
}
|
2016-09-15 18:17:58 -07:00
|
|
|
StatementKind::Nop => {}
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
2015-11-03 06:33:59 -05:00
|
|
|
}
|
2015-12-08 14:07:25 -05:00
|
|
|
|
2016-01-07 05:49:46 -05:00
|
|
|
fn super_assign(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
place: &$($mutability)? Place<'tcx>,
|
|
|
|
rvalue: &$($mutability)? Rvalue<'tcx>,
|
2016-08-08 18:46:06 -07:00
|
|
|
location: Location) {
|
2018-10-26 13:22:45 +02:00
|
|
|
self.visit_place(
|
|
|
|
place,
|
|
|
|
PlaceContext::MutatingUse(MutatingUseContext::Store),
|
|
|
|
location
|
|
|
|
);
|
2016-08-08 18:46:06 -07:00
|
|
|
self.visit_rvalue(rvalue, location);
|
2015-12-08 14:07:25 -05:00
|
|
|
}
|
2015-12-08 14:09:16 -05:00
|
|
|
|
2016-01-07 05:49:46 -05:00
|
|
|
fn super_terminator(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
terminator: &$($mutability)? Terminator<'tcx>,
|
2016-08-08 18:46:06 -07:00
|
|
|
location: Location) {
|
2019-02-09 16:29:31 +00:00
|
|
|
let Terminator { source_info, kind } = terminator;
|
2016-03-24 06:12:19 -04:00
|
|
|
|
2016-06-07 19:21:56 +03:00
|
|
|
self.visit_source_info(source_info);
|
2019-04-22 21:07:14 +01:00
|
|
|
self.visit_terminator_kind(kind, location);
|
2016-03-24 06:12:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn super_terminator_kind(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
kind: & $($mutability)? TerminatorKind<'tcx>,
|
2016-08-08 18:46:06 -07:00
|
|
|
source_location: Location) {
|
2019-02-09 16:29:31 +00:00
|
|
|
match kind {
|
2019-04-26 21:36:36 +01:00
|
|
|
TerminatorKind::Goto { .. } |
|
|
|
|
TerminatorKind::Resume |
|
|
|
|
TerminatorKind::Abort |
|
|
|
|
TerminatorKind::Return |
|
|
|
|
TerminatorKind::GeneratorDrop |
|
|
|
|
TerminatorKind::Unreachable |
|
|
|
|
TerminatorKind::FalseEdges { .. } |
|
|
|
|
TerminatorKind::FalseUnwind { .. } => {
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
2015-12-08 14:09:16 -05:00
|
|
|
|
2019-02-09 16:29:31 +00:00
|
|
|
TerminatorKind::SwitchInt {
|
|
|
|
discr,
|
|
|
|
switch_ty,
|
|
|
|
values: _,
|
2019-04-26 21:36:36 +01:00
|
|
|
targets: _
|
2019-02-09 16:29:31 +00:00
|
|
|
} => {
|
2017-01-31 05:32:08 +02:00
|
|
|
self.visit_operand(discr, source_location);
|
2017-10-26 19:53:31 -04:00
|
|
|
self.visit_ty(switch_ty, TyContext::Location(source_location));
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
2015-12-08 14:09:16 -05:00
|
|
|
|
2019-02-09 16:29:31 +00:00
|
|
|
TerminatorKind::Drop {
|
|
|
|
location,
|
2019-04-26 21:36:36 +01:00
|
|
|
target: _,
|
|
|
|
unwind: _,
|
2019-02-09 16:29:31 +00:00
|
|
|
} => {
|
2018-10-26 13:22:45 +02:00
|
|
|
self.visit_place(
|
|
|
|
location,
|
|
|
|
PlaceContext::MutatingUse(MutatingUseContext::Drop),
|
|
|
|
source_location
|
|
|
|
);
|
2016-05-17 01:06:52 +03:00
|
|
|
}
|
|
|
|
|
2019-02-09 16:29:31 +00:00
|
|
|
TerminatorKind::DropAndReplace {
|
|
|
|
location,
|
|
|
|
value,
|
2019-04-26 21:36:36 +01:00
|
|
|
target: _,
|
|
|
|
unwind: _,
|
2019-02-09 16:29:31 +00:00
|
|
|
} => {
|
2018-10-26 13:22:45 +02:00
|
|
|
self.visit_place(
|
|
|
|
location,
|
|
|
|
PlaceContext::MutatingUse(MutatingUseContext::Drop),
|
|
|
|
source_location
|
|
|
|
);
|
2016-08-08 18:46:06 -07:00
|
|
|
self.visit_operand(value, source_location);
|
2016-01-30 00:18:47 +02:00
|
|
|
}
|
|
|
|
|
2019-02-09 16:29:31 +00:00
|
|
|
TerminatorKind::Call {
|
|
|
|
func,
|
|
|
|
args,
|
|
|
|
destination,
|
2019-04-26 21:36:36 +01:00
|
|
|
cleanup: _,
|
2019-02-09 16:29:31 +00:00
|
|
|
from_hir_call: _,
|
|
|
|
} => {
|
2016-08-08 18:46:06 -07:00
|
|
|
self.visit_operand(func, source_location);
|
2016-01-07 05:49:46 -05:00
|
|
|
for arg in args {
|
2016-08-08 18:46:06 -07:00
|
|
|
self.visit_operand(arg, source_location);
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
2019-04-26 21:36:36 +01:00
|
|
|
if let Some((destination, _)) = destination {
|
2018-10-26 13:22:45 +02:00
|
|
|
self.visit_place(
|
|
|
|
destination,
|
|
|
|
PlaceContext::MutatingUse(MutatingUseContext::Call),
|
|
|
|
source_location
|
|
|
|
);
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
|
|
|
}
|
2016-05-25 08:39:32 +03:00
|
|
|
|
2019-02-09 16:29:31 +00:00
|
|
|
TerminatorKind::Assert {
|
|
|
|
cond,
|
|
|
|
expected: _,
|
|
|
|
msg,
|
2019-04-26 21:36:36 +01:00
|
|
|
target: _,
|
|
|
|
cleanup: _,
|
2019-02-09 16:29:31 +00:00
|
|
|
} => {
|
2016-08-08 18:46:06 -07:00
|
|
|
self.visit_operand(cond, source_location);
|
|
|
|
self.visit_assert_message(msg, source_location);
|
2016-05-25 08:39:32 +03:00
|
|
|
}
|
2016-12-26 14:34:03 +01:00
|
|
|
|
2019-02-09 16:29:31 +00:00
|
|
|
TerminatorKind::Yield {
|
|
|
|
value,
|
2019-04-26 21:36:36 +01:00
|
|
|
resume: _,
|
|
|
|
drop: _,
|
2019-02-09 16:29:31 +00:00
|
|
|
} => {
|
2016-12-26 14:34:03 +01:00
|
|
|
self.visit_operand(value, source_location);
|
|
|
|
}
|
|
|
|
|
2016-05-25 08:39:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_assert_message(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
msg: & $($mutability)? AssertMessage<'tcx>,
|
2016-08-08 18:46:06 -07:00
|
|
|
location: Location) {
|
2019-07-29 13:28:55 +05:30
|
|
|
use crate::mir::interpret::PanicInfo::*;
|
2019-07-24 10:24:55 +02:00
|
|
|
match msg {
|
|
|
|
BoundsCheck { len, index } => {
|
|
|
|
self.visit_operand(len, location);
|
|
|
|
self.visit_operand(index, location);
|
|
|
|
}
|
|
|
|
Panic { .. } | Overflow(_) | OverflowNeg | DivisionByZero | RemainderByZero |
|
2019-11-26 00:30:07 +00:00
|
|
|
ResumedAfterReturn(_) | ResumedAfterPanic(_) => {
|
2019-07-24 10:24:55 +02:00
|
|
|
// Nothing to visit
|
|
|
|
}
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
|
|
|
}
|
2015-12-08 14:09:16 -05:00
|
|
|
|
2016-01-07 05:49:46 -05:00
|
|
|
fn super_rvalue(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
rvalue: & $($mutability)? Rvalue<'tcx>,
|
2016-08-08 18:46:06 -07:00
|
|
|
location: Location) {
|
2019-02-09 16:29:31 +00:00
|
|
|
match rvalue {
|
|
|
|
Rvalue::Use(operand) => {
|
2016-08-08 18:46:06 -07:00
|
|
|
self.visit_operand(operand, location);
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
2015-12-08 14:09:16 -05:00
|
|
|
|
2019-02-09 16:29:31 +00:00
|
|
|
Rvalue::Repeat(value, _) => {
|
2016-08-08 18:46:06 -07:00
|
|
|
self.visit_operand(value, location);
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
2015-12-08 14:09:16 -05:00
|
|
|
|
2019-02-09 16:29:31 +00:00
|
|
|
Rvalue::Ref(r, bk, path) => {
|
2017-08-04 11:25:13 +03:00
|
|
|
self.visit_region(r, location);
|
2018-10-26 13:22:45 +02:00
|
|
|
let ctx = match bk {
|
|
|
|
BorrowKind::Shared => PlaceContext::NonMutatingUse(
|
2019-04-24 19:41:43 +01:00
|
|
|
NonMutatingUseContext::SharedBorrow
|
2018-10-26 13:22:45 +02:00
|
|
|
),
|
|
|
|
BorrowKind::Shallow => PlaceContext::NonMutatingUse(
|
2019-04-24 19:41:43 +01:00
|
|
|
NonMutatingUseContext::ShallowBorrow
|
2018-10-26 13:22:45 +02:00
|
|
|
),
|
|
|
|
BorrowKind::Unique => PlaceContext::NonMutatingUse(
|
2019-04-24 19:41:43 +01:00
|
|
|
NonMutatingUseContext::UniqueBorrow
|
2018-10-26 13:22:45 +02:00
|
|
|
),
|
|
|
|
BorrowKind::Mut { .. } =>
|
2019-04-24 19:41:43 +01:00
|
|
|
PlaceContext::MutatingUse(MutatingUseContext::Borrow),
|
2018-10-26 13:22:45 +02:00
|
|
|
};
|
|
|
|
self.visit_place(path, ctx, location);
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
2015-12-08 14:09:16 -05:00
|
|
|
|
2019-02-09 16:29:31 +00:00
|
|
|
Rvalue::Len(path) => {
|
2018-10-26 13:22:45 +02:00
|
|
|
self.visit_place(
|
|
|
|
path,
|
|
|
|
PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
|
|
|
|
location
|
|
|
|
);
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
2015-12-08 14:09:16 -05:00
|
|
|
|
2019-02-09 16:29:31 +00:00
|
|
|
Rvalue::Cast(_cast_kind, operand, ty) => {
|
2016-08-08 18:46:06 -07:00
|
|
|
self.visit_operand(operand, location);
|
2017-10-26 19:53:31 -04:00
|
|
|
self.visit_ty(ty, TyContext::Location(location));
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
2015-12-08 14:09:16 -05:00
|
|
|
|
2019-02-09 16:29:31 +00:00
|
|
|
Rvalue::BinaryOp(_bin_op, lhs, rhs)
|
|
|
|
| Rvalue::CheckedBinaryOp(_bin_op, lhs, rhs) => {
|
2016-08-08 18:46:06 -07:00
|
|
|
self.visit_operand(lhs, location);
|
|
|
|
self.visit_operand(rhs, location);
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
2015-12-08 14:09:16 -05:00
|
|
|
|
2019-02-09 16:29:31 +00:00
|
|
|
Rvalue::UnaryOp(_un_op, op) => {
|
2016-08-08 18:46:06 -07:00
|
|
|
self.visit_operand(op, location);
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
2015-12-08 14:09:16 -05:00
|
|
|
|
2019-02-09 16:29:31 +00:00
|
|
|
Rvalue::Discriminant(place) => {
|
2018-10-26 13:22:45 +02:00
|
|
|
self.visit_place(
|
|
|
|
place,
|
|
|
|
PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),
|
|
|
|
location
|
|
|
|
);
|
2017-01-31 01:10:54 +02:00
|
|
|
}
|
|
|
|
|
2019-02-09 16:29:31 +00:00
|
|
|
Rvalue::NullaryOp(_op, ty) => {
|
2017-10-26 19:53:31 -04:00
|
|
|
self.visit_ty(ty, TyContext::Location(location));
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
2015-12-08 14:09:16 -05:00
|
|
|
|
2019-02-09 16:29:31 +00:00
|
|
|
Rvalue::Aggregate(kind, operands) => {
|
|
|
|
let kind = &$($mutability)? **kind;
|
|
|
|
match kind {
|
|
|
|
AggregateKind::Array(ty) => {
|
2017-10-26 19:53:31 -04:00
|
|
|
self.visit_ty(ty, TyContext::Location(location));
|
2016-03-24 06:12:19 -04:00
|
|
|
}
|
|
|
|
AggregateKind::Tuple => {
|
|
|
|
}
|
2019-02-09 16:29:31 +00:00
|
|
|
AggregateKind::Adt(
|
|
|
|
_adt_def,
|
|
|
|
_variant_index,
|
|
|
|
substs,
|
|
|
|
_user_substs,
|
|
|
|
_active_field_index
|
|
|
|
) => {
|
2017-07-18 22:31:38 -04:00
|
|
|
self.visit_substs(substs, location);
|
2016-03-24 06:12:19 -04:00
|
|
|
}
|
2019-02-09 16:29:31 +00:00
|
|
|
AggregateKind::Closure(
|
2019-04-26 21:36:36 +01:00
|
|
|
_,
|
2019-02-09 16:29:31 +00:00
|
|
|
closure_substs
|
|
|
|
) => {
|
2019-09-26 17:30:44 +00:00
|
|
|
self.visit_substs(closure_substs, location);
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
2019-02-09 16:29:31 +00:00
|
|
|
AggregateKind::Generator(
|
2019-04-26 21:36:36 +01:00
|
|
|
_,
|
2019-02-09 16:29:31 +00:00
|
|
|
generator_substs,
|
|
|
|
_movability,
|
|
|
|
) => {
|
2019-10-03 21:30:26 +08:00
|
|
|
self.visit_substs(generator_substs, location);
|
2016-12-26 14:34:03 +01:00
|
|
|
}
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
|
|
|
|
2016-03-24 06:12:19 -04:00
|
|
|
for operand in operands {
|
2016-08-08 18:46:06 -07:00
|
|
|
self.visit_operand(operand, location);
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
|
|
|
}
|
2015-12-08 14:09:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-07 05:49:46 -05:00
|
|
|
fn super_operand(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
operand: & $($mutability)? Operand<'tcx>,
|
2016-08-08 18:46:06 -07:00
|
|
|
location: Location) {
|
2019-02-09 16:29:31 +00:00
|
|
|
match operand {
|
|
|
|
Operand::Copy(place) => {
|
2018-10-26 13:22:45 +02:00
|
|
|
self.visit_place(
|
|
|
|
place,
|
|
|
|
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
|
|
|
|
location
|
|
|
|
);
|
2017-11-17 17:19:57 +02:00
|
|
|
}
|
2019-02-09 16:29:31 +00:00
|
|
|
Operand::Move(place) => {
|
2018-10-26 13:22:45 +02:00
|
|
|
self.visit_place(
|
|
|
|
place,
|
|
|
|
PlaceContext::NonMutatingUse(NonMutatingUseContext::Move),
|
|
|
|
location
|
|
|
|
);
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
2019-02-09 16:29:31 +00:00
|
|
|
Operand::Constant(constant) => {
|
2016-08-08 18:46:06 -07:00
|
|
|
self.visit_constant(constant, location);
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
2015-12-08 14:09:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-31 18:59:35 -04:00
|
|
|
fn super_ascribe_user_ty(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
place: & $($mutability)? Place<'tcx>,
|
|
|
|
_variance: & $($mutability)? ty::Variance,
|
2019-03-28 18:00:17 -07:00
|
|
|
user_ty: & $($mutability)? UserTypeProjection,
|
2018-08-31 18:59:35 -04:00
|
|
|
location: Location) {
|
2018-10-26 13:22:45 +02:00
|
|
|
self.visit_place(
|
|
|
|
place,
|
|
|
|
PlaceContext::NonUse(NonUseContext::AscribeUserTy),
|
|
|
|
location
|
|
|
|
);
|
2018-10-22 11:58:06 +02:00
|
|
|
self.visit_user_type_projection(user_ty);
|
2018-02-23 20:52:05 +00:00
|
|
|
}
|
|
|
|
|
2018-10-24 13:47:48 +02:00
|
|
|
fn super_retag(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
_kind: & $($mutability)? RetagKind,
|
|
|
|
place: & $($mutability)? Place<'tcx>,
|
2018-10-24 13:47:48 +02:00
|
|
|
location: Location) {
|
|
|
|
self.visit_place(
|
|
|
|
place,
|
|
|
|
PlaceContext::MutatingUse(MutatingUseContext::Retag),
|
|
|
|
location,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-05 19:56:11 +02:00
|
|
|
fn super_place_base(&mut self,
|
|
|
|
place_base: & $($mutability)? PlaceBase<'tcx>,
|
2019-04-24 19:41:43 +01:00
|
|
|
context: PlaceContext,
|
2016-08-08 18:46:06 -07:00
|
|
|
location: Location) {
|
2019-06-05 19:56:11 +02:00
|
|
|
match place_base {
|
|
|
|
PlaceBase::Local(local) => {
|
|
|
|
self.visit_local(local, context, location);
|
|
|
|
}
|
2019-08-05 21:11:55 -04:00
|
|
|
PlaceBase::Static(box Static { kind: _, ty, def_id: _ }) => {
|
2019-06-05 19:56:11 +02:00
|
|
|
self.visit_ty(& $($mutability)? *ty, TyContext::Location(location));
|
|
|
|
}
|
|
|
|
}
|
2016-03-24 06:12:19 -04:00
|
|
|
}
|
|
|
|
|
2016-09-25 01:38:27 +02:00
|
|
|
fn super_local_decl(&mut self,
|
2017-10-26 19:53:31 -04:00
|
|
|
local: Local,
|
2019-02-09 16:29:31 +00:00
|
|
|
local_decl: & $($mutability)? LocalDecl<'tcx>) {
|
2016-09-25 01:38:27 +02:00
|
|
|
let LocalDecl {
|
2016-03-24 06:12:19 -04:00
|
|
|
mutability: _,
|
2019-02-09 16:29:31 +00:00
|
|
|
ty,
|
|
|
|
user_ty,
|
|
|
|
source_info,
|
2018-05-29 17:37:24 +03:00
|
|
|
internal: _,
|
2019-11-18 23:04:06 +00:00
|
|
|
local_info: _,
|
2018-09-22 00:51:48 +02:00
|
|
|
is_block_tail: _,
|
2019-02-09 16:29:31 +00:00
|
|
|
} = local_decl;
|
2016-03-24 06:12:19 -04:00
|
|
|
|
2017-10-26 19:53:31 -04:00
|
|
|
self.visit_ty(ty, TyContext::LocalDecl {
|
|
|
|
local,
|
2018-05-29 21:31:33 +03:00
|
|
|
source_info: *source_info,
|
2017-10-26 19:53:31 -04:00
|
|
|
});
|
2019-02-09 16:29:31 +00:00
|
|
|
for (user_ty, _) in & $($mutability)? user_ty.contents {
|
2018-10-22 11:58:06 +02:00
|
|
|
self.visit_user_type_projection(user_ty);
|
2018-09-10 10:54:31 -04:00
|
|
|
}
|
2018-05-29 21:31:33 +03:00
|
|
|
self.visit_source_info(source_info);
|
2018-05-16 18:58:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn super_var_debug_info(&mut self,
|
|
|
|
var_debug_info: & $($mutability)? VarDebugInfo<'tcx>) {
|
|
|
|
let VarDebugInfo {
|
|
|
|
name: _,
|
|
|
|
source_info,
|
|
|
|
place,
|
|
|
|
} = var_debug_info;
|
|
|
|
|
|
|
|
self.visit_source_info(source_info);
|
|
|
|
let location = START_BLOCK.start_location();
|
|
|
|
self.visit_place(
|
|
|
|
place,
|
|
|
|
PlaceContext::NonUse(NonUseContext::VarDebugInfo),
|
|
|
|
location,
|
|
|
|
);
|
2016-03-24 06:12:19 -04:00
|
|
|
}
|
|
|
|
|
2018-05-28 14:16:09 +03:00
|
|
|
fn super_source_scope(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
_scope: & $($mutability)? SourceScope) {
|
2016-03-24 06:12:19 -04:00
|
|
|
}
|
|
|
|
|
2016-01-07 05:49:46 -05:00
|
|
|
fn super_constant(&mut self,
|
2019-02-09 16:29:31 +00:00
|
|
|
constant: & $($mutability)? Constant<'tcx>,
|
2016-08-08 18:46:06 -07:00
|
|
|
location: Location) {
|
2016-03-25 13:10:32 -04:00
|
|
|
let Constant {
|
2019-02-09 16:29:31 +00:00
|
|
|
span,
|
|
|
|
user_ty,
|
|
|
|
literal,
|
|
|
|
} = constant;
|
2016-03-25 13:10:32 -04:00
|
|
|
|
|
|
|
self.visit_span(span);
|
2018-08-09 06:18:00 -04:00
|
|
|
drop(user_ty); // no visit method for this
|
2018-07-22 01:01:07 +02:00
|
|
|
self.visit_const(literal, location);
|
2015-12-08 14:09:16 -05:00
|
|
|
}
|
|
|
|
|
2019-02-09 16:29:31 +00:00
|
|
|
fn super_span(&mut self, _span: & $($mutability)? Span) {
|
2015-12-08 14:09:16 -05:00
|
|
|
}
|
2016-03-24 06:12:19 -04:00
|
|
|
|
2019-02-09 16:29:31 +00:00
|
|
|
fn super_source_info(&mut self, source_info: & $($mutability)? SourceInfo) {
|
2016-06-07 19:21:56 +03:00
|
|
|
let SourceInfo {
|
2019-02-09 16:29:31 +00:00
|
|
|
span,
|
|
|
|
scope,
|
|
|
|
} = source_info;
|
2016-06-07 19:21:56 +03:00
|
|
|
|
|
|
|
self.visit_span(span);
|
2018-05-28 14:16:09 +03:00
|
|
|
self.visit_source_scope(scope);
|
2016-06-07 19:21:56 +03:00
|
|
|
}
|
|
|
|
|
2018-10-22 11:58:06 +02:00
|
|
|
fn super_user_type_projection(
|
|
|
|
&mut self,
|
2019-03-28 18:00:17 -07:00
|
|
|
_ty: & $($mutability)? UserTypeProjection,
|
2018-10-22 11:58:06 +02:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2018-10-15 09:31:38 -04:00
|
|
|
fn super_user_type_annotation(
|
|
|
|
&mut self,
|
2018-11-16 22:56:18 +01:00
|
|
|
_index: UserTypeAnnotationIndex,
|
2019-02-09 16:29:31 +00:00
|
|
|
ty: & $($mutability)? CanonicalUserTypeAnnotation<'tcx>,
|
2018-10-15 09:31:38 -04:00
|
|
|
) {
|
2019-02-09 16:29:31 +00:00
|
|
|
self.visit_span(& $($mutability)? ty.span);
|
|
|
|
self.visit_ty(& $($mutability)? ty.inferred_ty, TyContext::UserTy(ty.span));
|
2018-08-09 06:18:00 -04:00
|
|
|
}
|
|
|
|
|
2019-04-25 22:54:19 +02:00
|
|
|
fn super_ty(&mut self, _ty: $(& $mutability)? Ty<'tcx>) {
|
2016-03-24 06:12:19 -04:00
|
|
|
}
|
|
|
|
|
2019-02-09 16:29:31 +00:00
|
|
|
fn super_region(&mut self, _region: & $($mutability)? ty::Region<'tcx>) {
|
2017-08-04 11:25:13 +03:00
|
|
|
}
|
|
|
|
|
2019-03-14 10:19:31 +01:00
|
|
|
fn super_const(&mut self, _const: & $($mutability)? &'tcx ty::Const<'tcx>) {
|
2017-08-04 11:25:13 +03:00
|
|
|
}
|
|
|
|
|
2019-02-09 22:11:53 +08:00
|
|
|
fn super_substs(&mut self, _substs: & $($mutability)? SubstsRef<'tcx>) {
|
2016-03-24 06:12:19 -04:00
|
|
|
}
|
|
|
|
|
2016-09-15 18:18:40 -07:00
|
|
|
// Convenience methods
|
2019-10-04 00:55:28 -04:00
|
|
|
|
2019-10-09 23:22:58 -04:00
|
|
|
fn visit_location(&mut self, body_cache: & $($mutability)? cache_type!('tcx $($mutability)?), location: Location) {
|
|
|
|
let basic_block = & $($mutability)? body_cache[location.block];
|
2019-10-04 00:55:28 -04:00
|
|
|
if basic_block.statements.len() == location.statement_index {
|
|
|
|
if let Some(ref $($mutability)? terminator) = basic_block.terminator {
|
|
|
|
self.visit_terminator(terminator, location)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let statement = & $($mutability)?
|
|
|
|
basic_block.statements[location.statement_index];
|
|
|
|
self.visit_statement(statement, location)
|
2016-09-15 18:18:40 -07:00
|
|
|
}
|
|
|
|
}
|
2015-12-08 14:09:16 -05:00
|
|
|
}
|
|
|
|
}
|
2016-01-07 05:49:46 -05:00
|
|
|
}
|
2015-12-08 14:09:16 -05:00
|
|
|
|
2019-10-09 23:22:58 -04:00
|
|
|
macro_rules! cache_type {
|
|
|
|
($tcx:lifetime mut) => {MutCache<'_, $tcx>};
|
|
|
|
($tcx:lifetime) => {BorrowedCache<'_, $tcx>};
|
|
|
|
}
|
|
|
|
|
2019-10-08 12:16:26 -03:00
|
|
|
macro_rules! visit_place_fns {
|
|
|
|
(mut) => (
|
2019-10-20 16:11:04 -04:00
|
|
|
fn tcx<'a>(&'a self) -> TyCtxt<'tcx>;
|
|
|
|
|
2019-10-08 12:16:26 -03:00
|
|
|
fn super_place(
|
|
|
|
&mut self,
|
2019-10-08 15:33:19 -03:00
|
|
|
place: &mut Place<'tcx>,
|
|
|
|
context: PlaceContext,
|
|
|
|
location: Location,
|
2019-10-08 12:16:26 -03:00
|
|
|
) {
|
2019-10-08 15:33:19 -03:00
|
|
|
self.visit_place_base(&mut place.base, context, location);
|
|
|
|
|
2019-10-08 23:46:14 -03:00
|
|
|
if let Some(new_projection) = self.process_projection(&place.projection) {
|
2019-10-20 16:11:04 -04:00
|
|
|
place.projection = self.tcx().intern_place_elems(&new_projection);
|
2019-10-08 23:46:14 -03:00
|
|
|
}
|
2019-10-08 15:33:19 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn process_projection(
|
|
|
|
&mut self,
|
2019-10-08 23:46:14 -03:00
|
|
|
projection: &'a [PlaceElem<'tcx>],
|
2019-10-20 16:11:04 -04:00
|
|
|
) -> Option<Vec<PlaceElem<'tcx>>> {
|
2019-10-08 23:46:14 -03:00
|
|
|
let mut projection = Cow::Borrowed(projection);
|
2019-10-08 15:33:19 -03:00
|
|
|
|
2019-10-08 23:46:14 -03:00
|
|
|
for i in 0..projection.len() {
|
|
|
|
if let Some(elem) = projection.get(i) {
|
|
|
|
if let Some(elem) = self.process_projection_elem(elem) {
|
2019-10-20 16:11:04 -04:00
|
|
|
// This converts the borrowed projection into `Cow::Owned(_)` and returns a
|
|
|
|
// clone of the projection so we can mutate and reintern later.
|
2019-10-08 23:46:14 -03:00
|
|
|
let vec = projection.to_mut();
|
|
|
|
vec[i] = elem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
match projection {
|
|
|
|
Cow::Borrowed(_) => None,
|
2019-10-20 16:11:04 -04:00
|
|
|
Cow::Owned(vec) => Some(vec),
|
2019-10-08 23:46:14 -03:00
|
|
|
}
|
2019-10-08 15:33:19 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn process_projection_elem(
|
|
|
|
&mut self,
|
2019-10-08 23:46:14 -03:00
|
|
|
_elem: &PlaceElem<'tcx>,
|
|
|
|
) -> Option<PlaceElem<'tcx>> {
|
|
|
|
None
|
2019-10-08 12:16:26 -03:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
() => (
|
|
|
|
fn visit_projection(
|
|
|
|
&mut self,
|
|
|
|
base: &PlaceBase<'tcx>,
|
|
|
|
projection: &[PlaceElem<'tcx>],
|
|
|
|
context: PlaceContext,
|
|
|
|
location: Location,
|
|
|
|
) {
|
|
|
|
self.super_projection(base, projection, context, location);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_projection_elem(
|
|
|
|
&mut self,
|
|
|
|
base: &PlaceBase<'tcx>,
|
|
|
|
proj_base: &[PlaceElem<'tcx>],
|
|
|
|
elem: &PlaceElem<'tcx>,
|
|
|
|
context: PlaceContext,
|
|
|
|
location: Location,
|
|
|
|
) {
|
|
|
|
self.super_projection_elem(base, proj_base, elem, context, location);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_place(
|
|
|
|
&mut self,
|
|
|
|
place: &Place<'tcx>,
|
|
|
|
context: PlaceContext,
|
|
|
|
location: Location,
|
|
|
|
) {
|
|
|
|
let mut context = context;
|
|
|
|
|
|
|
|
if !place.projection.is_empty() {
|
|
|
|
context = if context.is_mutating_use() {
|
|
|
|
PlaceContext::MutatingUse(MutatingUseContext::Projection)
|
|
|
|
} else {
|
|
|
|
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
self.visit_place_base(&place.base, context, location);
|
|
|
|
|
|
|
|
self.visit_projection(&place.base,
|
|
|
|
&place.projection,
|
|
|
|
context,
|
|
|
|
location);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_projection(
|
|
|
|
&mut self,
|
|
|
|
base: &PlaceBase<'tcx>,
|
|
|
|
projection: &[PlaceElem<'tcx>],
|
|
|
|
context: PlaceContext,
|
|
|
|
location: Location,
|
|
|
|
) {
|
|
|
|
let mut cursor = projection;
|
|
|
|
while let [proj_base @ .., elem] = cursor {
|
|
|
|
cursor = proj_base;
|
|
|
|
self.visit_projection_elem(base, cursor, elem, context, location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_projection_elem(
|
|
|
|
&mut self,
|
|
|
|
_base: &PlaceBase<'tcx>,
|
|
|
|
_proj_base: &[PlaceElem<'tcx>],
|
|
|
|
elem: &PlaceElem<'tcx>,
|
|
|
|
_context: PlaceContext,
|
|
|
|
location: Location,
|
|
|
|
) {
|
|
|
|
match elem {
|
|
|
|
ProjectionElem::Field(_field, ty) => {
|
|
|
|
self.visit_ty(ty, TyContext::Location(location));
|
|
|
|
}
|
|
|
|
ProjectionElem::Index(local) => {
|
|
|
|
self.visit_local(
|
|
|
|
local,
|
|
|
|
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
|
|
|
|
location
|
|
|
|
);
|
|
|
|
}
|
|
|
|
ProjectionElem::Deref |
|
|
|
|
ProjectionElem::Subslice { from: _, to: _ } |
|
|
|
|
ProjectionElem::ConstantIndex { offset: _,
|
|
|
|
min_length: _,
|
|
|
|
from_end: _ } |
|
|
|
|
ProjectionElem::Downcast(_, _) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-01-07 05:49:46 -05:00
|
|
|
make_mir_visitor!(Visitor,);
|
|
|
|
make_mir_visitor!(MutVisitor,mut);
|
2015-12-08 14:09:16 -05:00
|
|
|
|
2017-12-12 11:59:09 -03:00
|
|
|
pub trait MirVisitable<'tcx> {
|
|
|
|
fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>);
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> MirVisitable<'tcx> for Statement<'tcx> {
|
|
|
|
fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>)
|
|
|
|
{
|
2019-04-22 21:07:14 +01:00
|
|
|
visitor.visit_statement(self, location)
|
2017-12-12 11:59:09 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> MirVisitable<'tcx> for Terminator<'tcx> {
|
|
|
|
fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>)
|
|
|
|
{
|
2019-04-22 21:07:14 +01:00
|
|
|
visitor.visit_terminator(self, location)
|
2017-12-12 11:59:09 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> MirVisitable<'tcx> for Option<Terminator<'tcx>> {
|
|
|
|
fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>)
|
|
|
|
{
|
2019-04-22 21:07:14 +01:00
|
|
|
visitor.visit_terminator(self.as_ref().unwrap(), location)
|
2017-12-12 11:59:09 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-26 19:53:31 -04:00
|
|
|
/// Extra information passed to `visit_ty` and friends to give context
|
|
|
|
/// about where the type etc appears.
|
2019-10-20 15:54:53 +11:00
|
|
|
#[derive(Debug)]
|
2017-10-26 19:53:31 -04:00
|
|
|
pub enum TyContext {
|
|
|
|
LocalDecl {
|
|
|
|
/// The index of the local variable we are visiting.
|
|
|
|
local: Local,
|
|
|
|
|
|
|
|
/// The source location where this local variable was declared.
|
|
|
|
source_info: SourceInfo,
|
|
|
|
},
|
|
|
|
|
2019-01-12 14:55:23 +00:00
|
|
|
/// The inferred type of a user type annotation.
|
|
|
|
UserTy(Span),
|
|
|
|
|
2017-11-07 04:30:06 -05:00
|
|
|
/// The return type of the function.
|
|
|
|
ReturnTy(SourceInfo),
|
2017-10-26 19:53:31 -04:00
|
|
|
|
2018-01-19 19:18:02 -03:00
|
|
|
YieldTy(SourceInfo),
|
|
|
|
|
2017-11-07 04:30:06 -05:00
|
|
|
/// A type found at some location.
|
|
|
|
Location(Location),
|
2017-07-18 22:31:38 -04:00
|
|
|
}
|
|
|
|
|
2016-08-16 04:59:50 +03:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
2019-04-24 19:41:43 +01:00
|
|
|
pub enum NonMutatingUseContext {
|
2018-10-26 13:22:45 +02:00
|
|
|
/// Being inspected in some way, like loading a len.
|
|
|
|
Inspect,
|
|
|
|
/// Consumed as part of an operand.
|
|
|
|
Copy,
|
|
|
|
/// Consumed as part of an operand.
|
|
|
|
Move,
|
|
|
|
/// Shared borrow.
|
2019-04-24 19:41:43 +01:00
|
|
|
SharedBorrow,
|
2018-10-26 13:22:45 +02:00
|
|
|
/// Shallow borrow.
|
2019-04-24 19:41:43 +01:00
|
|
|
ShallowBorrow,
|
2018-10-26 13:22:45 +02:00
|
|
|
/// Unique borrow.
|
2019-04-24 19:41:43 +01:00
|
|
|
UniqueBorrow,
|
2018-11-27 02:59:49 +00:00
|
|
|
/// Used as base for another place, e.g., `x` in `x.y`. Will not mutate the place.
|
2018-10-26 13:22:45 +02:00
|
|
|
/// For example, the projection `x.y` is not marked as a mutation in these cases:
|
|
|
|
///
|
|
|
|
/// z = x.y;
|
|
|
|
/// f(&x.y);
|
|
|
|
///
|
|
|
|
Projection,
|
|
|
|
}
|
2015-12-08 14:09:16 -05:00
|
|
|
|
2018-10-26 13:22:45 +02:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
2019-04-24 19:41:43 +01:00
|
|
|
pub enum MutatingUseContext {
|
2018-10-26 13:22:45 +02:00
|
|
|
/// Appears as LHS of an assignment.
|
|
|
|
Store,
|
|
|
|
/// Can often be treated as a `Store`, but needs to be separate because
|
|
|
|
/// ASM is allowed to read outputs as well, so a `Store`-`AsmOutput` sequence
|
|
|
|
/// cannot be simplified the way a `Store`-`Store` can be.
|
2017-12-19 17:05:14 -05:00
|
|
|
AsmOutput,
|
2018-10-26 13:22:45 +02:00
|
|
|
/// Destination of a call.
|
2016-04-04 19:21:27 +12:00
|
|
|
Call,
|
2018-10-26 13:22:45 +02:00
|
|
|
/// Being dropped.
|
2016-01-07 05:49:46 -05:00
|
|
|
Drop,
|
2018-10-26 13:22:45 +02:00
|
|
|
/// Mutable borrow.
|
2019-04-24 19:41:43 +01:00
|
|
|
Borrow,
|
2018-11-27 02:59:49 +00:00
|
|
|
/// Used as base for another place, e.g., `x` in `x.y`. Could potentially mutate the place.
|
2018-10-26 13:22:45 +02:00
|
|
|
/// For example, the projection `x.y` is marked as a mutation in these cases:
|
|
|
|
///
|
|
|
|
/// x.y = ...;
|
|
|
|
/// f(&mut x.y);
|
|
|
|
///
|
|
|
|
Projection,
|
2018-11-06 11:04:10 +01:00
|
|
|
/// Retagging, a "Stacked Borrows" shadow state operation
|
2018-10-24 11:47:17 +02:00
|
|
|
Retag,
|
2018-10-26 13:22:45 +02:00
|
|
|
}
|
2015-12-08 14:09:16 -05:00
|
|
|
|
2018-10-26 13:22:45 +02:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
|
|
|
pub enum NonUseContext {
|
|
|
|
/// Starting a storage live range.
|
2016-08-14 06:34:14 +03:00
|
|
|
StorageLive,
|
2018-10-26 13:22:45 +02:00
|
|
|
/// Ending a storage live range.
|
2016-08-14 06:34:14 +03:00
|
|
|
StorageDead,
|
2018-10-26 13:22:45 +02:00
|
|
|
/// User type annotation assertions for NLL.
|
|
|
|
AscribeUserTy,
|
2018-05-16 18:58:54 +03:00
|
|
|
/// The data of an user variable, for debug info.
|
|
|
|
VarDebugInfo,
|
2015-12-08 14:09:16 -05:00
|
|
|
}
|
2016-09-15 18:18:40 -07:00
|
|
|
|
2018-10-26 13:22:45 +02:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
2019-04-24 19:41:43 +01:00
|
|
|
pub enum PlaceContext {
|
|
|
|
NonMutatingUse(NonMutatingUseContext),
|
|
|
|
MutatingUse(MutatingUseContext),
|
2018-10-26 13:22:45 +02:00
|
|
|
NonUse(NonUseContext),
|
|
|
|
}
|
|
|
|
|
2019-06-11 12:21:38 +03:00
|
|
|
impl PlaceContext {
|
2018-10-26 13:22:45 +02:00
|
|
|
/// Returns `true` if this place context represents a drop.
|
2016-09-15 18:18:40 -07:00
|
|
|
pub fn is_drop(&self) -> bool {
|
|
|
|
match *self {
|
2018-10-26 13:22:45 +02:00
|
|
|
PlaceContext::MutatingUse(MutatingUseContext::Drop) => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns `true` if this place context represents a borrow.
|
|
|
|
pub fn is_borrow(&self) -> bool {
|
|
|
|
match *self {
|
2019-04-24 19:41:43 +01:00
|
|
|
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow) |
|
|
|
|
PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow) |
|
|
|
|
PlaceContext::NonMutatingUse(NonMutatingUseContext::UniqueBorrow) |
|
|
|
|
PlaceContext::MutatingUse(MutatingUseContext::Borrow) => true,
|
2016-09-15 18:18:40 -07:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-26 13:22:45 +02:00
|
|
|
/// Returns `true` if this place context represents a storage live or storage dead marker.
|
2016-09-15 18:18:40 -07:00
|
|
|
pub fn is_storage_marker(&self) -> bool {
|
|
|
|
match *self {
|
2018-10-26 13:22:45 +02:00
|
|
|
PlaceContext::NonUse(NonUseContext::StorageLive) |
|
|
|
|
PlaceContext::NonUse(NonUseContext::StorageDead) => true,
|
2016-09-15 18:18:40 -07:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-26 13:22:45 +02:00
|
|
|
/// Returns `true` if this place context represents a storage live marker.
|
2016-09-15 18:18:40 -07:00
|
|
|
pub fn is_storage_live_marker(&self) -> bool {
|
|
|
|
match *self {
|
2018-10-26 13:22:45 +02:00
|
|
|
PlaceContext::NonUse(NonUseContext::StorageLive) => true,
|
2016-09-15 18:18:40 -07:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-26 13:22:45 +02:00
|
|
|
/// Returns `true` if this place context represents a storage dead marker.
|
2016-09-15 18:18:40 -07:00
|
|
|
pub fn is_storage_dead_marker(&self) -> bool {
|
|
|
|
match *self {
|
2018-10-26 13:22:45 +02:00
|
|
|
PlaceContext::NonUse(NonUseContext::StorageDead) => true,
|
2016-09-15 18:18:40 -07:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-26 13:22:45 +02:00
|
|
|
/// Returns `true` if this place context represents a use that potentially changes the value.
|
2016-09-15 18:18:40 -07:00
|
|
|
pub fn is_mutating_use(&self) -> bool {
|
|
|
|
match *self {
|
2018-10-26 13:22:45 +02:00
|
|
|
PlaceContext::MutatingUse(..) => true,
|
|
|
|
_ => false,
|
2016-09-15 18:18:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-26 13:22:45 +02:00
|
|
|
/// Returns `true` if this place context represents a use that does not change the value.
|
2016-09-15 18:18:40 -07:00
|
|
|
pub fn is_nonmutating_use(&self) -> bool {
|
|
|
|
match *self {
|
2018-10-26 13:22:45 +02:00
|
|
|
PlaceContext::NonMutatingUse(..) => true,
|
|
|
|
_ => false,
|
2016-09-15 18:18:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-26 13:22:45 +02:00
|
|
|
/// Returns `true` if this place context represents a use.
|
2016-09-15 18:18:40 -07:00
|
|
|
pub fn is_use(&self) -> bool {
|
2018-10-26 13:22:45 +02:00
|
|
|
match *self {
|
|
|
|
PlaceContext::NonUse(..) => false,
|
|
|
|
_ => true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns `true` if this place context represents an assignment statement.
|
|
|
|
pub fn is_place_assignment(&self) -> bool {
|
|
|
|
match *self {
|
|
|
|
PlaceContext::MutatingUse(MutatingUseContext::Store) |
|
|
|
|
PlaceContext::MutatingUse(MutatingUseContext::Call) |
|
|
|
|
PlaceContext::MutatingUse(MutatingUseContext::AsmOutput) => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
2016-09-15 18:18:40 -07:00
|
|
|
}
|
|
|
|
}
|