From 0c4513e8ed576050c677763eeb632afbba83dce1 Mon Sep 17 00:00:00 2001 From: Saleem Jaffer Date: Thu, 1 Aug 2019 09:49:01 +0530 Subject: [PATCH] code review fixes --- src/librustc/mir/interpret/mod.rs | 71 ++++++++++++---------- src/librustc_mir/interpret/eval_context.rs | 4 +- src/librustc_mir/transform/const_prop.rs | 8 +-- 3 files changed, 43 insertions(+), 40 deletions(-) diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs index 8feb04ffe88..f3ed4ffab7d 100644 --- a/src/librustc/mir/interpret/mod.rs +++ b/src/librustc/mir/interpret/mod.rs @@ -1,34 +1,14 @@ //! An interpreter for MIR used in CTFE and by miri #[macro_export] -macro_rules! throw_unsup { - ($($tt:tt)*) => { return Err(err_unsup!($($tt)*).into()) }; -} - -#[macro_export] -macro_rules! throw_inval { - ($($tt:tt)*) => { return Err(err_inval!($($tt)*).into()) }; -} - -#[macro_export] -macro_rules! throw_ub { +macro_rules! err_unsup { ($($tt:tt)*) => { - return Err($crate::mir::interpret::InterpError::UndefinedBehaviour( - $crate::mir::interpret::UndefinedBehaviourInfo::$($tt)* - ).into()) + $crate::mir::interpret::InterpError::Unsupported( + $crate::mir::interpret::UnsupportedOpInfo::$($tt)* + ) }; } -#[macro_export] -macro_rules! throw_panic { - ($($tt:tt)*) => { return Err(err_panic!($($tt)*).into()) }; -} - -#[macro_export] -macro_rules! throw_exhaust { - ($($tt:tt)*) => { return Err(err_exhaust!($($tt)*).into()) }; -} - #[macro_export] macro_rules! err_inval { ($($tt:tt)*) => { @@ -39,10 +19,19 @@ macro_rules! err_inval { } #[macro_export] -macro_rules! err_unsup { +macro_rules! err_ub { ($($tt:tt)*) => { - $crate::mir::interpret::InterpError::Unsupported( - $crate::mir::interpret::UnsupportedOpInfo::$($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)* ) }; } @@ -57,14 +46,34 @@ macro_rules! err_exhaust { } #[macro_export] -macro_rules! err_panic { +macro_rules! throw_unsup { + ($($tt:tt)*) => { return Err(err_unsup!($($tt)*).into()) }; +} + +#[macro_export] +macro_rules! throw_inval { + ($($tt:tt)*) => { return Err(err_inval!($($tt)*).into()) }; +} + +#[macro_export] +macro_rules! throw_ub { ($($tt:tt)*) => { - $crate::mir::interpret::InterpError::Panic( - $crate::mir::interpret::PanicInfo::$($tt)* - ) + return Err($crate::mir::interpret::InterpError::UndefinedBehaviour( + $crate::mir::interpret::UndefinedBehaviourInfo::$($tt)* + ).into()) }; } +#[macro_export] +macro_rules! throw_panic { + ($($tt:tt)*) => { return Err(err_panic!($($tt)*).into()) }; +} + +#[macro_export] +macro_rules! throw_exhaust { + ($($tt:tt)*) => { return Err(err_exhaust!($($tt)*).into()) }; +} + mod error; mod value; mod allocation; diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 7ab99976b40..f10d7fb9651 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -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()) } } diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 164a268004d..5783f53316c 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -259,12 +259,7 @@ fn use_ecx( 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 @@ fn use_ecx( None, ); } + _ => {}, } None }, -- 2.44.0