Skip to content

Commit

Permalink
Unify conditional and non const call error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Dec 24, 2024
1 parent 6fe780f commit 719498a
Show file tree
Hide file tree
Showing 12 changed files with 284 additions and 249 deletions.
14 changes: 6 additions & 8 deletions compiler/rustc_const_eval/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ const_eval_closure_call =
closures need an RFC before allowed to be called in {const_eval_const_context}s
const_eval_closure_fndef_not_const =
function defined here, but it is not `const`
const_eval_conditionally_const_call =
cannot call conditionally-const {$def_descr} `{$def_path_str}` in {const_eval_const_context}s
const_eval_consider_dereferencing =
consider dereferencing here
Expand Down Expand Up @@ -239,18 +237,18 @@ const_eval_non_const_await =
cannot convert `{$ty}` into a future in {const_eval_const_context}s
const_eval_non_const_closure =
cannot call {$non}-const closure in {const_eval_const_context}s
cannot call {$non_or_conditionally}-const closure in {const_eval_const_context}s
const_eval_non_const_deref_coercion =
cannot perform {$non}-const deref coercion on `{$ty}` in {const_eval_const_context}s
cannot perform {$non_or_conditionally}-const deref coercion on `{$ty}` in {const_eval_const_context}s
.note = attempting to deref into `{$target_ty}`
.target_note = deref defined here
const_eval_non_const_fmt_macro_call =
cannot call {$non}-const formatting macro in {const_eval_const_context}s
cannot call {$non_or_conditionally}-const formatting macro in {const_eval_const_context}s
const_eval_non_const_fn_call =
cannot call {$non}-const {$def_descr} `{$def_path_str}` in {const_eval_const_context}s
cannot call {$non_or_conditionally}-const {$def_descr} `{$def_path_str}` in {const_eval_const_context}s
const_eval_non_const_for_loop_into_iter =
cannot use `for` loop on `{$ty}` in {const_eval_const_context}s
Expand All @@ -259,13 +257,13 @@ const_eval_non_const_impl =
impl defined here, but it is not `const`
const_eval_non_const_intrinsic =
cannot call {$non}-const intrinsic `{$name}` in {const_eval_const_context}s
cannot call {$non_or_conditionally}-const intrinsic `{$name}` in {const_eval_const_context}s
const_eval_non_const_match_eq = cannot match on `{$ty}` in {const_eval_const_context}s
.note = `{$ty}` cannot be compared in compile-time, and therefore cannot be used in `match`es
const_eval_non_const_operator =
cannot call {$non}-const operator in {const_eval_const_context}s
cannot call {$non_or_conditionally}-const operator in {const_eval_const_context}s
const_eval_non_const_question_branch =
`?` is not allowed on `{$ty}` in {const_eval_const_context}s
Expand Down
14 changes: 12 additions & 2 deletions compiler/rustc_const_eval/src/check_consts/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,12 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {

if trait_is_const {
// Trait calls are always conditionally-const.
self.check_op(ops::ConditionallyConstCall { callee, args: fn_args });
self.check_op(ops::ConditionallyConstCall {
callee,
args: fn_args,
span: *fn_span,
call_source,
});
// FIXME(const_trait_impl): do a more fine-grained check whether this
// particular trait can be const-stably called.
} else {
Expand All @@ -726,7 +731,12 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {

// Even if we know the callee, ensure we can use conditionally-const calls.
if has_const_conditions {
self.check_op(ops::ConditionallyConstCall { callee, args: fn_args });
self.check_op(ops::ConditionallyConstCall {
callee,
args: fn_args,
span: *fn_span,
call_source,
});
}

// At this point, we are calling a function, `callee`, whose `DefId` is known...
Expand Down
Loading

0 comments on commit 719498a

Please sign in to comment.