@@ -11,8 +11,9 @@ use rustc_middle::mir::interpret::Scalar;
11
11
use rustc_middle:: mir:: traversal;
12
12
use rustc_middle:: mir:: visit:: { PlaceContext , Visitor } ;
13
13
use 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 ,
16
17
} ;
17
18
use rustc_middle:: ty:: fold:: BottomUpFolder ;
18
19
use rustc_middle:: ty:: { self , ParamEnv , Ty , TyCtxt , TypeFoldable } ;
@@ -217,6 +218,23 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
217
218
self . super_operand ( operand, location) ;
218
219
}
219
220
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
+
220
238
fn visit_statement ( & mut self , statement : & Statement < ' tcx > , location : Location ) {
221
239
match & statement. kind {
222
240
StatementKind :: Assign ( box ( dest, rvalue) ) => {
0 commit comments