5 use crate::interpret::{ConstEvalErr, InterpErrorInfo, Machine};
6 #[derive(Clone, Debug)]
7 pub enum ConstEvalError {
12 impl<'tcx> Into<InterpErrorInfo<'tcx>> for ConstEvalError {
13 fn into(self) -> InterpErrorInfo<'tcx> {
14 err_unsup!(Unsupported(self.to_string())).into()
18 impl fmt::Display for ConstEvalError {
19 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20 use self::ConstEvalError::*;
22 NeedsRfc(ref msg) => {
23 write!(f, "\"{}\" needs an rfc before being allowed inside constants", msg)
25 ConstAccessesStatic => write!(f, "constant accesses static"),
30 impl Error for ConstEvalError {}
32 /// Turn an interpreter error into something to report to the user.
33 /// As a side-effect, if RUSTC_CTFE_BACKTRACE is set, this prints the backtrace.
34 /// Should be called only if the error is actually going to to be reported!
35 pub fn error_to_const_error<'mir, 'tcx, M: Machine<'mir, 'tcx>>(
36 ecx: &InterpCx<'mir, 'tcx, M>,
37 mut error: InterpErrorInfo<'tcx>,
38 ) -> ConstEvalErr<'tcx> {
39 error.print_backtrace();
40 let stacktrace = ecx.generate_stacktrace(None);
41 ConstEvalErr { error: error.kind, stacktrace, span: ecx.tcx.span }