@@ -697,7 +697,7 @@ fn is_layout_incompatible<'tcx>(cx: &LateContext<'tcx>, from: Ty<'tcx>, to: Ty<'
697
697
/// Check if the the type conversion can be expressed as a pointer cast, instead of
698
698
/// a transmute. In certain cases, including some invalid casts from array
699
699
/// 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.
701
701
fn can_be_expressed_as_pointer_cast < ' tcx > ( cx : & LateContext < ' tcx > , e : & ' tcx Expr < ' _ > , from_ty : Ty < ' tcx > , to_ty : Ty < ' tcx > ) -> bool {
702
702
use CastKind :: * ;
703
703
matches ! (
@@ -716,7 +716,7 @@ fn can_be_expressed_as_pointer_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<
716
716
/// If a cast from from_ty to to_ty is valid, returns an Ok containing the kind of
717
717
/// the cast. In certain cases, including some invalid casts from array references
718
718
/// 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.
720
720
fn check_cast < ' tcx > ( cx : & LateContext < ' tcx > , e : & ' tcx Expr < ' _ > , from_ty : Ty < ' tcx > , to_ty : Ty < ' tcx > ) -> Option < CastKind > {
721
721
let hir_id = e. hir_id ;
722
722
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>
743
743
DUMMY_SP ,
744
744
DUMMY_SP ,
745
745
) {
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 ( )
751
757
} else {
752
758
None
753
759
}
0 commit comments