Skip to content

Commit 9f22794

Browse files
committed
Simplify memory failure checking
1 parent ba542ee commit 9f22794

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

compiler/rustc_middle/src/mir/interpret/error.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,4 @@ impl InterpError<'_> {
535535
_ => false,
536536
}
537537
}
538-
539-
/// Did the error originate from volatile conditons such as the memory available to the
540-
/// interpreter?
541-
pub fn is_volatile(&self) -> bool {
542-
matches!(self, InterpError::ResourceExhaustion(ResourceExhaustionInfo::MemoryExhausted))
543-
}
544538
}

compiler/rustc_mir/src/transform/const_prop.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ use rustc_trait_selection::traits;
3131
use crate::const_eval::ConstEvalErr;
3232
use crate::interpret::{
3333
self, compile_time_machine, AllocId, Allocation, ConstValue, CtfeValidationMode, Frame, ImmTy,
34-
Immediate, InterpCx, InterpResult, LocalState, LocalValue, MemPlace, Memory, MemoryKind, OpTy,
35-
Operand as InterpOperand, PlaceTy, Pointer, Scalar, ScalarMaybeUninit, StackPopCleanup,
36-
StackPopUnwind,
34+
Immediate, InterpCx, InterpError, InterpResult, LocalState, LocalValue, MemPlace, Memory,
35+
MemoryKind, OpTy, Operand as InterpOperand, PlaceTy, Pointer, ResourceExhaustionInfo, Scalar,
36+
ScalarMaybeUninit, StackPopCleanup, StackPopUnwind,
3737
};
3838
use crate::transform::MirPass;
3939

@@ -478,19 +478,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
478478
Ok(op) => Some(op),
479479
Err(error) => {
480480
let tcx = self.ecx.tcx.at(c.span);
481-
if error.kind().is_volatile() {
482-
// Volatile errors can't be ignored since otherwise the amount of available
483-
// memory influences the result of optimization and the build. The error
484-
// doesn't need to be fatal since no code will actually be generated anyways.
485-
self.ecx
486-
.tcx
487-
.tcx
488-
.sess
489-
.struct_err("memory exhausted during optimization")
490-
.help("try increasing the amount of memory available to the compiler")
491-
.emit();
492-
return None;
493-
}
494481
let err = ConstEvalErr::new(&self.ecx, error, Some(c.span));
495482
if let Some(lint_root) = self.lint_root(source_info) {
496483
let lint_only = match c.literal {
@@ -507,7 +494,19 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
507494
},
508495
ConstantKind::Val(_, ty) => ty.needs_subst(),
509496
};
510-
if lint_only {
497+
// Memory errors can't be ignored since otherwise the amount of available
498+
// memory influences the result of optimization and the build. The error
499+
// doesn't need to be fatal since no code will actually be generated anyways.
500+
// FIXME(#86255): use err.error.is_hard_err(), but beware of backwards
501+
// compatibility and interactions with promoteds
502+
if lint_only
503+
&& !matches!(
504+
err.error,
505+
InterpError::ResourceExhaustion(
506+
ResourceExhaustionInfo::MemoryExhausted,
507+
),
508+
)
509+
{
511510
// Out of backwards compatibility we cannot report hard errors in unused
512511
// generic functions using associated constants of the generic parameters.
513512
err.report_as_lint(tcx, "erroneous constant used", lint_root, Some(c.span));

0 commit comments

Comments
 (0)