diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs
index 316a2bf08cb03..9e9a1f678edd7 100644
--- a/compiler/rustc_hir_typeck/src/cast.rs
+++ b/compiler/rustc_hir_typeck/src/cast.rs
@@ -141,7 +141,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
| ty::Never
| ty::Dynamic(_, _, ty::DynStar)
| ty::Error(_) => {
- self.dcx().span_bug(span, format!("`{t:?}` should be sized but is not?"));
+ let guar = self
+ .dcx()
+ .span_delayed_bug(span, format!("`{t:?}` should be sized but is not?"));
+ return Err(guar);
}
})
}
diff --git a/tests/ui/cast/ice-cast-type-with-error-124848.rs b/tests/ui/cast/ice-cast-type-with-error-124848.rs
new file mode 100644
index 0000000000000..9b3732b02db43
--- /dev/null
+++ b/tests/ui/cast/ice-cast-type-with-error-124848.rs
@@ -0,0 +1,18 @@
+// Regression test for ICE #124848
+// Tests that there is no ICE when a cast
+// involves a type with error
+
+use std::cell::Cell;
+
+struct MyType<'a>(Cell