about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/base.rs9
-rw-r--r--src/constant.rs14
2 files changed, 11 insertions, 12 deletions
diff --git a/src/base.rs b/src/base.rs
index 03889a4687f..0be498172ae 100644
--- a/src/base.rs
+++ b/src/base.rs
@@ -74,7 +74,12 @@ pub(crate) fn codegen_fn<'tcx>(
             .is_uninhabited()
     });
 
-    if arg_uninhabited {
+    if !crate::constant::check_constants(&mut fx) {
+        fx.bcx
+            .append_block_params_for_function_params(fx.block_map[START_BLOCK]);
+        fx.bcx.switch_to_block(fx.block_map[START_BLOCK]);
+        crate::trap::trap_unreachable(&mut fx, "compilation should have been aborted");
+    } else if arg_uninhabited {
         fx.bcx
             .append_block_params_for_function_params(fx.block_map[START_BLOCK]);
         fx.bcx.switch_to_block(fx.block_map[START_BLOCK]);
@@ -205,8 +210,6 @@ pub(crate) fn verify_func(
 }
 
 fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) {
-    crate::constant::check_constants(fx);
-
     for (bb, bb_data) in fx.mir.basic_blocks().iter_enumerated() {
         let block = fx.get_block(bb);
         fx.bcx.switch_to_block(block);
diff --git a/src/constant.rs b/src/constant.rs
index 5702832bcb6..f3e17774fdf 100644
--- a/src/constant.rs
+++ b/src/constant.rs
@@ -36,7 +36,8 @@ impl ConstantCx {
     }
 }
 
-pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, impl Module>) {
+pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, impl Module>) -> bool {
+    let mut all_constants_ok = true;
     for constant in &fx.mir.required_consts {
         let const_ = fx.monomorphize(constant.literal);
         match const_.val {
@@ -46,6 +47,7 @@ pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, impl Module>) {
                     fx.tcx
                         .const_eval_resolve(ParamEnv::reveal_all(), def, substs, promoted, None)
                 {
+                    all_constants_ok = false;
                     match err {
                         ErrorHandled::Reported(ErrorReported) | ErrorHandled::Linted => {
                             fx.tcx
@@ -69,6 +71,7 @@ pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, impl Module>) {
             | ConstKind::Error(_) => unreachable!("{:?}", const_),
         }
     }
+    all_constants_ok
 }
 
 pub(crate) fn codegen_static(constants_cx: &mut ConstantCx, def_id: DefId) {
@@ -134,14 +137,7 @@ pub(crate) fn codegen_constant<'tcx>(
             {
                 Ok(const_val) => const_val,
                 Err(_) => {
-                    fx.tcx
-                        .sess
-                        .span_err(constant.span, "erroneous constant encountered");
-                    return crate::trap::trap_unreachable_ret_value(
-                        fx,
-                        fx.layout_of(const_.ty),
-                        "erroneous constant encountered",
-                    );
+                    span_bug!(constant.span, "erroneous constant not captured by required_consts");
                 }
             }
         }