@@ -209,7 +209,7 @@ macro_rules! make_mir_visitor {
209209
210210 fn visit_ty( & mut self ,
211211 ty: & $( $mutability) * Ty <' tcx>,
212- _: Lookup ) {
212+ _: TyContext ) {
213213 self . super_ty( ty) ;
214214 }
215215
@@ -256,8 +256,9 @@ macro_rules! make_mir_visitor {
256256 }
257257
258258 fn visit_local_decl( & mut self ,
259+ local: Local ,
259260 local_decl: & $( $mutability) * LocalDecl <' tcx>) {
260- self . super_local_decl( local_decl) ;
261+ self . super_local_decl( local , local_decl) ;
261262 }
262263
263264 fn visit_local( & mut self ,
@@ -291,14 +292,14 @@ macro_rules! make_mir_visitor {
291292 self . visit_visibility_scope_data( scope) ;
292293 }
293294
294- let lookup = Lookup :: Src ( SourceInfo {
295+ let lookup = TyContext :: SourceInfo ( SourceInfo {
295296 span: mir. span,
296297 scope: ARGUMENT_VISIBILITY_SCOPE ,
297298 } ) ;
298299 self . visit_ty( & $( $mutability) * mir. return_ty, lookup) ;
299300
300- for local_decl in & $ ( $mutability ) * mir. local_decls {
301- self . visit_local_decl( local_decl ) ;
301+ for local in mir. local_decls. indices ( ) {
302+ self . visit_local_decl( local , & $ ( $mutability ) * mir . local_decls [ local ] ) ;
302303 }
303304
304305 self . visit_span( & $( $mutability) * mir. span) ;
@@ -359,7 +360,8 @@ macro_rules! make_mir_visitor {
359360 for operand in lvalues {
360361 self . visit_lvalue( & $( $mutability) * operand. lval,
361362 LvalueContext :: Validate , location) ;
362- self . visit_ty( & $( $mutability) * operand. ty, Lookup :: Loc ( location) ) ;
363+ self . visit_ty( & $( $mutability) * operand. ty,
364+ TyContext :: Location ( location) ) ;
363365 }
364366 }
365367 StatementKind :: SetDiscriminant { ref $( $mutability) * lvalue, .. } => {
@@ -421,7 +423,7 @@ macro_rules! make_mir_visitor {
421423 ref values,
422424 ref targets } => {
423425 self . visit_operand( discr, source_location) ;
424- self . visit_ty( switch_ty, Lookup :: Loc ( source_location) ) ;
426+ self . visit_ty( switch_ty, TyContext :: Location ( source_location) ) ;
425427 for value in & values[ ..] {
426428 self . visit_const_int( value, source_location) ;
427429 }
@@ -545,7 +547,7 @@ macro_rules! make_mir_visitor {
545547 ref $( $mutability) * operand,
546548 ref $( $mutability) * ty) => {
547549 self . visit_operand( operand, location) ;
548- self . visit_ty( ty, Lookup :: Loc ( location) ) ;
550+ self . visit_ty( ty, TyContext :: Location ( location) ) ;
549551 }
550552
551553 Rvalue :: BinaryOp ( _bin_op,
@@ -567,15 +569,15 @@ macro_rules! make_mir_visitor {
567569 }
568570
569571 Rvalue :: NullaryOp ( _op, ref $( $mutability) * ty) => {
570- self . visit_ty( ty, Lookup :: Loc ( location) ) ;
572+ self . visit_ty( ty, TyContext :: Location ( location) ) ;
571573 }
572574
573575 Rvalue :: Aggregate ( ref $( $mutability) * kind,
574576 ref $( $mutability) * operands) => {
575577 let kind = & $( $mutability) * * * kind;
576578 match * kind {
577579 AggregateKind :: Array ( ref $( $mutability) * ty) => {
578- self . visit_ty( ty, Lookup :: Loc ( location) ) ;
580+ self . visit_ty( ty, TyContext :: Location ( location) ) ;
579581 }
580582 AggregateKind :: Tuple => {
581583 }
@@ -645,7 +647,7 @@ macro_rules! make_mir_visitor {
645647 ref $( $mutability) * ty,
646648 } = * static_;
647649 self . visit_def_id( def_id, location) ;
648- self . visit_ty( ty, Lookup :: Loc ( location) ) ;
650+ self . visit_ty( ty, TyContext :: Location ( location) ) ;
649651 }
650652
651653 fn super_projection( & mut self ,
@@ -675,7 +677,7 @@ macro_rules! make_mir_visitor {
675677 ProjectionElem :: Subslice { from: _, to: _ } => {
676678 }
677679 ProjectionElem :: Field ( _field, ref $( $mutability) * ty) => {
678- self . visit_ty( ty, Lookup :: Loc ( location) ) ;
680+ self . visit_ty( ty, TyContext :: Location ( location) ) ;
679681 }
680682 ProjectionElem :: Index ( ref $( $mutability) * local) => {
681683 self . visit_local( local, LvalueContext :: Consume , location) ;
@@ -690,6 +692,7 @@ macro_rules! make_mir_visitor {
690692 }
691693
692694 fn super_local_decl( & mut self ,
695+ local: Local ,
693696 local_decl: & $( $mutability) * LocalDecl <' tcx>) {
694697 let LocalDecl {
695698 mutability: _,
@@ -701,7 +704,10 @@ macro_rules! make_mir_visitor {
701704 is_user_variable: _,
702705 } = * local_decl;
703706
704- self . visit_ty( ty, Lookup :: Src ( * source_info) ) ;
707+ self . visit_ty( ty, TyContext :: LocalDecl {
708+ local,
709+ source_info: * source_info,
710+ } ) ;
705711 self . visit_source_info( source_info) ;
706712 self . visit_visibility_scope( lexical_scope) ;
707713 }
@@ -725,7 +731,7 @@ macro_rules! make_mir_visitor {
725731 } = * constant;
726732
727733 self . visit_span( span) ;
728- self . visit_ty( ty, Lookup :: Loc ( location) ) ;
734+ self . visit_ty( ty, TyContext :: Location ( location) ) ;
729735 self . visit_literal( literal, location) ;
730736 }
731737
@@ -803,10 +809,21 @@ macro_rules! make_mir_visitor {
803809make_mir_visitor ! ( Visitor , ) ;
804810make_mir_visitor ! ( MutVisitor , mut ) ;
805811
812+ /// Extra information passed to `visit_ty` and friends to give context
813+ /// about where the type etc appears.
806814#[ derive( Copy , Clone , Debug ) ]
807- pub enum Lookup {
808- Loc ( Location ) ,
809- Src ( SourceInfo ) ,
815+ pub enum TyContext {
816+ LocalDecl {
817+ /// The index of the local variable we are visiting.
818+ local : Local ,
819+
820+ /// The source location where this local variable was declared.
821+ source_info : SourceInfo ,
822+ } ,
823+
824+ Location ( Location ) ,
825+
826+ SourceInfo ( SourceInfo ) ,
810827}
811828
812829#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
0 commit comments