-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Description
In the porting to translatable diagnostics, the error messages from const validation where set up in a way that causes tons of code and text duplication:
rust/compiler/rustc_const_eval/src/errors.rs
Lines 613 to 624 in 9857952
PtrToUninhabited { ptr_kind: PointerKind::Box, .. } => { | |
const_eval_validation_box_to_uninhabited | |
} | |
PtrToUninhabited { ptr_kind: PointerKind::Ref, .. } => { | |
const_eval_validation_ref_to_uninhabited | |
} | |
PtrToStatic { ptr_kind: PointerKind::Box } => const_eval_validation_box_to_static, | |
PtrToStatic { ptr_kind: PointerKind::Ref } => const_eval_validation_ref_to_static, | |
PtrToMut { ptr_kind: PointerKind::Box } => const_eval_validation_box_to_mut, | |
PtrToMut { ptr_kind: PointerKind::Ref } => const_eval_validation_ref_to_mut, |
rust/compiler/rustc_const_eval/messages.ftl
Lines 409 to 414 in 9857952
const_eval_validation_dangling_box_no_provenance = {$front_matter}: encountered a dangling box ({$pointer} has no provenance) | |
const_eval_validation_dangling_box_out_of_bounds = {$front_matter}: encountered a dangling box (going beyond the bounds of its allocation) | |
const_eval_validation_dangling_box_use_after_free = {$front_matter}: encountered a dangling box (use-after-free) | |
const_eval_validation_dangling_ref_no_provenance = {$front_matter}: encountered a dangling reference ({$pointer} has no provenance) | |
const_eval_validation_dangling_ref_out_of_bounds = {$front_matter}: encountered a dangling reference (going beyond the bounds of its allocation) | |
const_eval_validation_dangling_ref_use_after_free = {$front_matter}: encountered a dangling reference (use-after-free) |
We shouldn't have one variant per pointer kind here, we should just tell the diagnostic about the pointer kind so that all the other text does only have to be written once. For those "dangling" messages we also should just have a single template, that only splits cases for the tail (explaining why this particular pointer is dangling). Currently we get a huge combinatorial explosion of all the things that appear in these messages, making maintenance of this code a pain.
I was about to introduce the information of whether the reference is shared or mutable, but the current system makes that way too complicated, so I'll hold off on that for now.