@@ -513,7 +513,7 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
513
513
ScalarSizeMismatch ( _) => const_eval_scalar_size_mismatch,
514
514
UninhabitedEnumVariantWritten ( _) => const_eval_uninhabited_enum_variant_written,
515
515
UninhabitedEnumVariantRead ( _) => const_eval_uninhabited_enum_variant_read,
516
- Validation ( e) => e. diagnostic_message ( ) ,
516
+ ValidationError ( e) => e. diagnostic_message ( ) ,
517
517
Custom ( x) => ( x. msg ) ( ) ,
518
518
}
519
519
}
@@ -587,13 +587,13 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
587
587
InvalidUninitBytes ( Some ( ( alloc, info) ) ) => {
588
588
builder. set_arg ( "alloc" , alloc) ;
589
589
builder. set_arg ( "access" , info. access ) ;
590
- builder. set_arg ( "uninit" , info. uninit ) ;
590
+ builder. set_arg ( "uninit" , info. bad ) ;
591
591
}
592
592
ScalarSizeMismatch ( info) => {
593
593
builder. set_arg ( "target_size" , info. target_size ) ;
594
594
builder. set_arg ( "data_size" , info. data_size ) ;
595
595
}
596
- Validation ( e) => e. add_args ( handler, builder) ,
596
+ ValidationError ( e) => e. add_args ( handler, builder) ,
597
597
Custom ( custom) => {
598
598
( custom. add_args ) ( & mut |name, value| {
599
599
builder. set_arg ( name, value) ;
@@ -608,88 +608,94 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
608
608
use crate :: fluent_generated:: * ;
609
609
use rustc_middle:: mir:: interpret:: ValidationErrorKind :: * ;
610
610
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,
644
638
InvalidMetaSliceTooLarge { ptr_kind : PointerKind :: Box } => {
645
- const_eval_invalid_box_slice_meta
639
+ const_eval_validation_invalid_box_slice_meta
646
640
}
647
641
InvalidMetaSliceTooLarge { ptr_kind : PointerKind :: Ref } => {
648
- const_eval_invalid_ref_slice_meta
642
+ const_eval_validation_invalid_ref_slice_meta
649
643
}
650
644
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,
655
653
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 ,
658
656
DanglingPtrNoProvenance { ptr_kind : PointerKind :: Box , .. } => {
659
- const_eval_dangling_box_no_provenance
657
+ const_eval_validation_dangling_box_no_provenance
660
658
}
661
659
DanglingPtrNoProvenance { ptr_kind : PointerKind :: Ref , .. } => {
662
- const_eval_dangling_ref_no_provenance
660
+ const_eval_validation_dangling_ref_no_provenance
663
661
}
664
662
DanglingPtrOutOfBounds { ptr_kind : PointerKind :: Box } => {
665
- const_eval_dangling_box_out_of_bounds
663
+ const_eval_validation_dangling_box_out_of_bounds
666
664
}
667
665
DanglingPtrOutOfBounds { ptr_kind : PointerKind :: Ref } => {
668
- const_eval_dangling_ref_out_of_bounds
666
+ const_eval_validation_dangling_ref_out_of_bounds
669
667
}
670
668
DanglingPtrUseAfterFree { ptr_kind : PointerKind :: Box } => {
671
- const_eval_dangling_box_use_after_free
669
+ const_eval_validation_dangling_box_use_after_free
672
670
}
673
671
DanglingPtrUseAfterFree { ptr_kind : PointerKind :: Ref } => {
674
- const_eval_dangling_ref_use_after_free
672
+ const_eval_validation_dangling_ref_use_after_free
675
673
}
676
674
InvalidBool { .. } => const_eval_validation_invalid_bool,
677
675
InvalidChar { .. } => const_eval_validation_invalid_char,
678
- InvalidFnPtr { .. } => const_eval_invalid_fn_ptr ,
676
+ InvalidFnPtr { .. } => const_eval_validation_invalid_fn_ptr ,
679
677
}
680
678
}
681
679
682
680
fn add_args < G : EmissionGuarantee > ( self , handler : & Handler , err : & mut DiagnosticBuilder < ' _ , G > ) {
683
681
use crate :: fluent_generated as fluent;
684
682
use rustc_middle:: mir:: interpret:: ValidationErrorKind :: * ;
685
683
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
+
686
689
let message = if let Some ( path) = self . path {
687
690
handler. eagerly_translate_to_string (
688
- fluent:: const_eval_invalid_value_with_path ,
691
+ fluent:: const_eval_validation_front_matter_invalid_value_with_path ,
689
692
[ ( "path" . into ( ) , DiagnosticArgValue :: Str ( path. into ( ) ) ) ] . iter ( ) . map ( |( a, b) | ( a, b) ) ,
690
693
)
691
694
} 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
+ )
693
699
} ;
694
700
695
701
err. set_arg ( "front_matter" , message) ;
@@ -729,8 +735,24 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
729
735
PtrToUninhabited { ty, .. } | UninhabitedVal { ty } => {
730
736
err. set_arg ( "ty" , ty) ;
731
737
}
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 }
734
756
| InvalidVTablePtr { value }
735
757
| InvalidBool { value }
736
758
| InvalidChar { value }
@@ -758,15 +780,12 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
758
780
| NullFnPtr
759
781
| NeverVal
760
782
| UnsafeCell
761
- | UninitEnumTag
762
- | UninitStr
763
- | Uninit { .. }
764
- | UninitVal
765
783
| InvalidMetaSliceTooLarge { .. }
766
784
| InvalidMetaTooLarge { .. }
767
785
| DanglingPtrUseAfterFree { .. }
768
786
| DanglingPtrOutOfBounds { .. }
769
- | UninhabitedEnumTag => { }
787
+ | UninhabitedEnumVariant
788
+ | PartialPointer => { }
770
789
}
771
790
}
772
791
}
@@ -776,9 +795,9 @@ impl ReportErrorExt for UnsupportedOpInfo {
776
795
use crate :: fluent_generated:: * ;
777
796
match self {
778
797
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 ,
782
801
UnsupportedOpInfo :: ThreadLocalStatic ( _) => const_eval_thread_local_static,
783
802
UnsupportedOpInfo :: ReadExternStatic ( _) => const_eval_read_extern_static,
784
803
}
@@ -787,13 +806,16 @@ impl ReportErrorExt for UnsupportedOpInfo {
787
806
use crate :: fluent_generated:: * ;
788
807
789
808
use UnsupportedOpInfo :: * ;
790
- if let ReadPointerAsBytes | PartialPointerOverwrite ( _) | PartialPointerCopy ( _) = self {
809
+ if let ReadPointerAsInt ( _ ) | OverwritePartialPointer ( _) | ReadPartialPointer ( _) = self {
791
810
builder. help ( const_eval_ptr_as_bytes_1) ;
792
811
builder. help ( const_eval_ptr_as_bytes_2) ;
793
812
}
794
813
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) => {
797
819
builder. set_arg ( "ptr" , ptr) ;
798
820
}
799
821
ThreadLocalStatic ( did) | ReadExternStatic ( did) => {
0 commit comments