Skip to content

Commit 2a33fbf

Browse files
committed
addding an interp_error module
1 parent 9620521 commit 2a33fbf

File tree

7 files changed

+30
-11
lines changed

7 files changed

+30
-11
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! macros to do something like `.ok_or_else(|| inval!(TooGeneric).into())` rather than
2+
//! `.ok_or_else(|| InterpError::InvalidProgram(TooGeneric).into())`
3+
4+
#[macro_export]
5+
macro_rules! inval {
6+
($($tt:tt)*) => {
7+
$crate::mir::interpret::InterpError::InvalidProgram(
8+
$crate::mir::interpret::InvalidProgramInfo::$($tt)*
9+
)
10+
};
11+
}
12+
13+
#[macro_export]
14+
macro_rules! unsup {
15+
($($tt:tt)*) => {
16+
$crate::mir::interpret::InterpError::Unsupported(
17+
$crate::mir::interpret::UnsupportedOpInfo::$($tt)*
18+
)
19+
};
20+
}

src/librustc/mir/interpret/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ mod error;
4949
mod value;
5050
mod allocation;
5151
mod pointer;
52+
mod interp_error;
5253

5354
pub use self::error::{
5455
InterpErrorInfo, InterpResult, InterpError, AssertMessage, ConstEvalErr, struct_error,

src/librustc_mir/interpret/cast.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use syntax::symbol::sym;
77
use rustc_apfloat::ieee::{Single, Double};
88
use rustc_apfloat::{Float, FloatConvert};
99
use rustc::mir::interpret::{
10-
Scalar, InterpResult, Pointer, PointerArithmetic, InterpError,
10+
Scalar, InterpResult, Pointer, PointerArithmetic,
1111
};
1212
use rustc::mir::CastKind;
1313

@@ -74,7 +74,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
7474
}
7575

7676
Pointer(PointerCast::ReifyFnPointer) => {
77-
use rustc::mir::interpret::InvalidProgramInfo::TooGeneric;
7877
// The src operand does not matter, just its type
7978
match src.layout.ty.sty {
8079
ty::FnDef(def_id, substs) => {
@@ -86,7 +85,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
8685
self.param_env,
8786
def_id,
8887
substs,
89-
).ok_or_else(|| InterpError::InvalidProgram(TooGeneric).into());
88+
).ok_or_else(|| inval!(TooGeneric).into());
9089
let fn_ptr = self.memory.create_fn_alloc(FnVal::Instance(instance?));
9190
self.write_scalar(Scalar::Ptr(fn_ptr.into()), dest)?;
9291
}

src/librustc_mir/interpret/eval_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
326326
self.param_env,
327327
def_id,
328328
substs,
329-
).ok_or_else(|| InterpError::InvalidProgram(InvalidProgramInfo::TooGeneric).into())
329+
).ok_or_else(|| inval!(TooGeneric).into())
330330
}
331331

332332
pub fn load_mir(

src/librustc_mir/interpret/operand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
637637
.find(|(_, var)| var.val == real_discr),
638638
_ => bug!("tagged layout for non-adt non-generator"),
639639
}.ok_or_else(
640-
|| InterpError::Unsupported(InvalidDiscriminant(raw_discr.erase_tag()))
640+
|| unsup!(InvalidDiscriminant(raw_discr.erase_tag()))
641641
)?;
642642
(real_discr, index.0)
643643
},

src/librustc_mir/interpret/terminator.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ use syntax::source_map::Span;
77
use rustc_target::spec::abi::Abi;
88

99
use super::{
10-
InterpResult, PointerArithmetic, InterpError, Scalar,
10+
InterpResult, PointerArithmetic, Scalar,
1111
InterpCx, Machine, Immediate, OpTy, ImmTy, PlaceTy, MPlaceTy, StackPopCleanup, FnVal,
12-
UnsupportedOpInfo,
1312
};
1413

1514
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
@@ -221,7 +220,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
221220
return Ok(());
222221
}
223222
let caller_arg = caller_arg.next()
224-
.ok_or_else(|| InterpError::Unsupported(UnsupportedOpInfo::FunctionArgCountMismatch))?;
223+
.ok_or_else(|| unsup!(FunctionArgCountMismatch)) ?;
225224
if rust_abi {
226225
debug_assert!(!caller_arg.layout.is_zst(), "ZSTs must have been already filtered out");
227226
}

src/librustc_mir/interpret/traits.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use rustc::ty::{self, Ty, Instance};
22
use rustc::ty::layout::{Size, Align, LayoutOf};
3-
use rustc::mir::interpret::{Scalar, Pointer, InterpResult, PointerArithmetic, InvalidProgramInfo};
3+
use rustc::mir::interpret::{Scalar, Pointer, InterpResult, PointerArithmetic,};
44

5-
use super::{InterpCx, InterpError, Machine, MemoryKind, FnVal};
5+
use super::{InterpCx, Machine, MemoryKind, FnVal};
66

77
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
88
/// Creates a dynamic vtable for the given type and vtable origin. This is used only for
@@ -83,7 +83,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
8383
self.param_env,
8484
def_id,
8585
substs,
86-
).ok_or_else(|| InterpError::InvalidProgram(InvalidProgramInfo::TooGeneric))?;
86+
).ok_or_else(|| inval!(TooGeneric))?;
8787
let fn_ptr = self.memory.create_fn_alloc(FnVal::Instance(instance));
8888
let method_ptr = vtable.offset(ptr_size * (3 + i as u64), self)?;
8989
self.memory

0 commit comments

Comments
 (0)