Skip to content

Commit

Permalink
don't point at const usage site for resolution-time errors
Browse files Browse the repository at this point in the history
also share the code that emits the actual error
  • Loading branch information
RalfJung committed Sep 14, 2023
1 parent 3113fef commit b7cc765
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b7cc765

Please sign in to comment.