Skip to content

Commit 9f8b099

Browse files
committed
code review fixes
1 parent 03d47be commit 9f8b099

File tree

15 files changed

+57
-48
lines changed

15 files changed

+57
-48
lines changed

src/librustc/mir/interpret/error.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,12 @@ impl<O: fmt::Debug> fmt::Debug for PanicInfo<O> {
314314

315315
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
316316
pub enum InvalidProgramInfo<'tcx> {
317-
/// Resolution can fail if we are in a too generic context
317+
/// Resolution can fail if we are in a too generic context.
318318
TooGeneric,
319319
/// Cannot compute this constant because it depends on another one
320-
/// which already produced an error
320+
/// which already produced an error.
321321
ReferencedConstant,
322-
/// Abort in case type errors are reached
322+
/// Abort in case type errors are reached.
323323
TypeckError,
324324
/// An error occurred during layout computation.
325325
Layout(layout::LayoutError<'tcx>),
@@ -362,7 +362,7 @@ impl fmt::Debug for UndefinedBehaviourInfo {
362362
}
363363

364364
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
365-
pub enum UnsupportedInfo<'tcx> {
365+
pub enum UnsupportedOpInfo<'tcx> {
366366
/// Handle cases which for which we do not have a fixed variant.
367367
Unimplemented(String),
368368

@@ -426,9 +426,9 @@ pub enum UnsupportedInfo<'tcx> {
426426
PathNotFound(Vec<String>),
427427
}
428428

429-
impl fmt::Debug for UnsupportedInfo<'tcx> {
429+
impl fmt::Debug for UnsupportedOpInfo<'tcx> {
430430
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
431-
use UnsupportedInfo::*;
431+
use UnsupportedOpInfo::*;
432432
match self {
433433
PointerOutOfBounds { ptr, msg, allocation_size } => {
434434
write!(f, "{} failed: pointer must be in-bounds at offset {}, \
@@ -574,7 +574,7 @@ pub enum InterpError<'tcx> {
574574
UndefinedBehaviour(UndefinedBehaviourInfo),
575575
/// The program did something the interpreter does not support (some of these *might* be UB
576576
/// but the interpreter is not sure).
577-
Unsupported(UnsupportedInfo<'tcx>),
577+
Unsupported(UnsupportedOpInfo<'tcx>),
578578
/// The program was invalid (ill-typed, not sufficiently monomorphized, ...).
579579
InvalidProgram(InvalidProgramInfo<'tcx>),
580580
/// The program exhausted the interpreter's resources (stack/heap too big,

src/librustc/mir/interpret/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
macro_rules! err {
55
($($tt:tt)*) => {
66
Err($crate::mir::interpret::InterpError::Unsupported(
7-
$crate::mir::interpret::UnsupportedInfo::$($tt)*
7+
$crate::mir::interpret::UnsupportedOpInfo::$($tt)*
88
).into())
99
};
1010
}
@@ -52,7 +52,7 @@ mod pointer;
5252

5353
pub use self::error::{
5454
InterpErrorInfo, InterpResult, InterpError, AssertMessage, ConstEvalErr, struct_error,
55-
FrameInfo, ConstEvalRawResult, ConstEvalResult, ErrorHandled, PanicInfo, UnsupportedInfo,
55+
FrameInfo, ConstEvalRawResult, ConstEvalResult, ErrorHandled, PanicInfo, UnsupportedOpInfo,
5656
InvalidProgramInfo, ResourceExhaustionInfo, UndefinedBehaviourInfo,
5757
};
5858

src/librustc/mir/interpret/pointer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl<'tcx, Tag> Pointer<Tag> {
196196
msg: CheckInAllocMsg,
197197
) -> InterpResult<'tcx, ()> {
198198
if self.offset > allocation_size {
199-
err!(PointerOutOfBounds { ptr: self.erase_tag(),msg,allocation_size })
199+
err!(PointerOutOfBounds { ptr: self.erase_tag(), msg, allocation_size })
200200
} else {
201201
Ok(())
202202
}

src/librustc_mir/const_eval.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ use crate::interpret::{self,
2424
RawConst, ConstValue,
2525
InterpResult, InterpErrorInfo, InterpError, GlobalId, InterpCx, StackPopCleanup,
2626
Allocation, AllocId, MemoryKind,
27-
snapshot, RefTracking, intern_const_alloc_recursive, UnsupportedInfo::*,
28-
InvalidProgramInfo::*,
27+
snapshot, RefTracking, intern_const_alloc_recursive, UnsupportedOpInfo,
2928
};
3029

3130
/// Number of steps until the detector even starts doing anything.
@@ -184,7 +183,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
184183

185184
impl<'tcx> Into<InterpErrorInfo<'tcx>> for ConstEvalError {
186185
fn into(self) -> InterpErrorInfo<'tcx> {
187-
InterpError::Unsupported(MachineError(self.to_string())).into()
186+
InterpError::Unsupported(UnsupportedOpInfo::MachineError(self.to_string())).into()
188187
}
189188
}
190189

@@ -361,7 +360,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
361360
Ok(Some(match ecx.load_mir(instance.def) {
362361
Ok(body) => body,
363362
Err(err) => {
364-
if let InterpError::Unsupported(NoMirFor(ref path)) = err.kind {
363+
if let InterpError::Unsupported(UnsupportedOpInfo::NoMirFor(ref path)) = err.kind {
365364
return Err(
366365
ConstEvalError::NeedsRfc(format!("calling extern function `{}`", path))
367366
.into(),
@@ -698,6 +697,7 @@ pub fn const_eval_raw_provider<'tcx>(
698697
// promoting runtime code is only allowed to error if it references broken constants
699698
// any other kind of error will be reported to the user as a deny-by-default lint
700699
_ => if let Some(p) = cid.promoted {
700+
use crate::interpret::InvalidProgramInfo::*;
701701
let span = tcx.promoted_mir(def_id)[p].span;
702702
if let InterpError::InvalidProgram(ReferencedConstant) = err.error {
703703
err.report_as_error(

src/librustc_mir/interpret/cast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use rustc_apfloat::{Float, FloatConvert};
99
use rustc::mir::interpret::{
1010
Scalar, InterpResult, Pointer, PointerArithmetic, InterpError,
1111
};
12-
use rustc::mir::{CastKind, interpret::{InvalidProgramInfo::*}};
13-
12+
use rustc::mir::CastKind;
1413

1514
use super::{InterpCx, Machine, PlaceTy, OpTy, Immediate, FnVal};
1615

@@ -75,6 +74,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
7574
}
7675

7776
Pointer(PointerCast::ReifyFnPointer) => {
77+
use rustc::mir::interpret::InvalidProgramInfo::TooGeneric;
7878
// The src operand does not matter, just its type
7979
match src.layout.ty.sty {
8080
ty::FnDef(def_id, substs) => {

src/librustc_mir/interpret/eval_context.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc::mir::interpret::{
1717
ErrorHandled,
1818
GlobalId, Scalar, Pointer, FrameInfo, AllocId,
1919
InterpResult, InterpError,
20-
truncate, sign_extend, InvalidProgramInfo::*,
20+
truncate, sign_extend, InvalidProgramInfo,
2121
};
2222
use rustc_data_structures::fx::FxHashMap;
2323

@@ -190,8 +190,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf for InterpCx<'mir, 'tcx, M> {
190190

191191
#[inline]
192192
fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
193-
self.tcx.layout_of(self.param_env.and(ty))
194-
.map_err(|layout| InterpError::InvalidProgram(Layout(layout)).into())
193+
self.tcx
194+
.layout_of(self.param_env.and(ty))
195+
.map_err(|layout| {
196+
InterpError::InvalidProgram(InvalidProgramInfo::Layout(layout)).into()
197+
})
195198
}
196199
}
197200

@@ -302,7 +305,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
302305
&substs,
303306
)),
304307
None => if substs.needs_subst() {
305-
err_inval!(TooGeneric).into()
308+
err_inval!(TooGeneric)
306309
} else {
307310
Ok(substs)
308311
},
@@ -323,7 +326,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
323326
self.param_env,
324327
def_id,
325328
substs,
326-
).ok_or_else(|| InterpError::InvalidProgram(TooGeneric).into())
329+
).ok_or_else(|| InterpError::InvalidProgram(InvalidProgramInfo::TooGeneric).into())
327330
}
328331

329332
pub fn load_mir(
@@ -694,8 +697,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
694697
// `Memory::get_static_alloc` which has to use `const_eval_raw` to avoid cycles.
695698
let val = self.tcx.const_eval_raw(param_env.and(gid)).map_err(|err| {
696699
match err {
697-
ErrorHandled::Reported => InterpError::InvalidProgram(ReferencedConstant),
698-
ErrorHandled::TooGeneric => InterpError::InvalidProgram(TooGeneric),
700+
ErrorHandled::Reported =>
701+
InterpError::InvalidProgram(InvalidProgramInfo::ReferencedConstant),
702+
ErrorHandled::TooGeneric =>
703+
InterpError::InvalidProgram(InvalidProgramInfo::TooGeneric),
699704
}
700705
})?;
701706
self.raw_const_to_mplace(val)

src/librustc_mir/interpret/intern.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use rustc::ty::{Ty, TyCtxt, ParamEnv, self};
77
use rustc::mir::interpret::{
8-
InterpResult, ErrorHandled, UnsupportedInfo::*,
8+
InterpResult, ErrorHandled, UnsupportedOpInfo,
99
};
1010
use rustc::hir;
1111
use rustc::hir::def_id::DefId;
@@ -293,7 +293,7 @@ pub fn intern_const_alloc_recursive(
293293
if let Err(error) = interned {
294294
// This can happen when e.g. the tag of an enum is not a valid discriminant. We do have
295295
// to read enum discriminants in order to find references in enum variant fields.
296-
if let InterpError::Unsupported(ValidationFailure(_)) = error.kind {
296+
if let InterpError::Unsupported(UnsupportedOpInfo::ValidationFailure(_)) = error.kind {
297297
let err = crate::const_eval::error_to_const_error(&ecx, error);
298298
match err.struct_error(ecx.tcx, "it is undefined behavior to use this value") {
299299
Ok(mut diag) => {

src/librustc_mir/interpret/intrinsics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc::ty;
77
use rustc::ty::layout::{LayoutOf, Primitive, Size};
88
use rustc::mir::BinOp;
99
use rustc::mir::interpret::{
10-
InterpResult, InterpError, Scalar, PanicInfo, UnsupportedInfo::*,
10+
InterpResult, InterpError, Scalar, PanicInfo, UnsupportedOpInfo,
1111
};
1212

1313
use super::{
@@ -100,7 +100,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
100100
let bits = self.read_scalar(args[0])?.to_bits(layout_of.size)?;
101101
let kind = match layout_of.abi {
102102
ty::layout::Abi::Scalar(ref scalar) => scalar.value,
103-
_ => Err(InterpError::Unsupported(TypeNotPrimitive(ty)))?,
103+
_ => Err(InterpError::Unsupported(UnsupportedOpInfo::TypeNotPrimitive(ty)))?,
104104
};
105105
let out_val = if intrinsic_name.ends_with("_nonzero") {
106106
if bits == 0 {

src/librustc_mir/interpret/machine.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc::ty::{self, TyCtxt};
1111

1212
use super::{
1313
Allocation, AllocId, InterpResult, InterpError, Scalar, AllocationExtra,
14-
InterpCx, PlaceTy, OpTy, ImmTy, MemoryKind, Pointer, Memory, UnsupportedInfo::*
14+
InterpCx, PlaceTy, OpTy, ImmTy, MemoryKind, Pointer, Memory, UnsupportedOpInfo,
1515
};
1616

1717
/// Whether this kind of memory is allowed to leak
@@ -240,9 +240,9 @@ pub trait Machine<'mir, 'tcx>: Sized {
240240
int: u64,
241241
) -> InterpResult<'tcx, Pointer<Self::PointerTag>> {
242242
Err((if int == 0 {
243-
InterpError::Unsupported(InvalidNullPointerUsage)
243+
InterpError::Unsupported(UnsupportedOpInfo::InvalidNullPointerUsage)
244244
} else {
245-
InterpError::Unsupported(ReadBytesAsPointer)
245+
InterpError::Unsupported(UnsupportedOpInfo::ReadBytesAsPointer)
246246
}).into())
247247
}
248248

src/librustc_mir/interpret/memory.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ use syntax::ast::Mutability;
1919
use super::{
2020
Pointer, AllocId, Allocation, GlobalId, AllocationExtra,
2121
InterpResult, Scalar, InterpError, GlobalAlloc, PointerArithmetic,
22-
Machine, AllocMap, MayLeak, ErrorHandled, CheckInAllocMsg, UnsupportedInfo::*,
23-
InvalidProgramInfo::*
22+
Machine, AllocMap, MayLeak, ErrorHandled, CheckInAllocMsg, InvalidProgramInfo,
2423
};
2524

2625
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
@@ -438,9 +437,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
438437
assert!(tcx.is_static(def_id));
439438
match err {
440439
ErrorHandled::Reported =>
441-
InterpError::InvalidProgram(ReferencedConstant),
440+
InterpError::InvalidProgram(
441+
InvalidProgramInfo::ReferencedConstant
442+
),
442443
ErrorHandled::TooGeneric =>
443-
InterpError::InvalidProgram(TooGeneric),
444+
InterpError::InvalidProgram(InvalidProgramInfo::TooGeneric),
444445
}
445446
})?;
446447
// Make sure we use the ID of the resolved memory, not the lazy one!
@@ -590,7 +591,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
590591
} else {
591592
match self.tcx.alloc_map.lock().get(id) {
592593
Some(GlobalAlloc::Function(instance)) => Ok(FnVal::Instance(instance)),
593-
_ => Err(InterpError::Unsupported(ExecuteMemory).into()),
594+
_ => err!(ExecuteMemory),
594595
}
595596
}
596597
}

0 commit comments

Comments
 (0)