@@ -697,7 +697,7 @@ fn is_layout_incompatible<'tcx>(cx: &LateContext<'tcx>, from: Ty<'tcx>, to: Ty<'
697697/// Check if the the type conversion can be expressed as a pointer cast, instead of
698698/// a transmute. In certain cases, including some invalid casts from array
699699/// references to pointers, this may cause additional errors to be emitted and/or
700- /// ICE error messages.
700+ /// ICE error messages. This function will panic if that occurs.
701701fn can_be_expressed_as_pointer_cast < ' tcx > ( cx : & LateContext < ' tcx > , e : & ' tcx Expr < ' _ > , from_ty : Ty < ' tcx > , to_ty : Ty < ' tcx > ) -> bool {
702702 use CastKind :: * ;
703703 matches ! (
@@ -716,7 +716,7 @@ fn can_be_expressed_as_pointer_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<
716716/// If a cast from from_ty to to_ty is valid, returns an Ok containing the kind of
717717/// the cast. In certain cases, including some invalid casts from array references
718718/// to pointers, this may cause additional errors to be emitted and/or ICE error
719- /// messages.
719+ /// messages. This function will panic if that occurs.
720720fn check_cast < ' tcx > ( cx : & LateContext < ' tcx > , e : & ' tcx Expr < ' _ > , from_ty : Ty < ' tcx > , to_ty : Ty < ' tcx > ) -> Option < CastKind > {
721721 let hir_id = e. hir_id ;
722722 let local_def_id = hir_id. owner ;
@@ -743,11 +743,17 @@ fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>
743743 DUMMY_SP ,
744744 DUMMY_SP ,
745745 ) {
746- check. do_check ( & fn_ctxt)
747- . ok ( )
748- // do_check's documentation says that it might return Ok and create
749- // errors in the fcx instead of returing Err in some cases.
750- . filter ( |_| !fn_ctxt. errors_reported_since_creation ( ) )
746+ let res = check. do_check ( & fn_ctxt) ;
747+
748+ // do_check's documentation says that it might return Ok and create
749+ // errors in the fcx instead of returing Err in some cases. Those cases
750+ // should be filtered out before getting here.
751+ assert ! (
752+ !fn_ctxt. errors_reported_since_creation( ) ,
753+ "`fn_ctxt` contained errors after cast check!"
754+ ) ;
755+
756+ res. ok ( )
751757 } else {
752758 None
753759 }
0 commit comments