Skip to content

Commit db51aea

Browse files
Unify conditional and non const call error reporting
1 parent bbe951e commit db51aea

12 files changed

+288
-249
lines changed

compiler/rustc_const_eval/messages.ftl

+6-8
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ const_eval_closure_call =
2121
closures need an RFC before allowed to be called in {const_eval_const_context}s
2222
const_eval_closure_fndef_not_const =
2323
function defined here, but it is not `const`
24-
const_eval_conditionally_const_call =
25-
cannot call conditionally-const {$def_descr} `{$def_path_str}` in {const_eval_const_context}s
2624
2725
const_eval_consider_dereferencing =
2826
consider dereferencing here
@@ -239,18 +237,18 @@ const_eval_non_const_await =
239237
cannot convert `{$ty}` into a future in {const_eval_const_context}s
240238
241239
const_eval_non_const_closure =
242-
cannot call {$non}-const closure in {const_eval_const_context}s
240+
cannot call {$non_or_conditionally}-const closure in {const_eval_const_context}s
243241
244242
const_eval_non_const_deref_coercion =
245-
cannot perform {$non}-const deref coercion on `{$ty}` in {const_eval_const_context}s
243+
cannot perform {$non_or_conditionally}-const deref coercion on `{$ty}` in {const_eval_const_context}s
246244
.note = attempting to deref into `{$target_ty}`
247245
.target_note = deref defined here
248246
249247
const_eval_non_const_fmt_macro_call =
250-
cannot call {$non}-const formatting macro in {const_eval_const_context}s
248+
cannot call {$non_or_conditionally}-const formatting macro in {const_eval_const_context}s
251249
252250
const_eval_non_const_fn_call =
253-
cannot call {$non}-const {$def_descr} `{$def_path_str}` in {const_eval_const_context}s
251+
cannot call {$non_or_conditionally}-const {$def_descr} `{$def_path_str}` in {const_eval_const_context}s
254252
255253
const_eval_non_const_for_loop_into_iter =
256254
cannot use `for` loop on `{$ty}` in {const_eval_const_context}s
@@ -259,13 +257,13 @@ const_eval_non_const_impl =
259257
impl defined here, but it is not `const`
260258
261259
const_eval_non_const_intrinsic =
262-
cannot call {$non}-const intrinsic `{$name}` in {const_eval_const_context}s
260+
cannot call non-const intrinsic `{$name}` in {const_eval_const_context}s
263261
264262
const_eval_non_const_match_eq = cannot match on `{$ty}` in {const_eval_const_context}s
265263
.note = `{$ty}` cannot be compared in compile-time, and therefore cannot be used in `match`es
266264
267265
const_eval_non_const_operator =
268-
cannot call {$non}-const operator in {const_eval_const_context}s
266+
cannot call {$non_or_conditionally}-const operator in {const_eval_const_context}s
269267
270268
const_eval_non_const_question_branch =
271269
`?` is not allowed on `{$ty}` in {const_eval_const_context}s

compiler/rustc_const_eval/src/check_consts/check.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,12 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
708708

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

727732
// Even if we know the callee, ensure we can use conditionally-const calls.
728733
if has_const_conditions {
729-
self.check_op(ops::ConditionallyConstCall { callee, args: fn_args });
734+
self.check_op(ops::ConditionallyConstCall {
735+
callee,
736+
args: fn_args,
737+
span: *fn_span,
738+
call_source,
739+
});
730740
}
731741

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

0 commit comments

Comments
 (0)