@@ -513,7 +513,7 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
513513 ScalarSizeMismatch(_) => const_eval_scalar_size_mismatch,
514514 UninhabitedEnumVariantWritten(_) => const_eval_uninhabited_enum_variant_written,
515515 UninhabitedEnumVariantRead(_) => const_eval_uninhabited_enum_variant_read,
516- Validation (e) => e.diagnostic_message(),
516+ ValidationError (e) => e.diagnostic_message(),
517517 Custom(x) => (x.msg)(),
518518 }
519519 }
@@ -587,13 +587,13 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
587587 InvalidUninitBytes(Some((alloc, info))) => {
588588 builder.set_arg("alloc", alloc);
589589 builder.set_arg("access", info.access);
590- builder.set_arg("uninit", info.uninit );
590+ builder.set_arg("uninit", info.bad );
591591 }
592592 ScalarSizeMismatch(info) => {
593593 builder.set_arg("target_size", info.target_size);
594594 builder.set_arg("data_size", info.data_size);
595595 }
596- Validation (e) => e.add_args(handler, builder),
596+ ValidationError (e) => e.add_args(handler, builder),
597597 Custom(custom) => {
598598 (custom.add_args)(&mut |name, value| {
599599 builder.set_arg(name, value);
@@ -608,88 +608,94 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
608608 use crate::fluent_generated::*;
609609 use rustc_middle::mir::interpret::ValidationErrorKind::*;
610610 match self.kind {
611- PtrToUninhabited { ptr_kind: PointerKind::Box, .. } => const_eval_box_to_uninhabited,
612- PtrToUninhabited { ptr_kind: PointerKind::Ref, .. } => const_eval_ref_to_uninhabited,
613-
614- PtrToStatic { ptr_kind: PointerKind::Box } => const_eval_box_to_static,
615- PtrToStatic { ptr_kind: PointerKind::Ref } => const_eval_ref_to_static,
616-
617- PtrToMut { ptr_kind: PointerKind::Box } => const_eval_box_to_mut,
618- PtrToMut { ptr_kind: PointerKind::Ref } => const_eval_ref_to_mut,
619-
620- ExpectedNonPtr { .. } => const_eval_expected_non_ptr,
621- MutableRefInConst => const_eval_mutable_ref_in_const,
622- NullFnPtr => const_eval_null_fn_ptr,
623- NeverVal => const_eval_never_val,
624- NullablePtrOutOfRange { .. } => const_eval_nullable_ptr_out_of_range,
625- PtrOutOfRange { .. } => const_eval_ptr_out_of_range,
626- OutOfRange { .. } => const_eval_out_of_range,
627- UnsafeCell => const_eval_unsafe_cell,
628- UninhabitedVal { .. } => const_eval_uninhabited_val,
629- InvalidEnumTag { .. } => const_eval_invalid_enum_tag,
630- UninhabitedEnumTag => const_eval_uninhabited_enum_tag,
631- UninitEnumTag => const_eval_uninit_enum_tag,
632- UninitStr => const_eval_uninit_str,
633- Uninit { expected: ExpectedKind::Bool } => const_eval_uninit_bool,
634- Uninit { expected: ExpectedKind::Reference } => const_eval_uninit_ref,
635- Uninit { expected: ExpectedKind::Box } => const_eval_uninit_box,
636- Uninit { expected: ExpectedKind::RawPtr } => const_eval_uninit_raw_ptr,
637- Uninit { expected: ExpectedKind::InitScalar } => const_eval_uninit_init_scalar,
638- Uninit { expected: ExpectedKind::Char } => const_eval_uninit_char,
639- Uninit { expected: ExpectedKind::Float } => const_eval_uninit_float,
640- Uninit { expected: ExpectedKind::Int } => const_eval_uninit_int,
641- Uninit { expected: ExpectedKind::FnPtr } => const_eval_uninit_fn_ptr,
642- UninitVal => const_eval_uninit,
643- InvalidVTablePtr { .. } => const_eval_invalid_vtable_ptr,
611+ PtrToUninhabited { ptr_kind: PointerKind::Box, .. } => {
612+ const_eval_validation_box_to_uninhabited
613+ }
614+ PtrToUninhabited { ptr_kind: PointerKind::Ref, .. } => {
615+ const_eval_validation_ref_to_uninhabited
616+ }
617+
618+ PtrToStatic { ptr_kind: PointerKind::Box } => const_eval_validation_box_to_static,
619+ PtrToStatic { ptr_kind: PointerKind::Ref } => const_eval_validation_ref_to_static,
620+
621+ PtrToMut { ptr_kind: PointerKind::Box } => const_eval_validation_box_to_mut,
622+ PtrToMut { ptr_kind: PointerKind::Ref } => const_eval_validation_ref_to_mut,
623+
624+ PointerAsInt { .. } => const_eval_validation_pointer_as_int,
625+ PartialPointer => const_eval_validation_partial_pointer,
626+ MutableRefInConst => const_eval_validation_mutable_ref_in_const,
627+ NullFnPtr => const_eval_validation_null_fn_ptr,
628+ NeverVal => const_eval_validation_never_val,
629+ NullablePtrOutOfRange { .. } => const_eval_validation_nullable_ptr_out_of_range,
630+ PtrOutOfRange { .. } => const_eval_validation_ptr_out_of_range,
631+ OutOfRange { .. } => const_eval_validation_out_of_range,
632+ UnsafeCell => const_eval_validation_unsafe_cell,
633+ UninhabitedVal { .. } => const_eval_validation_uninhabited_val,
634+ InvalidEnumTag { .. } => const_eval_validation_invalid_enum_tag,
635+ UninhabitedEnumVariant => const_eval_validation_uninhabited_enum_variant,
636+ Uninit { .. } => const_eval_validation_uninit,
637+ InvalidVTablePtr { .. } => const_eval_validation_invalid_vtable_ptr,
644638 InvalidMetaSliceTooLarge { ptr_kind: PointerKind::Box } => {
645- const_eval_invalid_box_slice_meta
639+ const_eval_validation_invalid_box_slice_meta
646640 }
647641 InvalidMetaSliceTooLarge { ptr_kind: PointerKind::Ref } => {
648- const_eval_invalid_ref_slice_meta
642+ const_eval_validation_invalid_ref_slice_meta
649643 }
650644
651- InvalidMetaTooLarge { ptr_kind: PointerKind::Box } => const_eval_invalid_box_meta,
652- InvalidMetaTooLarge { ptr_kind: PointerKind::Ref } => const_eval_invalid_ref_meta,
653- UnalignedPtr { ptr_kind: PointerKind::Ref, .. } => const_eval_unaligned_ref,
654- UnalignedPtr { ptr_kind: PointerKind::Box, .. } => const_eval_unaligned_box,
645+ InvalidMetaTooLarge { ptr_kind: PointerKind::Box } => {
646+ const_eval_validation_invalid_box_meta
647+ }
648+ InvalidMetaTooLarge { ptr_kind: PointerKind::Ref } => {
649+ const_eval_validation_invalid_ref_meta
650+ }
651+ UnalignedPtr { ptr_kind: PointerKind::Ref, .. } => const_eval_validation_unaligned_ref,
652+ UnalignedPtr { ptr_kind: PointerKind::Box, .. } => const_eval_validation_unaligned_box,
655653
656- NullPtr { ptr_kind: PointerKind::Box } => const_eval_null_box ,
657- NullPtr { ptr_kind: PointerKind::Ref } => const_eval_null_ref ,
654+ NullPtr { ptr_kind: PointerKind::Box } => const_eval_validation_null_box ,
655+ NullPtr { ptr_kind: PointerKind::Ref } => const_eval_validation_null_ref ,
658656 DanglingPtrNoProvenance { ptr_kind: PointerKind::Box, .. } => {
659- const_eval_dangling_box_no_provenance
657+ const_eval_validation_dangling_box_no_provenance
660658 }
661659 DanglingPtrNoProvenance { ptr_kind: PointerKind::Ref, .. } => {
662- const_eval_dangling_ref_no_provenance
660+ const_eval_validation_dangling_ref_no_provenance
663661 }
664662 DanglingPtrOutOfBounds { ptr_kind: PointerKind::Box } => {
665- const_eval_dangling_box_out_of_bounds
663+ const_eval_validation_dangling_box_out_of_bounds
666664 }
667665 DanglingPtrOutOfBounds { ptr_kind: PointerKind::Ref } => {
668- const_eval_dangling_ref_out_of_bounds
666+ const_eval_validation_dangling_ref_out_of_bounds
669667 }
670668 DanglingPtrUseAfterFree { ptr_kind: PointerKind::Box } => {
671- const_eval_dangling_box_use_after_free
669+ const_eval_validation_dangling_box_use_after_free
672670 }
673671 DanglingPtrUseAfterFree { ptr_kind: PointerKind::Ref } => {
674- const_eval_dangling_ref_use_after_free
672+ const_eval_validation_dangling_ref_use_after_free
675673 }
676674 InvalidBool { .. } => const_eval_validation_invalid_bool,
677675 InvalidChar { .. } => const_eval_validation_invalid_char,
678- InvalidFnPtr { .. } => const_eval_invalid_fn_ptr ,
676+ InvalidFnPtr { .. } => const_eval_validation_invalid_fn_ptr ,
679677 }
680678 }
681679
682680 fn add_args<G: EmissionGuarantee>(self, handler: &Handler, err: &mut DiagnosticBuilder<'_, G>) {
683681 use crate::fluent_generated as fluent;
684682 use rustc_middle::mir::interpret::ValidationErrorKind::*;
685683
684+ if let PointerAsInt { .. } | PartialPointer = self.kind {
685+ err.help(fluent::const_eval_ptr_as_bytes_1);
686+ err.help(fluent::const_eval_ptr_as_bytes_2);
687+ }
688+
686689 let message = if let Some(path) = self.path {
687690 handler.eagerly_translate_to_string(
688- fluent::const_eval_invalid_value_with_path ,
691+ fluent::const_eval_validation_front_matter_invalid_value_with_path ,
689692 [("path".into(), DiagnosticArgValue::Str(path.into()))].iter().map(|(a, b)| (a, b)),
690693 )
691694 } else {
692- handler.eagerly_translate_to_string(fluent::const_eval_invalid_value, [].into_iter())
695+ handler.eagerly_translate_to_string(
696+ fluent::const_eval_validation_front_matter_invalid_value,
697+ [].into_iter(),
698+ )
693699 };
694700
695701 err.set_arg("front_matter", message);
@@ -729,8 +735,24 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
729735 PtrToUninhabited { ty, .. } | UninhabitedVal { ty } => {
730736 err.set_arg("ty", ty);
731737 }
732- ExpectedNonPtr { value }
733- | InvalidEnumTag { value }
738+ PointerAsInt { expected } | Uninit { expected } => {
739+ let msg = match expected {
740+ ExpectedKind::Reference => fluent::const_eval_validation_expected_ref,
741+ ExpectedKind::Box => fluent::const_eval_validation_expected_box,
742+ ExpectedKind::RawPtr => fluent::const_eval_validation_expected_raw_ptr,
743+ ExpectedKind::InitScalar => fluent::const_eval_validation_expected_init_scalar,
744+ ExpectedKind::Bool => fluent::const_eval_validation_expected_bool,
745+ ExpectedKind::Char => fluent::const_eval_validation_expected_char,
746+ ExpectedKind::Float => fluent::const_eval_validation_expected_float,
747+ ExpectedKind::Int => fluent::const_eval_validation_expected_int,
748+ ExpectedKind::FnPtr => fluent::const_eval_validation_expected_fn_ptr,
749+ ExpectedKind::EnumTag => fluent::const_eval_validation_expected_enum_tag,
750+ ExpectedKind::Str => fluent::const_eval_validation_expected_str,
751+ };
752+ let msg = handler.eagerly_translate_to_string(msg, [].into_iter());
753+ err.set_arg("expected", msg);
754+ }
755+ InvalidEnumTag { value }
734756 | InvalidVTablePtr { value }
735757 | InvalidBool { value }
736758 | InvalidChar { value }
@@ -758,15 +780,12 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
758780 | NullFnPtr
759781 | NeverVal
760782 | UnsafeCell
761- | UninitEnumTag
762- | UninitStr
763- | Uninit { .. }
764- | UninitVal
765783 | InvalidMetaSliceTooLarge { .. }
766784 | InvalidMetaTooLarge { .. }
767785 | DanglingPtrUseAfterFree { .. }
768786 | DanglingPtrOutOfBounds { .. }
769- | UninhabitedEnumTag => {}
787+ | UninhabitedEnumVariant
788+ | PartialPointer => {}
770789 }
771790 }
772791}
@@ -776,9 +795,9 @@ impl ReportErrorExt for UnsupportedOpInfo {
776795 use crate::fluent_generated::*;
777796 match self {
778797 UnsupportedOpInfo::Unsupported(s) => s.clone().into(),
779- UnsupportedOpInfo::PartialPointerOverwrite (_) => const_eval_partial_pointer_overwrite,
780- UnsupportedOpInfo::PartialPointerCopy (_) => const_eval_partial_pointer_copy,
781- UnsupportedOpInfo::ReadPointerAsBytes => const_eval_read_pointer_as_bytes ,
798+ UnsupportedOpInfo::OverwritePartialPointer (_) => const_eval_partial_pointer_overwrite,
799+ UnsupportedOpInfo::ReadPartialPointer (_) => const_eval_partial_pointer_copy,
800+ UnsupportedOpInfo::ReadPointerAsInt(_) => const_eval_read_pointer_as_int ,
782801 UnsupportedOpInfo::ThreadLocalStatic(_) => const_eval_thread_local_static,
783802 UnsupportedOpInfo::ReadExternStatic(_) => const_eval_read_extern_static,
784803 }
@@ -787,13 +806,16 @@ impl ReportErrorExt for UnsupportedOpInfo {
787806 use crate::fluent_generated::*;
788807
789808 use UnsupportedOpInfo::*;
790- if let ReadPointerAsBytes | PartialPointerOverwrite (_) | PartialPointerCopy (_) = self {
809+ if let ReadPointerAsInt(_) | OverwritePartialPointer (_) | ReadPartialPointer (_) = self {
791810 builder.help(const_eval_ptr_as_bytes_1);
792811 builder.help(const_eval_ptr_as_bytes_2);
793812 }
794813 match self {
795- Unsupported(_) | ReadPointerAsBytes => {}
796- PartialPointerOverwrite(ptr) | PartialPointerCopy(ptr) => {
814+ // `ReadPointerAsInt(Some(info))` is never printed anyway, it only serves as an error to
815+ // be further processed by validity checking which then turns it into something nice to
816+ // print. So it's not worth the effort of having diagnostics that can print the `info`.
817+ Unsupported(_) | ReadPointerAsInt(_) => {}
818+ OverwritePartialPointer(ptr) | ReadPartialPointer(ptr) => {
797819 builder.set_arg("ptr", ptr);
798820 }
799821 ThreadLocalStatic(did) | ReadExternStatic(did) => {
0 commit comments