1
Fork 0

code review fixes

This commit is contained in:
Saleem Jaffer 2019-08-01 09:49:01 +05:30
parent c17d11fb39
commit 0c4513e8ed
3 changed files with 48 additions and 45 deletions

View file

@ -1,5 +1,50 @@
//! An interpreter for MIR used in CTFE and by miri
#[macro_export]
macro_rules! err_unsup {
($($tt:tt)*) => {
$crate::mir::interpret::InterpError::Unsupported(
$crate::mir::interpret::UnsupportedOpInfo::$($tt)*
)
};
}
#[macro_export]
macro_rules! err_inval {
($($tt:tt)*) => {
$crate::mir::interpret::InterpError::InvalidProgram(
$crate::mir::interpret::InvalidProgramInfo::$($tt)*
)
};
}
#[macro_export]
macro_rules! err_ub {
($($tt:tt)*) => {
$crate::mir::interpret::InterpError::UndefinedBehaviour(
$crate::mir::interpret::UndefinedBehaviourInfo::$($tt)*
)
};
}
#[macro_export]
macro_rules! err_panic {
($($tt:tt)*) => {
$crate::mir::interpret::InterpError::Panic(
$crate::mir::interpret::PanicInfo::$($tt)*
)
};
}
#[macro_export]
macro_rules! err_exhaust {
($($tt:tt)*) => {
$crate::mir::interpret::InterpError::ResourceExhaustion(
$crate::mir::interpret::ResourceExhaustionInfo::$($tt)*
)
};
}
#[macro_export]
macro_rules! throw_unsup {
($($tt:tt)*) => { return Err(err_unsup!($($tt)*).into()) };
@ -29,42 +74,6 @@ macro_rules! throw_exhaust {
($($tt:tt)*) => { return Err(err_exhaust!($($tt)*).into()) };
}
#[macro_export]
macro_rules! err_inval {
($($tt:tt)*) => {
$crate::mir::interpret::InterpError::InvalidProgram(
$crate::mir::interpret::InvalidProgramInfo::$($tt)*
)
};
}
#[macro_export]
macro_rules! err_unsup {
($($tt:tt)*) => {
$crate::mir::interpret::InterpError::Unsupported(
$crate::mir::interpret::UnsupportedOpInfo::$($tt)*
)
};
}
#[macro_export]
macro_rules! err_exhaust {
($($tt:tt)*) => {
$crate::mir::interpret::InterpError::ResourceExhaustion(
$crate::mir::interpret::ResourceExhaustionInfo::$($tt)*
)
};
}
#[macro_export]
macro_rules! err_panic {
($($tt:tt)*) => {
$crate::mir::interpret::InterpError::Panic(
$crate::mir::interpret::PanicInfo::$($tt)*
)
};
}
mod error;
mod value;
mod allocation;

View file

@ -191,9 +191,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf for InterpCx<'mir, 'tcx, M> {
fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
self.tcx
.layout_of(self.param_env.and(ty))
.map_err(|layout| {
err_inval!(Layout(layout)).into()
})
.map_err(|layout| err_inval!(Layout(layout)).into())
}
}

View file

@ -259,12 +259,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
use rustc::mir::interpret::InterpError::*;
match diagnostic.error {
Exit(_) => bug!("the CTFE program cannot exit"),
| Unsupported(_) => {},
| UndefinedBehaviour(_) => {},
| InvalidProgram(_) => {},
| ResourceExhaustion(_) => {},
| Panic(_)
=> {
Panic(_) => {
diagnostic.report_as_lint(
self.ecx.tcx,
"this expression will panic at runtime",
@ -272,6 +267,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
None,
);
}
_ => {},
}
None
},