Skip to content

Commit d366ed2

Browse files
committed
abort() now takes a msg parameter
1 parent 4f9fd2a commit d366ed2

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

compiler/rustc_mir/src/const_eval/error.rs

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub enum ConstEvalErrKind {
2020
ModifiedGlobal,
2121
AssertFailure(AssertKind<ConstInt>),
2222
Panic { msg: Symbol, line: u32, col: u32, file: Symbol },
23+
Abort(String),
2324
}
2425

2526
// The errors become `MachineStop` with plain strings when being raised.
@@ -46,6 +47,7 @@ impl fmt::Display for ConstEvalErrKind {
4647
Panic { msg, line, col, file } => {
4748
write!(f, "the evaluated program panicked at '{}', {}:{}:{}", msg, file, line, col)
4849
}
50+
Abort(ref msg) => write!(f, "{}", msg)
4951
}
5052
}
5153
}

compiler/rustc_mir/src/interpret/intrinsics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
126126
None => match intrinsic_name {
127127
sym::transmute => throw_ub_format!("transmuting to uninhabited type"),
128128
sym::unreachable => throw_ub!(Unreachable),
129-
sym::abort => M::abort(self)?,
129+
sym::abort => M::abort(self, "aborted execution".to_owned())?,
130130
// Unsupported diverging intrinsic.
131131
_ => return Ok(false),
132132
},
@@ -412,7 +412,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
412412
let layout = self.layout_of(ty)?;
413413

414414
if layout.abi.is_uninhabited() {
415-
throw_ub_format!("attempted to instantiate uninhabited type `{}`", ty);
415+
M::abort(self, format!("attempted to instantiate uninhabited type `{}`", ty))?;
416416
}
417417
}
418418
sym::simd_insert => {

compiler/rustc_mir/src/interpret/machine.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,10 @@ pub trait Machine<'mir, 'tcx>: Sized {
176176
) -> InterpResult<'tcx>;
177177

178178
/// Called to evaluate `Abort` MIR terminator.
179-
fn abort(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx, !> {
180-
throw_unsup_format!("aborting execution is not supported")
179+
fn abort(_ecx: &mut InterpCx<'mir, 'tcx, Self>, msg: String) -> InterpResult<'tcx, !> {
180+
use crate::const_eval::ConstEvalErrKind;
181+
182+
Err(ConstEvalErrKind::Abort(msg).into())
181183
}
182184

183185
/// Called for all binary operations where the LHS has pointer type.

compiler/rustc_mir/src/interpret/terminator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
110110
}
111111

112112
Abort => {
113-
M::abort(self)?;
113+
M::abort(self, "aborted execution".to_owned())?;
114114
}
115115

116116
// When we encounter Resume, we've finished unwinding

0 commit comments

Comments
 (0)