Skip to content

Commit 13bd4c7

Browse files
Update compiler source code to more easily check if error messages are used
1 parent 40acdf6 commit 13bd4c7

File tree

3 files changed

+123
-125
lines changed

3 files changed

+123
-125
lines changed

compiler/rustc_const_eval/src/const_eval/error.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,22 @@ impl MachineStopType for ConstEvalErrKind {
4444
fn diagnostic_message(&self) -> DiagMessage {
4545
use ConstEvalErrKind::*;
4646

47-
use crate::fluent_generated::*;
47+
use crate::fluent_generated as fluent;
4848
match self {
49-
ConstAccessesMutGlobal => const_eval_const_accesses_mut_global,
50-
ModifiedGlobal => const_eval_modified_global,
51-
Panic { .. } => const_eval_panic,
52-
RecursiveStatic => const_eval_recursive_static,
49+
ConstAccessesMutGlobal => fluent::const_eval_const_accesses_mut_global,
50+
ModifiedGlobal => fluent::const_eval_modified_global,
51+
Panic { .. } => fluent::const_eval_panic,
52+
RecursiveStatic => fluent::const_eval_recursive_static,
5353
AssertFailure(x) => x.diagnostic_message(),
54-
WriteThroughImmutablePointer => const_eval_write_through_immutable_pointer,
54+
WriteThroughImmutablePointer => fluent::const_eval_write_through_immutable_pointer,
5555
ConstMakeGlobalPtrAlreadyMadeGlobal { .. } => {
56-
const_eval_const_make_global_ptr_already_made_global
56+
fluent::const_eval_const_make_global_ptr_already_made_global
5757
}
58-
ConstMakeGlobalPtrIsNonHeap(_) => const_eval_const_make_global_ptr_is_non_heap,
59-
ConstMakeGlobalWithDanglingPtr(_) => const_eval_const_make_global_with_dangling_ptr,
60-
ConstMakeGlobalWithOffset(_) => const_eval_const_make_global_with_offset,
58+
ConstMakeGlobalPtrIsNonHeap(_) => fluent::const_eval_const_make_global_ptr_is_non_heap,
59+
ConstMakeGlobalWithDanglingPtr(_) => {
60+
fluent::const_eval_const_make_global_with_dangling_ptr
61+
}
62+
ConstMakeGlobalWithOffset(_) => fluent::const_eval_const_make_global_with_offset,
6163
}
6264
}
6365
fn add_args(self: Box<Self>, adder: &mut dyn FnMut(DiagArgName, DiagArgValue)) {

compiler/rustc_const_eval/src/errors.rs

Lines changed: 92 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -466,51 +466,50 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
466466
fn diagnostic_message(&self) -> DiagMessage {
467467
use UndefinedBehaviorInfo::*;
468468

469-
use crate::fluent_generated::*;
470469
match self {
471470
Ub(msg) => msg.clone().into(),
472471
Custom(x) => (x.msg)(),
473472
ValidationError(e) => e.diagnostic_message(),
474473

475-
Unreachable => const_eval_unreachable,
476-
BoundsCheckFailed { .. } => const_eval_bounds_check_failed,
477-
DivisionByZero => const_eval_division_by_zero,
478-
RemainderByZero => const_eval_remainder_by_zero,
479-
DivisionOverflow => const_eval_division_overflow,
480-
RemainderOverflow => const_eval_remainder_overflow,
481-
PointerArithOverflow => const_eval_pointer_arithmetic_overflow,
482-
ArithOverflow { .. } => const_eval_overflow_arith,
483-
ShiftOverflow { .. } => const_eval_overflow_shift,
484-
InvalidMeta(InvalidMetaKind::SliceTooBig) => const_eval_invalid_meta_slice,
485-
InvalidMeta(InvalidMetaKind::TooBig) => const_eval_invalid_meta,
486-
UnterminatedCString(_) => const_eval_unterminated_c_string,
487-
PointerUseAfterFree(_, _) => const_eval_pointer_use_after_free,
488-
PointerOutOfBounds { .. } => const_eval_pointer_out_of_bounds,
489-
DanglingIntPointer { addr: 0, .. } => const_eval_dangling_null_pointer,
490-
DanglingIntPointer { .. } => const_eval_dangling_int_pointer,
491-
AlignmentCheckFailed { .. } => const_eval_alignment_check_failed,
492-
WriteToReadOnly(_) => const_eval_write_to_read_only,
493-
DerefFunctionPointer(_) => const_eval_deref_function_pointer,
494-
DerefVTablePointer(_) => const_eval_deref_vtable_pointer,
495-
DerefTypeIdPointer(_) => const_eval_deref_typeid_pointer,
496-
InvalidBool(_) => const_eval_invalid_bool,
497-
InvalidChar(_) => const_eval_invalid_char,
498-
InvalidTag(_) => const_eval_invalid_tag,
499-
InvalidFunctionPointer(_) => const_eval_invalid_function_pointer,
500-
InvalidVTablePointer(_) => const_eval_invalid_vtable_pointer,
501-
InvalidVTableTrait { .. } => const_eval_invalid_vtable_trait,
502-
InvalidStr(_) => const_eval_invalid_str,
503-
InvalidUninitBytes(None) => const_eval_invalid_uninit_bytes_unknown,
504-
InvalidUninitBytes(Some(_)) => const_eval_invalid_uninit_bytes,
505-
DeadLocal => const_eval_dead_local,
506-
ScalarSizeMismatch(_) => const_eval_scalar_size_mismatch,
507-
UninhabitedEnumVariantWritten(_) => const_eval_uninhabited_enum_variant_written,
508-
UninhabitedEnumVariantRead(_) => const_eval_uninhabited_enum_variant_read,
474+
Unreachable => fluent::const_eval_unreachable,
475+
BoundsCheckFailed { .. } => fluent::const_eval_bounds_check_failed,
476+
DivisionByZero => fluent::const_eval_division_by_zero,
477+
RemainderByZero => fluent::const_eval_remainder_by_zero,
478+
DivisionOverflow => fluent::const_eval_division_overflow,
479+
RemainderOverflow => fluent::const_eval_remainder_overflow,
480+
PointerArithOverflow => fluent::const_eval_pointer_arithmetic_overflow,
481+
ArithOverflow { .. } => fluent::const_eval_overflow_arith,
482+
ShiftOverflow { .. } => fluent::const_eval_overflow_shift,
483+
InvalidMeta(InvalidMetaKind::SliceTooBig) => fluent::const_eval_invalid_meta_slice,
484+
InvalidMeta(InvalidMetaKind::TooBig) => fluent::const_eval_invalid_meta,
485+
UnterminatedCString(_) => fluent::const_eval_unterminated_c_string,
486+
PointerUseAfterFree(_, _) => fluent::const_eval_pointer_use_after_free,
487+
PointerOutOfBounds { .. } => fluent::const_eval_pointer_out_of_bounds,
488+
DanglingIntPointer { addr: 0, .. } => fluent::const_eval_dangling_null_pointer,
489+
DanglingIntPointer { .. } => fluent::const_eval_dangling_int_pointer,
490+
AlignmentCheckFailed { .. } => fluent::const_eval_alignment_check_failed,
491+
WriteToReadOnly(_) => fluent::const_eval_write_to_read_only,
492+
DerefFunctionPointer(_) => fluent::const_eval_deref_function_pointer,
493+
DerefVTablePointer(_) => fluent::const_eval_deref_vtable_pointer,
494+
DerefTypeIdPointer(_) => fluent::const_eval_deref_typeid_pointer,
495+
InvalidBool(_) => fluent::const_eval_invalid_bool,
496+
InvalidChar(_) => fluent::const_eval_invalid_char,
497+
InvalidTag(_) => fluent::const_eval_invalid_tag,
498+
InvalidFunctionPointer(_) => fluent::const_eval_invalid_function_pointer,
499+
InvalidVTablePointer(_) => fluent::const_eval_invalid_vtable_pointer,
500+
InvalidVTableTrait { .. } => fluent::const_eval_invalid_vtable_trait,
501+
InvalidStr(_) => fluent::const_eval_invalid_str,
502+
InvalidUninitBytes(None) => fluent::const_eval_invalid_uninit_bytes_unknown,
503+
InvalidUninitBytes(Some(_)) => fluent::const_eval_invalid_uninit_bytes,
504+
DeadLocal => fluent::const_eval_dead_local,
505+
ScalarSizeMismatch(_) => fluent::const_eval_scalar_size_mismatch,
506+
UninhabitedEnumVariantWritten(_) => fluent::const_eval_uninhabited_enum_variant_written,
507+
UninhabitedEnumVariantRead(_) => fluent::const_eval_uninhabited_enum_variant_read,
509508
InvalidNichedEnumVariantWritten { .. } => {
510-
const_eval_invalid_niched_enum_variant_written
509+
fluent::const_eval_invalid_niched_enum_variant_written
511510
}
512-
AbiMismatchArgument { .. } => const_eval_incompatible_arg_types,
513-
AbiMismatchReturn { .. } => const_eval_incompatible_return_types,
511+
AbiMismatchArgument { .. } => fluent::const_eval_incompatible_arg_types,
512+
AbiMismatchReturn { .. } => fluent::const_eval_incompatible_return_types,
514513
}
515514
}
516515

@@ -653,80 +652,79 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
653652
fn diagnostic_message(&self) -> DiagMessage {
654653
use rustc_middle::mir::interpret::ValidationErrorKind::*;
655654

656-
use crate::fluent_generated::*;
657655
match self.kind {
658656
PtrToUninhabited { ptr_kind: PointerKind::Box, .. } => {
659-
const_eval_validation_box_to_uninhabited
657+
fluent::const_eval_validation_box_to_uninhabited
660658
}
661659
PtrToUninhabited { ptr_kind: PointerKind::Ref(_), .. } => {
662-
const_eval_validation_ref_to_uninhabited
663-
}
664-
665-
PointerAsInt { .. } => const_eval_validation_pointer_as_int,
666-
PartialPointer => const_eval_validation_partial_pointer,
667-
MutableRefToImmutable => const_eval_validation_mutable_ref_to_immutable,
668-
MutableRefInConst => const_eval_validation_mutable_ref_in_const,
669-
NullFnPtr => const_eval_validation_null_fn_ptr,
670-
NeverVal => const_eval_validation_never_val,
671-
NonnullPtrMaybeNull { .. } => const_eval_validation_nonnull_ptr_out_of_range,
672-
PtrOutOfRange { .. } => const_eval_validation_ptr_out_of_range,
673-
OutOfRange { .. } => const_eval_validation_out_of_range,
674-
UnsafeCellInImmutable => const_eval_validation_unsafe_cell,
675-
UninhabitedVal { .. } => const_eval_validation_uninhabited_val,
676-
InvalidEnumTag { .. } => const_eval_validation_invalid_enum_tag,
677-
UninhabitedEnumVariant => const_eval_validation_uninhabited_enum_variant,
678-
Uninit { .. } => const_eval_validation_uninit,
679-
InvalidVTablePtr { .. } => const_eval_validation_invalid_vtable_ptr,
680-
InvalidMetaWrongTrait { .. } => const_eval_validation_invalid_vtable_trait,
660+
fluent::const_eval_validation_ref_to_uninhabited
661+
}
662+
663+
PointerAsInt { .. } => fluent::const_eval_validation_pointer_as_int,
664+
PartialPointer => fluent::const_eval_validation_partial_pointer,
665+
MutableRefToImmutable => fluent::const_eval_validation_mutable_ref_to_immutable,
666+
MutableRefInConst => fluent::const_eval_validation_mutable_ref_in_const,
667+
NullFnPtr => fluent::const_eval_validation_null_fn_ptr,
668+
NeverVal => fluent::const_eval_validation_never_val,
669+
NonnullPtrMaybeNull { .. } => fluent::const_eval_validation_nonnull_ptr_out_of_range,
670+
PtrOutOfRange { .. } => fluent::const_eval_validation_ptr_out_of_range,
671+
OutOfRange { .. } => fluent::const_eval_validation_out_of_range,
672+
UnsafeCellInImmutable => fluent::const_eval_validation_unsafe_cell,
673+
UninhabitedVal { .. } => fluent::const_eval_validation_uninhabited_val,
674+
InvalidEnumTag { .. } => fluent::const_eval_validation_invalid_enum_tag,
675+
UninhabitedEnumVariant => fluent::const_eval_validation_uninhabited_enum_variant,
676+
Uninit { .. } => fluent::const_eval_validation_uninit,
677+
InvalidVTablePtr { .. } => fluent::const_eval_validation_invalid_vtable_ptr,
678+
InvalidMetaWrongTrait { .. } => fluent::const_eval_validation_invalid_vtable_trait,
681679
InvalidMetaSliceTooLarge { ptr_kind: PointerKind::Box } => {
682-
const_eval_validation_invalid_box_slice_meta
680+
fluent::const_eval_validation_invalid_box_slice_meta
683681
}
684682
InvalidMetaSliceTooLarge { ptr_kind: PointerKind::Ref(_) } => {
685-
const_eval_validation_invalid_ref_slice_meta
683+
fluent::const_eval_validation_invalid_ref_slice_meta
686684
}
687685

688686
InvalidMetaTooLarge { ptr_kind: PointerKind::Box } => {
689-
const_eval_validation_invalid_box_meta
687+
fluent::const_eval_validation_invalid_box_meta
690688
}
691689
InvalidMetaTooLarge { ptr_kind: PointerKind::Ref(_) } => {
692-
const_eval_validation_invalid_ref_meta
690+
fluent::const_eval_validation_invalid_ref_meta
693691
}
694692
UnalignedPtr { ptr_kind: PointerKind::Ref(_), .. } => {
695-
const_eval_validation_unaligned_ref
693+
fluent::const_eval_validation_unaligned_ref
694+
}
695+
UnalignedPtr { ptr_kind: PointerKind::Box, .. } => {
696+
fluent::const_eval_validation_unaligned_box
696697
}
697-
UnalignedPtr { ptr_kind: PointerKind::Box, .. } => const_eval_validation_unaligned_box,
698698

699-
NullPtr { ptr_kind: PointerKind::Box, .. } => const_eval_validation_null_box,
700-
NullPtr { ptr_kind: PointerKind::Ref(_), .. } => const_eval_validation_null_ref,
699+
NullPtr { ptr_kind: PointerKind::Box, .. } => fluent::const_eval_validation_null_box,
700+
NullPtr { ptr_kind: PointerKind::Ref(_), .. } => fluent::const_eval_validation_null_ref,
701701
DanglingPtrNoProvenance { ptr_kind: PointerKind::Box, .. } => {
702-
const_eval_validation_dangling_box_no_provenance
702+
fluent::const_eval_validation_dangling_box_no_provenance
703703
}
704704
DanglingPtrNoProvenance { ptr_kind: PointerKind::Ref(_), .. } => {
705-
const_eval_validation_dangling_ref_no_provenance
705+
fluent::const_eval_validation_dangling_ref_no_provenance
706706
}
707707
DanglingPtrOutOfBounds { ptr_kind: PointerKind::Box } => {
708-
const_eval_validation_dangling_box_out_of_bounds
708+
fluent::const_eval_validation_dangling_box_out_of_bounds
709709
}
710710
DanglingPtrOutOfBounds { ptr_kind: PointerKind::Ref(_) } => {
711-
const_eval_validation_dangling_ref_out_of_bounds
711+
fluent::const_eval_validation_dangling_ref_out_of_bounds
712712
}
713713
DanglingPtrUseAfterFree { ptr_kind: PointerKind::Box } => {
714-
const_eval_validation_dangling_box_use_after_free
714+
fluent::const_eval_validation_dangling_box_use_after_free
715715
}
716716
DanglingPtrUseAfterFree { ptr_kind: PointerKind::Ref(_) } => {
717-
const_eval_validation_dangling_ref_use_after_free
717+
fluent::const_eval_validation_dangling_ref_use_after_free
718718
}
719-
InvalidBool { .. } => const_eval_validation_invalid_bool,
720-
InvalidChar { .. } => const_eval_validation_invalid_char,
721-
InvalidFnPtr { .. } => const_eval_validation_invalid_fn_ptr,
719+
InvalidBool { .. } => fluent::const_eval_validation_invalid_bool,
720+
InvalidChar { .. } => fluent::const_eval_validation_invalid_char,
721+
InvalidFnPtr { .. } => fluent::const_eval_validation_invalid_fn_ptr,
722722
}
723723
}
724724

725725
fn add_args<G: EmissionGuarantee>(self, err: &mut Diag<'_, G>) {
726726
use rustc_middle::mir::interpret::ValidationErrorKind::*;
727727

728-
use crate::fluent_generated as fluent;
729-
730728
if let PointerAsInt { .. } | PartialPointer = self.kind {
731729
err.help(fluent::const_eval_ptr_as_bytes_1);
732730
err.help(fluent::const_eval_ptr_as_bytes_2);
@@ -841,25 +839,23 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
841839

842840
impl ReportErrorExt for UnsupportedOpInfo {
843841
fn diagnostic_message(&self) -> DiagMessage {
844-
use crate::fluent_generated::*;
845842
match self {
846843
UnsupportedOpInfo::Unsupported(s) => s.clone().into(),
847-
UnsupportedOpInfo::ExternTypeField => const_eval_extern_type_field,
848-
UnsupportedOpInfo::UnsizedLocal => const_eval_unsized_local,
849-
UnsupportedOpInfo::ReadPartialPointer(_) => const_eval_partial_pointer_read,
850-
UnsupportedOpInfo::ReadPointerAsInt(_) => const_eval_read_pointer_as_int,
851-
UnsupportedOpInfo::ThreadLocalStatic(_) => const_eval_thread_local_static,
852-
UnsupportedOpInfo::ExternStatic(_) => const_eval_extern_static,
844+
UnsupportedOpInfo::ExternTypeField => fluent::const_eval_extern_type_field,
845+
UnsupportedOpInfo::UnsizedLocal => fluent::const_eval_unsized_local,
846+
UnsupportedOpInfo::ReadPartialPointer(_) => fluent::const_eval_partial_pointer_read,
847+
UnsupportedOpInfo::ReadPointerAsInt(_) => fluent::const_eval_read_pointer_as_int,
848+
UnsupportedOpInfo::ThreadLocalStatic(_) => fluent::const_eval_thread_local_static,
849+
UnsupportedOpInfo::ExternStatic(_) => fluent::const_eval_extern_static,
853850
}
854851
}
855852

856853
fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
857854
use UnsupportedOpInfo::*;
858855

859-
use crate::fluent_generated::*;
860856
if let ReadPointerAsInt(_) | ReadPartialPointer(_) = self {
861-
diag.help(const_eval_ptr_as_bytes_1);
862-
diag.help(const_eval_ptr_as_bytes_2);
857+
diag.help(fluent::const_eval_ptr_as_bytes_1);
858+
diag.help(fluent::const_eval_ptr_as_bytes_2);
863859
}
864860
match self {
865861
// `ReadPointerAsInt(Some(info))` is never printed anyway, it only serves as an error to
@@ -904,10 +900,9 @@ impl<'tcx> ReportErrorExt for InterpErrorKind<'tcx> {
904900

905901
impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> {
906902
fn diagnostic_message(&self) -> DiagMessage {
907-
use crate::fluent_generated::*;
908903
match self {
909-
InvalidProgramInfo::TooGeneric => const_eval_too_generic,
910-
InvalidProgramInfo::AlreadyReported(_) => const_eval_already_reported,
904+
InvalidProgramInfo::TooGeneric => fluent::const_eval_too_generic,
905+
InvalidProgramInfo::AlreadyReported(_) => fluent::const_eval_already_reported,
911906
InvalidProgramInfo::Layout(e) => e.diagnostic_message(),
912907
}
913908
}
@@ -929,12 +924,13 @@ impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> {
929924

930925
impl ReportErrorExt for ResourceExhaustionInfo {
931926
fn diagnostic_message(&self) -> DiagMessage {
932-
use crate::fluent_generated::*;
933927
match self {
934-
ResourceExhaustionInfo::StackFrameLimitReached => const_eval_stack_frame_limit_reached,
935-
ResourceExhaustionInfo::MemoryExhausted => const_eval_memory_exhausted,
936-
ResourceExhaustionInfo::AddressSpaceFull => const_eval_address_space_full,
937-
ResourceExhaustionInfo::Interrupted => const_eval_interrupted,
928+
ResourceExhaustionInfo::StackFrameLimitReached => {
929+
fluent::const_eval_stack_frame_limit_reached
930+
}
931+
ResourceExhaustionInfo::MemoryExhausted => fluent::const_eval_memory_exhausted,
932+
ResourceExhaustionInfo::AddressSpaceFull => fluent::const_eval_address_space_full,
933+
ResourceExhaustionInfo::Interrupted => fluent::const_eval_interrupted,
938934
}
939935
}
940936
fn add_args<G: EmissionGuarantee>(self, _: &mut Diag<'_, G>) {}

0 commit comments

Comments
 (0)