diff options
| author | Smitty <me@smitop.com> | 2021-06-15 19:16:10 -0400 |
|---|---|---|
| committer | Smitty <me@smitop.com> | 2021-06-15 19:16:10 -0400 |
| commit | 4fe4ff95f6c459d98c2449c9993e0f7e0b8c47d3 (patch) | |
| tree | 50d71e1f2f95ac40297f3a0c4d0563cc0cfdb4e1 /compiler/rustc_mir | |
| parent | 60f1a2fc4b535ead9c85ce085fdce49b1b097531 (diff) | |
| download | rust-4fe4ff95f6c459d98c2449c9993e0f7e0b8c47d3.tar.gz rust-4fe4ff95f6c459d98c2449c9993e0f7e0b8c47d3.zip | |
Use better error message for hard errors in CTFE
Currently the same message is used for hard errors and soft errors. This makes hard errors use a message that indicates the reality of the situation correctly, since usage of the constant is never allowed when there was a hard error evaluating it.
Diffstat (limited to 'compiler/rustc_mir')
| -rw-r--r-- | compiler/rustc_mir/src/const_eval/error.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_mir/src/const_eval/eval_queries.rs | 5 |
2 files changed, 4 insertions, 9 deletions
diff --git a/compiler/rustc_mir/src/const_eval/error.rs b/compiler/rustc_mir/src/const_eval/error.rs index fc21047ab72..17e8ab2a4da 100644 --- a/compiler/rustc_mir/src/const_eval/error.rs +++ b/compiler/rustc_mir/src/const_eval/error.rs @@ -157,7 +157,7 @@ impl<'tcx> ConstEvalErr<'tcx> { tcx: TyCtxtAt<'tcx>, message: &str, emit: impl FnOnce(DiagnosticBuilder<'_>), - mut lint_root: Option<hir::HirId>, + lint_root: Option<hir::HirId>, ) -> ErrorHandled { let finish = |mut err: DiagnosticBuilder<'_>, span_msg: Option<String>| { trace!("reporting const eval failure at {:?}", self.span); @@ -194,12 +194,6 @@ impl<'tcx> ConstEvalErr<'tcx> { _ => {} }; - // If we have a 'hard error', then set `lint_root` to `None` so that we don't - // emit a lint. - if matches!(&self.error, InterpError::MachineStop(err) if err.is_hard_err()) { - lint_root = None; - } - let err_msg = self.error.to_string(); // Regular case - emit a lint. diff --git a/compiler/rustc_mir/src/const_eval/eval_queries.rs b/compiler/rustc_mir/src/const_eval/eval_queries.rs index 460fea37461..6adb6e34958 100644 --- a/compiler/rustc_mir/src/const_eval/eval_queries.rs +++ b/compiler/rustc_mir/src/const_eval/eval_queries.rs @@ -2,8 +2,8 @@ use super::{CompileTimeEvalContext, CompileTimeInterpreter, ConstEvalErr, Memory use crate::interpret::eval_nullary_intrinsic; use crate::interpret::{ intern_const_alloc_recursive, Allocation, ConstAlloc, ConstValue, CtfeValidationMode, GlobalId, - Immediate, InternKind, InterpCx, InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking, Scalar, - ScalarMaybeUninit, StackPopCleanup, + Immediate, InternKind, InterpCx, InterpError, InterpResult, MPlaceTy, MemoryKind, OpTy, + RefTracking, Scalar, ScalarMaybeUninit, StackPopCleanup, }; use crate::util::pretty::display_allocation; @@ -315,6 +315,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>( let emit_as_lint = if let Some(def) = def.as_local() { // (Associated) consts only emit a lint, since they might be unused. matches!(tcx.def_kind(def.did.to_def_id()), DefKind::Const | DefKind::AssocConst) + && !matches!(&err.error, InterpError::MachineStop(err) if err.is_hard_err()) } else { // use of broken constant from other crate: always an error false |
