@@ -22,7 +22,9 @@ use rustc_span::{BytePos, Pos, Span, Symbol};
22
22
use rustc_trait_selection:: traits:: SelectionContext ;
23
23
24
24
use super :: ConstCx ;
25
- use crate :: errors:: { NonConstOpErr , StaticAccessErr } ;
25
+ use crate :: errors:: {
26
+ NonConstOpErr , PanicNonStrErr , RawPtrComparisonErr , RawPtrToIntErr , StaticAccessErr ,
27
+ } ;
26
28
use crate :: util:: { call_kind, CallDesugaringKind , CallKind } ;
27
29
28
30
#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
@@ -642,10 +644,7 @@ impl<'tcx> NonConstOp<'tcx> for PanicNonStr {
642
644
ccx : & ConstCx < ' _ , ' tcx > ,
643
645
span : Span ,
644
646
) -> DiagnosticBuilder < ' tcx , ErrorGuaranteed > {
645
- ccx. tcx . sess . struct_span_err (
646
- span,
647
- "argument to `panic!()` in a const context must have type `&str`" ,
648
- )
647
+ ccx. tcx . sess . create_err ( PanicNonStrErr { span } )
649
648
}
650
649
}
651
650
@@ -660,15 +659,7 @@ impl<'tcx> NonConstOp<'tcx> for RawPtrComparison {
660
659
ccx : & ConstCx < ' _ , ' tcx > ,
661
660
span : Span ,
662
661
) -> DiagnosticBuilder < ' tcx , ErrorGuaranteed > {
663
- let mut err = ccx
664
- . tcx
665
- . sess
666
- . struct_span_err ( span, "pointers cannot be reliably compared during const eval" ) ;
667
- err. note (
668
- "see issue #53020 <https://github.com/rust-lang/rust/issues/53020> \
669
- for more information",
670
- ) ;
671
- err
662
+ ccx. tcx . sess . create_err ( RawPtrComparisonErr { span } )
672
663
}
673
664
}
674
665
@@ -704,15 +695,7 @@ impl<'tcx> NonConstOp<'tcx> for RawPtrToIntCast {
704
695
ccx : & ConstCx < ' _ , ' tcx > ,
705
696
span : Span ,
706
697
) -> DiagnosticBuilder < ' tcx , ErrorGuaranteed > {
707
- let mut err = ccx
708
- . tcx
709
- . sess
710
- . struct_span_err ( span, "pointers cannot be cast to integers during const eval" ) ;
711
- err. note ( "at compile-time, pointers do not have an integer value" ) ;
712
- err. note (
713
- "avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior" ,
714
- ) ;
715
- err
698
+ ccx. tcx . sess . create_err ( RawPtrToIntErr { span } )
716
699
}
717
700
}
718
701
0 commit comments