don't point at const usage site for resolution-time errors

also share the code that emits the actual error
This commit is contained in:
Ralf Jung 2023-09-11 23:09:11 +02:00
parent 3113fef3a3
commit b7cc765b60

View File

@ -2,7 +2,6 @@
use rustc_ast::InlineAsmOptions; use rustc_ast::InlineAsmOptions;
use rustc_index::IndexVec; use rustc_index::IndexVec;
use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::ty::adjustment::PointerCoercion; use rustc_middle::ty::adjustment::PointerCoercion;
use rustc_middle::ty::layout::FnAbiOf; use rustc_middle::ty::layout::FnAbiOf;
use rustc_middle::ty::print::with_no_trimmed_paths; 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) { 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))) { if let Err(err) =
Ok(()) => {} fx.mir.post_mono_checks(fx.tcx, ty::ParamEnv::reveal_all(), |c| Ok(fx.monomorphize(c)))
Err(ErrorHandled::TooGeneric(span)) => { {
span_bug!(span, "codegen encountered polymorphic constant"); err.emit_err(fx.tcx);
} fx.bcx.append_block_params_for_function_params(fx.block_map[START_BLOCK]);
Err(ErrorHandled::Reported(info, span)) => { fx.bcx.switch_to_block(fx.block_map[START_BLOCK]);
if !info.is_tainted_by_errors() { // compilation should have been aborted
fx.tcx.sess.span_err(span, "erroneous constant encountered"); fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
} return;
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 let arg_uninhabited = fx