From b7cc765b602bcb1e0a0a8883b6d982c47b3236c1 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 11 Sep 2023 23:09:11 +0200 Subject: [PATCH] don't point at const usage site for resolution-time errors also share the code that emits the actual error --- src/base.rs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/base.rs b/src/base.rs index e41c6b31e9c..9b5a6b89191 100644 --- a/src/base.rs +++ b/src/base.rs @@ -2,7 +2,6 @@ use rustc_ast::InlineAsmOptions; use rustc_index::IndexVec; -use rustc_middle::mir::interpret::ErrorHandled; use rustc_middle::ty::adjustment::PointerCoercion; use rustc_middle::ty::layout::FnAbiOf; use rustc_middle::ty::print::with_no_trimmed_paths; @@ -251,21 +250,15 @@ pub(crate) fn verify_func( } fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { - match fx.mir.post_mono_checks(fx.tcx, ty::ParamEnv::reveal_all(), |c| Ok(fx.monomorphize(c))) { - Ok(()) => {} - Err(ErrorHandled::TooGeneric(span)) => { - span_bug!(span, "codegen encountered polymorphic constant"); - } - Err(ErrorHandled::Reported(info, span)) => { - if !info.is_tainted_by_errors() { - fx.tcx.sess.span_err(span, "erroneous constant encountered"); - } - fx.bcx.append_block_params_for_function_params(fx.block_map[START_BLOCK]); - fx.bcx.switch_to_block(fx.block_map[START_BLOCK]); - // compilation should have been aborted - fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); - return; - } + if let Err(err) = + fx.mir.post_mono_checks(fx.tcx, ty::ParamEnv::reveal_all(), |c| Ok(fx.monomorphize(c))) + { + err.emit_err(fx.tcx); + fx.bcx.append_block_params_for_function_params(fx.block_map[START_BLOCK]); + fx.bcx.switch_to_block(fx.block_map[START_BLOCK]); + // compilation should have been aborted + fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); + return; } let arg_uninhabited = fx