@@ -48,8 +48,11 @@ enum FieldAccessError {
4848 OutOfRange { field_count : usize }
4949}
5050
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.
5356struct TypeVerifier < ' a , ' b : ' a , ' tcx : ' b > {
5457 cx : & ' a mut TypeChecker < ' b , ' tcx > ,
5558 mir : & ' a Mir < ' tcx > ,
@@ -119,11 +122,11 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
119122 }
120123
121124 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
125129 }
126- span_mirbug_and_err ! ( self , parent, "bad type {:?}" , ty)
127130 }
128131
129132 fn sanitize_lvalue ( & mut self , lvalue : & Lvalue < ' tcx > ) -> LvalueTy < ' tcx > {
@@ -225,7 +228,8 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
225228 }
226229 _ => LvalueTy :: Ty {
227230 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)
229233 }
230234 } ,
231235 ProjectionElem :: Field ( field, fty) => {
@@ -467,8 +471,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
467471 args : & [ Operand < ' tcx > ] )
468472 {
469473 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 ) {
472476 span_mirbug ! ( self , term, "call to {:?} with wrong # of args" , sig) ;
473477 }
474478 for ( n, ( fn_arg, op_arg) ) in sig. inputs . iter ( ) . zip ( args) . enumerate ( ) {
0 commit comments