@@ -48,8 +48,11 @@ enum FieldAccessError {
48
48
OutOfRange { field_count : usize }
49
49
}
50
50
51
- /// Verifies that MIR types are sane to not crash further
52
- /// checks.
51
+ /// Verifies that MIR types are sane to not crash further checks.
52
+ ///
53
+ /// The sanitize_XYZ methods here take an MIR object and compute its
54
+ /// type, calling `span_mirbug` and returning an error type if there
55
+ /// is a problem.
53
56
struct TypeVerifier < ' a , ' b : ' a , ' tcx : ' b > {
54
57
cx : & ' a mut TypeChecker < ' b , ' tcx > ,
55
58
mir : & ' a Mir < ' tcx > ,
@@ -119,11 +122,11 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
119
122
}
120
123
121
124
fn sanitize_type ( & mut self , parent : & fmt:: Debug , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
122
- if !( ty. needs_infer ( ) || ty. has_escaping_regions ( ) ||
123
- ty. references_error ( ) ) {
124
- return ty;
125
+ if ty. needs_infer ( ) || ty. has_escaping_regions ( ) || ty. references_error ( ) {
126
+ span_mirbug_and_err ! ( self , parent, "bad type {:?}" , ty)
127
+ } else {
128
+ ty
125
129
}
126
- span_mirbug_and_err ! ( self , parent, "bad type {:?}" , ty)
127
130
}
128
131
129
132
fn sanitize_lvalue ( & mut self , lvalue : & Lvalue < ' tcx > ) -> LvalueTy < ' tcx > {
@@ -225,7 +228,8 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
225
228
}
226
229
_ => LvalueTy :: Ty {
227
230
ty : span_mirbug_and_err ! (
228
- self , lvalue, "can't downcast {:?}" , base_ty)
231
+ self , lvalue, "can't downcast {:?} as {:?}" ,
232
+ base_ty, adt_def1)
229
233
}
230
234
} ,
231
235
ProjectionElem :: Field ( field, fty) => {
@@ -467,8 +471,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
467
471
args : & [ Operand < ' tcx > ] )
468
472
{
469
473
debug ! ( "check_call_inputs({:?}, {:?})" , sig, args) ;
470
- if sig . inputs . len ( ) > args . len ( ) ||
471
- ( sig . inputs . len ( ) < args . len ( ) && !sig. variadic ) {
474
+ if args . len ( ) < sig . inputs . len ( ) ||
475
+ ( args . len ( ) > sig . inputs . len ( ) && !sig. variadic ) {
472
476
span_mirbug ! ( self , term, "call to {:?} with wrong # of args" , sig) ;
473
477
}
474
478
for ( n, ( fn_arg, op_arg) ) in sig. inputs . iter ( ) . zip ( args) . enumerate ( ) {
0 commit comments