fn visit_ty(&mut self,
ty: & $($mutability)* Ty<'tcx>,
- _: Lookup) {
+ _: TyContext) {
self.super_ty(ty);
}
}
fn visit_local_decl(&mut self,
+ local: Local,
local_decl: & $($mutability)* LocalDecl<'tcx>) {
- self.super_local_decl(local_decl);
+ self.super_local_decl(local, local_decl);
}
fn visit_local(&mut self,
self.visit_visibility_scope_data(scope);
}
- let lookup = Lookup::Src(SourceInfo {
+ let lookup = TyContext::SourceInfo(SourceInfo {
span: mir.span,
scope: ARGUMENT_VISIBILITY_SCOPE,
});
self.visit_ty(&$($mutability)* mir.return_ty, lookup);
- for local_decl in &$($mutability)* mir.local_decls {
- self.visit_local_decl(local_decl);
+ for local in mir.local_decls.indices() {
+ self.visit_local_decl(local, & $($mutability)* mir.local_decls[local]);
}
self.visit_span(&$($mutability)* mir.span);
for operand in lvalues {
self.visit_lvalue(& $($mutability)* operand.lval,
LvalueContext::Validate, location);
- self.visit_ty(& $($mutability)* operand.ty, Lookup::Loc(location));
+ self.visit_ty(& $($mutability)* operand.ty,
+ TyContext::Location(location));
}
}
StatementKind::SetDiscriminant{ ref $($mutability)* lvalue, .. } => {
ref values,
ref targets } => {
self.visit_operand(discr, source_location);
- self.visit_ty(switch_ty, Lookup::Loc(source_location));
+ self.visit_ty(switch_ty, TyContext::Location(source_location));
for value in &values[..] {
self.visit_const_int(value, source_location);
}
ref $($mutability)* operand,
ref $($mutability)* ty) => {
self.visit_operand(operand, location);
- self.visit_ty(ty, Lookup::Loc(location));
+ self.visit_ty(ty, TyContext::Location(location));
}
Rvalue::BinaryOp(_bin_op,
}
Rvalue::NullaryOp(_op, ref $($mutability)* ty) => {
- self.visit_ty(ty, Lookup::Loc(location));
+ self.visit_ty(ty, TyContext::Location(location));
}
Rvalue::Aggregate(ref $($mutability)* kind,
let kind = &$($mutability)* **kind;
match *kind {
AggregateKind::Array(ref $($mutability)* ty) => {
- self.visit_ty(ty, Lookup::Loc(location));
+ self.visit_ty(ty, TyContext::Location(location));
}
AggregateKind::Tuple => {
}
ref $($mutability)* ty,
} = *static_;
self.visit_def_id(def_id, location);
- self.visit_ty(ty, Lookup::Loc(location));
+ self.visit_ty(ty, TyContext::Location(location));
}
fn super_projection(&mut self,
ProjectionElem::Subslice { from: _, to: _ } => {
}
ProjectionElem::Field(_field, ref $($mutability)* ty) => {
- self.visit_ty(ty, Lookup::Loc(location));
+ self.visit_ty(ty, TyContext::Location(location));
}
ProjectionElem::Index(ref $($mutability)* local) => {
self.visit_local(local, LvalueContext::Consume, location);
}
fn super_local_decl(&mut self,
+ local: Local,
local_decl: & $($mutability)* LocalDecl<'tcx>) {
let LocalDecl {
mutability: _,
is_user_variable: _,
} = *local_decl;
- self.visit_ty(ty, Lookup::Src(*source_info));
+ self.visit_ty(ty, TyContext::LocalDecl {
+ local,
+ source_info: *source_info,
+ });
self.visit_source_info(source_info);
self.visit_visibility_scope(lexical_scope);
}
} = *constant;
self.visit_span(span);
- self.visit_ty(ty, Lookup::Loc(location));
+ self.visit_ty(ty, TyContext::Location(location));
self.visit_literal(literal, location);
}
make_mir_visitor!(Visitor,);
make_mir_visitor!(MutVisitor,mut);
+/// Extra information passed to `visit_ty` and friends to give context
+/// about where the type etc appears.
#[derive(Copy, Clone, Debug)]
-pub enum Lookup {
- Loc(Location),
- Src(SourceInfo),
+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,
+ },
+
+ Location(Location),
+
+ SourceInfo(SourceInfo),
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]