diff options
| author | Smitty <me@smitop.com> | 2021-06-30 11:24:52 -0400 |
|---|---|---|
| committer | Smitty <me@smitop.com> | 2021-06-30 11:24:52 -0400 |
| commit | 9f227945f141deb0ae1540b0439cd8330d4df454 (patch) | |
| tree | 775a24627a9d886a6256d90f174c0fdb09773c34 | |
| parent | ba542eebc0f6f08a7275e0e0ed57f110bc3461f2 (diff) | |
| download | rust-9f227945f141deb0ae1540b0439cd8330d4df454.tar.gz rust-9f227945f141deb0ae1540b0439cd8330d4df454.zip | |
Simplify memory failure checking
| -rw-r--r-- | compiler/rustc_middle/src/mir/interpret/error.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_mir/src/transform/const_prop.rs | 33 |
2 files changed, 16 insertions, 23 deletions
diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs index e17017f7225..ab9239585c4 100644 --- a/compiler/rustc_middle/src/mir/interpret/error.rs +++ b/compiler/rustc_middle/src/mir/interpret/error.rs @@ -535,10 +535,4 @@ impl InterpError<'_> { _ => false, } } - - /// Did the error originate from volatile conditons such as the memory available to the - /// interpreter? - pub fn is_volatile(&self) -> bool { - matches!(self, InterpError::ResourceExhaustion(ResourceExhaustionInfo::MemoryExhausted)) - } } diff --git a/compiler/rustc_mir/src/transform/const_prop.rs b/compiler/rustc_mir/src/transform/const_prop.rs index 5ab6b334ed4..e7ab8c1e35c 100644 --- a/compiler/rustc_mir/src/transform/const_prop.rs +++ b/compiler/rustc_mir/src/transform/const_prop.rs @@ -31,9 +31,9 @@ use rustc_trait_selection::traits; use crate::const_eval::ConstEvalErr; use crate::interpret::{ self, compile_time_machine, AllocId, Allocation, ConstValue, CtfeValidationMode, Frame, ImmTy, - Immediate, InterpCx, InterpResult, LocalState, LocalValue, MemPlace, Memory, MemoryKind, OpTy, - Operand as InterpOperand, PlaceTy, Pointer, Scalar, ScalarMaybeUninit, StackPopCleanup, - StackPopUnwind, + Immediate, InterpCx, InterpError, InterpResult, LocalState, LocalValue, MemPlace, Memory, + MemoryKind, OpTy, Operand as InterpOperand, PlaceTy, Pointer, ResourceExhaustionInfo, Scalar, + ScalarMaybeUninit, StackPopCleanup, StackPopUnwind, }; use crate::transform::MirPass; @@ -478,19 +478,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { Ok(op) => Some(op), Err(error) => { let tcx = self.ecx.tcx.at(c.span); - if error.kind().is_volatile() { - // Volatile errors can't be ignored since otherwise the amount of available - // memory influences the result of optimization and the build. The error - // doesn't need to be fatal since no code will actually be generated anyways. - self.ecx - .tcx - .tcx - .sess - .struct_err("memory exhausted during optimization") - .help("try increasing the amount of memory available to the compiler") - .emit(); - return None; - } let err = ConstEvalErr::new(&self.ecx, error, Some(c.span)); if let Some(lint_root) = self.lint_root(source_info) { let lint_only = match c.literal { @@ -507,7 +494,19 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { }, ConstantKind::Val(_, ty) => ty.needs_subst(), }; - if lint_only { + // Memory errors can't be ignored since otherwise the amount of available + // memory influences the result of optimization and the build. The error + // doesn't need to be fatal since no code will actually be generated anyways. + // FIXME(#86255): use err.error.is_hard_err(), but beware of backwards + // compatibility and interactions with promoteds + if lint_only + && !matches!( + err.error, + InterpError::ResourceExhaustion( + ResourceExhaustionInfo::MemoryExhausted, + ), + ) + { // Out of backwards compatibility we cannot report hard errors in unused // generic functions using associated constants of the generic parameters. err.report_as_lint(tcx, "erroneous constant used", lint_root, Some(c.span)); |
