Skip to content

Commit 1d808d1

Browse files
committed
When popping in CTFE, perform validation before jumping to next statement to have a better span for the error
1 parent 6b9b97b commit 1d808d1

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/librustc_mir/interpret/eval_context.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -492,23 +492,6 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
492492
let frame = self.stack.pop().expect(
493493
"tried to pop a stack frame, but there were none",
494494
);
495-
match frame.return_to_block {
496-
StackPopCleanup::Goto(block) => {
497-
self.goto_block(block)?;
498-
}
499-
StackPopCleanup::None { cleanup } => {
500-
if !cleanup {
501-
// Leak the locals. Also skip validation, this is only used by
502-
// static/const computation which does its own (stronger) final
503-
// validation.
504-
return Ok(());
505-
}
506-
}
507-
}
508-
// Deallocate all locals that are backed by an allocation.
509-
for local in frame.locals {
510-
self.deallocate_local(local)?;
511-
}
512495
// Validate the return value.
513496
if let Some(return_place) = frame.return_place {
514497
if M::enforce_validity(self) {
@@ -530,6 +513,22 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
530513
// Uh, that shouldn't happen... the function did not intend to return
531514
return err!(Unreachable);
532515
}
516+
// Jump to new block -- *after* validation so that the spans make more sense.
517+
match frame.return_to_block {
518+
StackPopCleanup::Goto(block) => {
519+
self.goto_block(block)?;
520+
}
521+
StackPopCleanup::None { cleanup } => {
522+
if !cleanup {
523+
// Leak the locals.
524+
return Ok(());
525+
}
526+
}
527+
}
528+
// Deallocate all locals that are backed by an allocation.
529+
for local in frame.locals {
530+
self.deallocate_local(local)?;
531+
}
533532

534533
if self.stack.len() > 1 { // FIXME should be "> 0", printing topmost frame crashes rustc...
535534
debug!("CONTINUING({}) {}", self.cur_frame(), self.frame().instance);

0 commit comments

Comments
 (0)