@@ -11,8 +11,9 @@ use rustc_middle::mir::interpret::Scalar;
1111use rustc_middle:: mir:: traversal;
1212use rustc_middle:: mir:: visit:: { PlaceContext , Visitor } ;
1313use rustc_middle:: mir:: {
14- AggregateKind , BasicBlock , Body , BorrowKind , Local , Location , MirPhase , Operand , PlaceRef ,
15- Rvalue , SourceScope , Statement , StatementKind , Terminator , TerminatorKind ,
14+ AggregateKind , BasicBlock , Body , BorrowKind , Local , Location , MirPhase , Operand , PlaceElem ,
15+ PlaceRef , ProjectionElem , Rvalue , SourceScope , Statement , StatementKind , Terminator ,
16+ TerminatorKind ,
1617} ;
1718use rustc_middle:: ty:: fold:: BottomUpFolder ;
1819use rustc_middle:: ty:: { self , ParamEnv , Ty , TyCtxt , TypeFoldable } ;
@@ -217,6 +218,23 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
217218 self . super_operand ( operand, location) ;
218219 }
219220
221+ fn visit_projection_elem (
222+ & mut self ,
223+ local : Local ,
224+ proj_base : & [ PlaceElem < ' tcx > ] ,
225+ elem : PlaceElem < ' tcx > ,
226+ context : PlaceContext ,
227+ location : Location ,
228+ ) {
229+ if let ProjectionElem :: Index ( index) = elem {
230+ let index_ty = self . body . local_decls [ index] . ty ;
231+ if index_ty != self . tcx . types . usize {
232+ self . fail ( location, format ! ( "bad index ({:?} != usize)" , index_ty) )
233+ }
234+ }
235+ self . super_projection_elem ( local, proj_base, elem, context, location) ;
236+ }
237+
220238 fn visit_statement ( & mut self , statement : & Statement < ' tcx > , location : Location ) {
221239 match & statement. kind {
222240 StatementKind :: Assign ( box ( dest, rvalue) ) => {
0 commit comments