diff options
| author | Smitty <me@smitop.com> | 2021-06-16 18:23:34 -0400 |
|---|---|---|
| committer | Smitty <me@smitop.com> | 2021-06-16 18:23:34 -0400 |
| commit | 044b3620e7f3d495e859113ecc6aa55e37ddc228 (patch) | |
| tree | b1950166e3c085757ee4cc013a3db8b79b31da99 | |
| parent | 4fe4ff95f6c459d98c2449c9993e0f7e0b8c47d3 (diff) | |
| download | rust-044b3620e7f3d495e859113ecc6aa55e37ddc228.tar.gz rust-044b3620e7f3d495e859113ecc6aa55e37ddc228.zip | |
Move some hard error logic to InterpError
| -rw-r--r-- | compiler/rustc_middle/src/mir/interpret/error.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_mir/src/const_eval/eval_queries.rs | 32 |
2 files changed, 27 insertions, 15 deletions
diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs index 65d9c1dd90e..cce360713b5 100644 --- a/compiler/rustc_middle/src/mir/interpret/error.rs +++ b/compiler/rustc_middle/src/mir/interpret/error.rs @@ -502,4 +502,14 @@ impl InterpError<'_> { _ => false, } } + + /// Should this error be reported as a hard error, preventing compilation, or a soft error, + /// causing a deny-by-default lint? + pub fn is_hard_err(&self) -> bool { + use InterpError::*; + match *self { + MachineStop(ref err) => err.is_hard_err(), + _ => false, + } + } } diff --git a/compiler/rustc_mir/src/const_eval/eval_queries.rs b/compiler/rustc_mir/src/const_eval/eval_queries.rs index 6adb6e34958..536dbad4f76 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, InterpError, InterpResult, MPlaceTy, MemoryKind, OpTy, - RefTracking, Scalar, ScalarMaybeUninit, StackPopCleanup, + Immediate, InternKind, InterpCx, InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking, Scalar, + ScalarMaybeUninit, StackPopCleanup, }; use crate::util::pretty::display_allocation; @@ -312,23 +312,17 @@ pub fn eval_to_allocation_raw_provider<'tcx>( let err = ConstEvalErr::new(&ecx, error, None); // Some CTFE errors raise just a lint, not a hard error; see // <https://github.com/rust-lang/rust/issues/71800>. - let emit_as_lint = if let Some(def) = def.as_local() { + let is_hard_err = 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()) + !matches!(tcx.def_kind(def.did.to_def_id()), DefKind::Const | DefKind::AssocConst) + // check if the inner InterpError is hard + || err.error.is_hard_err() } else { // use of broken constant from other crate: always an error - false + true }; - if emit_as_lint { - let hir_id = tcx.hir().local_def_id_to_hir_id(def.as_local().unwrap().did); - Err(err.report_as_lint( - tcx.at(tcx.def_span(def.did)), - "any use of this value will cause an error", - hir_id, - Some(err.span), - )) - } else { + + if is_hard_err { let msg = if is_static { Cow::from("could not evaluate static initializer") } else { @@ -346,6 +340,14 @@ pub fn eval_to_allocation_raw_provider<'tcx>( }; Err(err.report_as_error(ecx.tcx.at(ecx.cur_span()), &msg)) + } else { + let hir_id = tcx.hir().local_def_id_to_hir_id(def.as_local().unwrap().did); + Err(err.report_as_lint( + tcx.at(tcx.def_span(def.did)), + "any use of this value will cause an error", + hir_id, + Some(err.span), + )) } } Ok(mplace) => { |
