1
Fork 0

Auto merge of #133321 - compiler-errors:const-checker, r=wesleywiser

Get rid of HIR const checker

As far as I can tell, the HIR const checker was implemented in https://github.com/rust-lang/rust/pull/66170 because we were not able to issue useful const error messages in the MIR const checker.

This seems to have changed in the last 5 years, probably due to work like #90532. I've tweaked the diagnostics slightly and think the error messages have gotten *better* in fact.

Thus I think the HIR const checker has reached the end of its usefulness, and we can retire it.

cc `@RalfJung`
This commit is contained in:
bors 2024-12-03 04:39:48 +00:00
commit efdd9e8020
38 changed files with 151 additions and 604 deletions

View file

@ -110,7 +110,7 @@ const_eval_extern_type_field = `extern type` field does not have a known offset
const_eval_fn_ptr_call =
function pointers need an RFC before allowed to be called in {const_eval_const_context}s
const_eval_for_loop_into_iter_non_const =
cannot convert `{$ty}` into an iterator in {const_eval_const_context}s
cannot use `for` loop on `{$ty}` in {const_eval_const_context}s
const_eval_frame_note = {$times ->
[0] {const_eval_frame_note_inner}
@ -324,11 +324,11 @@ const_eval_ptr_as_bytes_1 =
this code performed an operation that depends on the underlying bytes representing a pointer
const_eval_ptr_as_bytes_2 =
the absolute address of a pointer is not known at compile-time, so such operations are not supported
const_eval_question_branch_non_const =
`?` cannot determine the branch of `{$ty}` in {const_eval_const_context}s
const_eval_question_branch_non_const =
`?` is not allowed on `{$ty}` in {const_eval_const_context}s
const_eval_question_from_residual_non_const =
`?` cannot convert from residual of `{$ty}` in {const_eval_const_context}s
`?` is not allowed on `{$ty}` in {const_eval_const_context}s
const_eval_range = in the range {$lo}..={$hi}
const_eval_range_lower = greater or equal to {$lo}

View file

@ -180,8 +180,10 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
};
}
let mut err = match kind {
CallDesugaringKind::ForLoopIntoIter => {
// Don't point at the trait if this is a desugaring...
// FIXME(const_trait_impl): we could perhaps do this for `Iterator`.
match kind {
CallDesugaringKind::ForLoopIntoIter | CallDesugaringKind::ForLoopNext => {
error!(NonConstForLoopIntoIter)
}
CallDesugaringKind::QuestionBranch => {
@ -196,10 +198,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
CallDesugaringKind::Await => {
error!(NonConstAwait)
}
};
diag_trait(&mut err, self_ty, kind.trait_def_id(tcx));
err
}
}
CallKind::FnCall { fn_trait_id, self_ty } => {
let note = match self_ty.kind() {