Skip to content

Commit 437561f

Browse files
authored
Unrolled build for rust-lang#134732
Rollup merge of rust-lang#134732 - compiler-errors:unify-conditional-const-error-reporting, r=RalfJung Unify conditional-const error reporting with non-const error reporting This PR unifies the error reporting between `ConditionallyConstCall` and `FnCallNonConst` so that the former will refer to syntactical sugar like operators by their sugared name, rather than calling all operators "methods". We achieve this by making the "non-const" part of the error message generic over the "non" part so we can plug in "conditionally" instead. This should ensure that as we constify traits in the standard library, we don't regress error messages for things like `==`. r? fmease or reassign
2 parents b44e14f + 924000d commit 437561f

12 files changed

+325
-248
lines changed

compiler/rustc_const_eval/messages.ftl

+31-28
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ const_eval_already_reported =
1212
const_eval_assume_false =
1313
`assume` called with `false`
1414
15-
const_eval_await_non_const =
16-
cannot convert `{$ty}` into a future in {const_eval_const_context}s
1715
const_eval_bounds_check_failed =
1816
indexing out of bounds: the len is {$len} but the index is {$index}
1917
const_eval_call_nonzero_intrinsic =
@@ -23,11 +21,6 @@ const_eval_closure_call =
2321
closures need an RFC before allowed to be called in {const_eval_const_context}s
2422
const_eval_closure_fndef_not_const =
2523
function defined here, but it is not `const`
26-
const_eval_closure_non_const =
27-
cannot call non-const closure in {const_eval_const_context}s
28-
29-
const_eval_conditionally_const_call =
30-
cannot call conditionally-const {$def_descr} `{$def_path_str}` in {const_eval_const_context}s
3124
3225
const_eval_consider_dereferencing =
3326
consider dereferencing here
@@ -62,10 +55,6 @@ const_eval_dealloc_incorrect_layout =
6255
const_eval_dealloc_kind_mismatch =
6356
deallocating {$alloc}, which is {$alloc_kind} memory, using {$kind} deallocation operation
6457
65-
const_eval_deref_coercion_non_const =
66-
cannot perform deref coercion on `{$ty}` in {const_eval_const_context}s
67-
.note = attempting to deref into `{$target_ty}`
68-
.target_note = deref defined here
6958
const_eval_deref_function_pointer =
7059
accessing {$allocation} which contains a function
7160
const_eval_deref_vtable_pointer =
@@ -109,9 +98,6 @@ const_eval_extern_type_field = `extern type` field does not have a known offset
10998
11099
const_eval_fn_ptr_call =
111100
function pointers need an RFC before allowed to be called in {const_eval_const_context}s
112-
const_eval_for_loop_into_iter_non_const =
113-
cannot use `for` loop on `{$ty}` in {const_eval_const_context}s
114-
115101
const_eval_frame_note = {$times ->
116102
[0] {const_eval_frame_note_inner}
117103
*[other] [... {$times} additional calls {const_eval_frame_note_inner} ...]
@@ -216,9 +202,6 @@ const_eval_long_running =
216202
.label = the const evaluator is currently interpreting this expression
217203
.help = the constant being evaluated
218204
219-
const_eval_match_eq_non_const = cannot match on `{$ty}` in {const_eval_const_context}s
220-
.note = `{$ty}` cannot be compared in compile-time, and therefore cannot be used in `match`es
221-
222205
const_eval_max_num_nodes_in_const = maximum number of nodes exceeded in constant {$global_const_id}
223206
224207
const_eval_memory_access_test = memory access failed
@@ -249,18 +232,47 @@ const_eval_mutable_ref_escaping =
249232
If you really want global mutable state, try using an interior mutable `static` or a `static mut`.
250233
251234
const_eval_nested_static_in_thread_local = #[thread_local] does not support implicit nested statics, please create explicit static items and refer to them instead
235+
236+
const_eval_non_const_await =
237+
cannot convert `{$ty}` into a future in {const_eval_const_context}s
238+
239+
const_eval_non_const_closure =
240+
cannot call {$non_or_conditionally}-const closure in {const_eval_const_context}s
241+
242+
const_eval_non_const_deref_coercion =
243+
cannot perform {$non_or_conditionally}-const deref coercion on `{$ty}` in {const_eval_const_context}s
244+
.note = attempting to deref into `{$target_ty}`
245+
.target_note = deref defined here
246+
252247
const_eval_non_const_fmt_macro_call =
253-
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
254249
255250
const_eval_non_const_fn_call =
256-
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
252+
253+
const_eval_non_const_for_loop_into_iter =
254+
cannot use `for` loop on `{$ty}` in {const_eval_const_context}s
257255
258256
const_eval_non_const_impl =
259257
impl defined here, but it is not `const`
260258
261259
const_eval_non_const_intrinsic =
262260
cannot call non-const intrinsic `{$name}` in {const_eval_const_context}s
263261
262+
const_eval_non_const_match_eq = cannot match on `{$ty}` in {const_eval_const_context}s
263+
.note = `{$ty}` cannot be compared in compile-time, and therefore cannot be used in `match`es
264+
265+
const_eval_non_const_operator =
266+
cannot call {$non_or_conditionally}-const operator in {const_eval_const_context}s
267+
268+
const_eval_non_const_question_branch =
269+
`?` is not allowed on `{$ty}` in {const_eval_const_context}s
270+
const_eval_non_const_question_from_residual =
271+
`?` is not allowed on `{$ty}` in {const_eval_const_context}s
272+
273+
const_eval_non_const_try_block_from_output =
274+
`try` block cannot convert `{$ty}` to the result in {const_eval_const_context}s
275+
264276
const_eval_not_enough_caller_args =
265277
calling a function with fewer arguments than it requires
266278
@@ -281,8 +293,6 @@ const_eval_offset_from_unsigned_overflow =
281293
*[false] offset
282294
} than second: {$a_offset} < {$b_offset}
283295
284-
const_eval_operator_non_const =
285-
cannot call non-const operator in {const_eval_const_context}s
286296
const_eval_overflow_arith =
287297
arithmetic overflow in `{$intrinsic}`
288298
const_eval_overflow_shift =
@@ -325,11 +335,6 @@ const_eval_ptr_as_bytes_1 =
325335
const_eval_ptr_as_bytes_2 =
326336
the absolute address of a pointer is not known at compile-time, so such operations are not supported
327337
328-
const_eval_question_branch_non_const =
329-
`?` is not allowed on `{$ty}` in {const_eval_const_context}s
330-
const_eval_question_from_residual_non_const =
331-
`?` is not allowed on `{$ty}` in {const_eval_const_context}s
332-
333338
const_eval_range = in the range {$lo}..={$hi}
334339
const_eval_range_lower = greater or equal to {$lo}
335340
const_eval_range_singular = equal to {$lo}
@@ -379,8 +384,6 @@ const_eval_too_generic =
379384
const_eval_too_many_caller_args =
380385
calling a function with more arguments than it expected
381386
382-
const_eval_try_block_from_output_non_const =
383-
`try` block cannot convert `{$ty}` to the result in {const_eval_const_context}s
384387
const_eval_unallowed_fn_pointer_call = function pointer calls are not allowed in {const_eval_const_context}s
385388
386389
const_eval_unallowed_heap_allocations =

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)