Skip to content

Commit f7e9d2a

Browse files
Add an InfiniteLoop variant to EvalErrorKind
1 parent 0f1c61c commit f7e9d2a

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

src/librustc/ich/impls_ty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,8 @@ for ::mir::interpret::EvalErrorKind<'gcx, O> {
549549
RemainderByZero |
550550
DivisionByZero |
551551
GeneratorResumedAfterReturn |
552-
GeneratorResumedAfterPanic => {}
552+
GeneratorResumedAfterPanic |
553+
InfiniteLoop => {}
553554
ReferencedConstant(ref err) => err.hash_stable(hcx, hasher),
554555
MachineError(ref err) => err.hash_stable(hcx, hasher),
555556
FunctionPointerTyMismatch(a, b) => {

src/librustc/mir/interpret/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ pub enum EvalErrorKind<'tcx, O> {
264264
ReferencedConstant(Lrc<ConstEvalErr<'tcx>>),
265265
GeneratorResumedAfterReturn,
266266
GeneratorResumedAfterPanic,
267+
InfiniteLoop,
267268
}
268269

269270
pub type EvalResult<'tcx, T = ()> = Result<T, EvalError<'tcx>>;
@@ -398,6 +399,7 @@ impl<'tcx, O> EvalErrorKind<'tcx, O> {
398399
RemainderByZero => "attempt to calculate the remainder with a divisor of zero",
399400
GeneratorResumedAfterReturn => "generator resumed after completion",
400401
GeneratorResumedAfterPanic => "generator resumed after panicking",
402+
InfiniteLoop => "program will never terminate",
401403
}
402404
}
403405
}

src/librustc/ty/structural_impls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ impl<'a, 'tcx, O: Lift<'tcx>> Lift<'tcx> for interpret::EvalErrorKind<'a, O> {
587587
RemainderByZero => RemainderByZero,
588588
GeneratorResumedAfterReturn => GeneratorResumedAfterReturn,
589589
GeneratorResumedAfterPanic => GeneratorResumedAfterPanic,
590+
InfiniteLoop => InfiniteLoop,
590591
})
591592
}
592593
}

src/librustc_mir/interpret/eval_context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl<'a, 'mir, 'tcx, M> InfiniteLoopDetector<'a, 'mir, 'tcx, M>
180180
machine: &M,
181181
stack: &Vec<Frame<'mir, 'tcx>>,
182182
memory: &Memory<'a, 'mir, 'tcx, M>,
183-
) -> Result<(), (/*TODO*/)> {
183+
) -> EvalResult<'_, ()> {
184184
let snapshot = (machine, stack, memory);
185185

186186
let mut fx = FxHasher::default();
@@ -197,8 +197,8 @@ impl<'a, 'mir, 'tcx, M> InfiniteLoopDetector<'a, 'mir, 'tcx, M>
197197
return Ok(())
198198
}
199199

200-
// Second cycle,
201-
Err(())
200+
// Second cycle
201+
Err(EvalErrorKind::InfiniteLoop.into())
202202
}
203203
}
204204

0 commit comments

Comments
 (0)