diff options
| author | Michael Goulet <michael@errs.io> | 2022-06-28 22:46:25 -0700 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2022-07-08 03:47:59 +0000 |
| commit | 584e5d4c4ff1e24c7cb32e2a7526b4f629728daf (patch) | |
| tree | fc76f3b07c03170f4479484f8788e568acc1663b /compiler/rustc_const_eval/src | |
| parent | c48f4828131d7d326b8a4a91ae9931736deda26f (diff) | |
| download | rust-584e5d4c4ff1e24c7cb32e2a7526b4f629728daf.tar.gz rust-584e5d4c4ff1e24c7cb32e2a7526b4f629728daf.zip | |
Migrate PanicNonStr, RawPtrComparison, RawPtrToInt diagnostics
Diffstat (limited to 'compiler/rustc_const_eval/src')
| -rw-r--r-- | compiler/rustc_const_eval/src/errors.rs | 24 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/transform/check_consts/ops.rs | 29 |
2 files changed, 30 insertions, 23 deletions
diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs index 3a498f84ec5..20382a81f14 100644 --- a/compiler/rustc_const_eval/src/errors.rs +++ b/compiler/rustc_const_eval/src/errors.rs @@ -39,3 +39,27 @@ pub(crate) struct StaticAccessErr { #[help(const_eval::teach_help)] pub teach: Option<()>, } + +#[derive(SessionDiagnostic)] +#[error(const_eval::raw_ptr_to_int)] +#[note] +#[note(const_eval::note2)] +pub(crate) struct RawPtrToIntErr { + #[primary_span] + pub span: Span, +} + +#[derive(SessionDiagnostic)] +#[error(const_eval::raw_ptr_comparison)] +#[note] +pub(crate) struct RawPtrComparisonErr { + #[primary_span] + pub span: Span, +} + +#[derive(SessionDiagnostic)] +#[error(const_eval::panic_non_str)] +pub(crate) struct PanicNonStrErr { + #[primary_span] + pub span: Span, +} diff --git a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs index d104fdd59c5..181dbacdc82 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs @@ -22,7 +22,9 @@ use rustc_span::{BytePos, Pos, Span, Symbol}; use rustc_trait_selection::traits::SelectionContext; use super::ConstCx; -use crate::errors::{NonConstOpErr, StaticAccessErr}; +use crate::errors::{ + NonConstOpErr, PanicNonStrErr, RawPtrComparisonErr, RawPtrToIntErr, StaticAccessErr, +}; use crate::util::{call_kind, CallDesugaringKind, CallKind}; #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -642,10 +644,7 @@ impl<'tcx> NonConstOp<'tcx> for PanicNonStr { ccx: &ConstCx<'_, 'tcx>, span: Span, ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { - ccx.tcx.sess.struct_span_err( - span, - "argument to `panic!()` in a const context must have type `&str`", - ) + ccx.tcx.sess.create_err(PanicNonStrErr { span }) } } @@ -660,15 +659,7 @@ impl<'tcx> NonConstOp<'tcx> for RawPtrComparison { ccx: &ConstCx<'_, 'tcx>, span: Span, ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { - let mut err = ccx - .tcx - .sess - .struct_span_err(span, "pointers cannot be reliably compared during const eval"); - err.note( - "see issue #53020 <https://github.com/rust-lang/rust/issues/53020> \ - for more information", - ); - err + ccx.tcx.sess.create_err(RawPtrComparisonErr { span }) } } @@ -704,15 +695,7 @@ impl<'tcx> NonConstOp<'tcx> for RawPtrToIntCast { ccx: &ConstCx<'_, 'tcx>, span: Span, ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { - let mut err = ccx - .tcx - .sess - .struct_span_err(span, "pointers cannot be cast to integers during const eval"); - err.note("at compile-time, pointers do not have an integer value"); - err.note( - "avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior", - ); - err + ccx.tcx.sess.create_err(RawPtrToIntErr { span }) } } |
