replace all unreachable! and panic! calls with bug!

This commit is contained in:
Oliver Schneider
2016-09-06 16:16:49 +02:00
parent cd42bb97f0
commit cd91f9feee
5 changed files with 39 additions and 43 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ fn build_controller(
fn extract_str(lit: &syntax::ast::Lit) -> syntax::parse::token::InternedString {
match lit.node {
syntax::ast::LitKind::Str(ref s, _) => s.clone(),
_ => panic!("attribute values need to be strings"),
_ => bug!("attribute values need to be strings"),
}
}
for attr in krate.attrs.iter() {
+22 -26
View File
@@ -187,9 +187,9 @@ macro_rules! i2p {
self.memory.write_f64(ptr, f)?;
Ok(ptr)
},
Float(ConstFloat::FInfer{..}) => unreachable!(),
Integral(ConstInt::Infer(_)) => unreachable!(),
Integral(ConstInt::InferSigned(_)) => unreachable!(),
Float(ConstFloat::FInfer{..}) |
Integral(ConstInt::Infer(_)) |
Integral(ConstInt::InferSigned(_)) => bug!("uninferred constants only exist before typeck"),
Integral(ConstInt::I8(i)) => i2p!(i, 1),
Integral(ConstInt::U8(i)) => i2p!(i, 1),
Integral(ConstInt::Isize(ConstIsize::Is16(i))) |
@@ -255,7 +255,7 @@ pub fn load_mir(&self, def_id: DefId) -> CachedMir<'a, 'tcx> {
let cs = &self.tcx.sess.cstore;
let mir = cs.maybe_get_item_mir(self.tcx, def_id).unwrap_or_else(|| {
panic!("no mir for `{}`", self.tcx.item_path_str(def_id));
bug!("no mir for `{}`", self.tcx.item_path_str(def_id));
});
let cached = Rc::new(mir);
mir_cache.insert(def_id, cached.clone());
@@ -359,7 +359,7 @@ fn intrinsic_with_overflow(
use rustc::ty::layout::Layout::*;
let tup_layout = match *dest_layout {
Univariant { ref variant, .. } => variant,
_ => panic!("checked bin op returns something other than a tuple"),
_ => bug!("checked bin op returns something other than a tuple"),
};
let overflowed = self.intrinsic_overflowing(op, left, right, dest)?;
@@ -446,8 +446,7 @@ fn eval_assignment(&mut self, lvalue: &mir::Lvalue<'tcx>, rvalue: &mir::Rvalue<'
Array { .. } => {
let elem_size = match dest_ty.sty {
ty::TyArray(elem_ty, _) => self.type_size(elem_ty) as u64,
_ => panic!("tried to assign {:?} to non-array type {:?}",
kind, dest_ty),
_ => bug!("tried to assign {:?} to non-array type {:?}", kind, dest_ty),
};
let offsets = (0..).map(|i| i * elem_size);
self.assign_fields(dest, offsets, operands)?;
@@ -463,7 +462,7 @@ fn eval_assignment(&mut self, lvalue: &mir::Lvalue<'tcx>, rvalue: &mir::Rvalue<'
.map(|s| s.bytes());
self.assign_fields(dest, offsets, operands)?;
} else {
panic!("tried to assign {:?} to Layout::General", kind);
bug!("tried to assign {:?} to Layout::General", kind);
}
}
@@ -480,7 +479,7 @@ fn eval_assignment(&mut self, lvalue: &mir::Lvalue<'tcx>, rvalue: &mir::Rvalue<'
self.memory.write_isize(dest, 0)?;
}
} else {
panic!("tried to assign {:?} to Layout::RawNullablePointer", kind);
bug!("tried to assign {:?} to Layout::RawNullablePointer", kind);
}
}
@@ -497,7 +496,7 @@ fn eval_assignment(&mut self, lvalue: &mir::Lvalue<'tcx>, rvalue: &mir::Rvalue<'
try!(self.memory.write_isize(dest, 0));
}
} else {
panic!("tried to assign {:?} to Layout::RawNullablePointer", kind);
bug!("tried to assign {:?} to Layout::RawNullablePointer", kind);
}
}
@@ -513,7 +512,7 @@ fn eval_assignment(&mut self, lvalue: &mir::Lvalue<'tcx>, rvalue: &mir::Rvalue<'
self.memory.write_uint(dest, val, size)?;
}
} else {
panic!("tried to assign {:?} to Layout::CEnum", kind);
bug!("tried to assign {:?} to Layout::CEnum", kind);
}
}
@@ -524,7 +523,7 @@ fn eval_assignment(&mut self, lvalue: &mir::Lvalue<'tcx>, rvalue: &mir::Rvalue<'
Repeat(ref operand, _) => {
let (elem_size, elem_align, length) = match dest_ty.sty {
ty::TyArray(elem_ty, n) => (self.type_size(elem_ty), self.type_align(elem_ty), n),
_ => panic!("tried to assign array-repeat to non-array type {:?}", dest_ty),
_ => bug!("tried to assign array-repeat to non-array type {:?}", dest_ty),
};
let src = self.eval_operand(operand)?;
@@ -542,9 +541,9 @@ fn eval_assignment(&mut self, lvalue: &mir::Lvalue<'tcx>, rvalue: &mir::Rvalue<'
ty::TySlice(_) => if let LvalueExtra::Length(n) = src.extra {
n
} else {
panic!("Rvalue::Len of a slice given non-slice pointer: {:?}", src);
bug!("Rvalue::Len of a slice given non-slice pointer: {:?}", src);
},
_ => panic!("Rvalue::Len expected array or slice, got {:?}", ty),
_ => bug!("Rvalue::Len expected array or slice, got {:?}", ty),
};
self.memory.write_usize(dest, len)?;
}
@@ -559,7 +558,7 @@ fn eval_assignment(&mut self, lvalue: &mir::Lvalue<'tcx>, rvalue: &mir::Rvalue<'
self.memory.write_usize(len_ptr, len)?;
}
LvalueExtra::DowncastVariant(..) =>
panic!("attempted to take a reference to an enum downcast lvalue"),
bug!("attempted to take a reference to an enum downcast lvalue"),
}
}
@@ -615,7 +614,7 @@ fn eval_assignment(&mut self, lvalue: &mir::Lvalue<'tcx>, rvalue: &mir::Rvalue<'
let fn_ptr = self.memory.create_fn_ptr(def_id, substs, fn_ty);
self.memory.write_ptr(dest, fn_ptr)?;
},
ref other => panic!("reify fn pointer on {:?}", other),
ref other => bug!("reify fn pointer on {:?}", other),
},
UnsafeFnPointer => match dest_ty.sty {
@@ -626,7 +625,7 @@ fn eval_assignment(&mut self, lvalue: &mir::Lvalue<'tcx>, rvalue: &mir::Rvalue<'
let fn_ptr = self.memory.create_fn_ptr(fn_def.def_id, fn_def.substs, unsafe_fn_ty);
self.memory.write_ptr(dest, fn_ptr)?;
},
ref other => panic!("fn to unsafe fn cast on {:?}", other),
ref other => bug!("fn to unsafe fn cast on {:?}", other),
},
}
}
@@ -649,10 +648,7 @@ fn nonnull_offset(&self, ty: Ty<'tcx>, nndiscr: u64, discrfield: &[u32]) -> Eval
let field = &variant.fields[index];
field.ty(self.tcx, substs)
}
_ => panic!(
"non-enum for StructWrappedNullablePointer: {}",
ty,
),
_ => bug!("non-enum for StructWrappedNullablePointer: {}", ty),
};
self.field_path_offset(inner_ty, path)
@@ -772,7 +768,7 @@ fn eval_lvalue(&mut self, lvalue: &mir::Lvalue<'tcx>) -> EvalResult<'tcx, Lvalue
if let LvalueExtra::DowncastVariant(variant_idx) = base.extra {
&variants[variant_idx]
} else {
panic!("field access on enum had no variant index");
bug!("field access on enum had no variant index");
}
}
RawNullablePointer { .. } => {
@@ -780,7 +776,7 @@ fn eval_lvalue(&mut self, lvalue: &mir::Lvalue<'tcx>) -> EvalResult<'tcx, Lvalue
return Ok(base);
}
StructWrappedNullablePointer { ref nonnull, .. } => nonnull,
_ => panic!("field access on non-product type: {:?}", base_layout),
_ => bug!("field access on non-product type: {:?}", base_layout),
};
let offset = variant.field_offset(field.index()).bytes();
@@ -799,7 +795,7 @@ fn eval_lvalue(&mut self, lvalue: &mir::Lvalue<'tcx>) -> EvalResult<'tcx, Lvalue
RawNullablePointer { .. } | StructWrappedNullablePointer { .. } => {
return Ok(base);
}
_ => panic!("variant downcast on non-aggregate: {:?}", base_layout),
_ => bug!("variant downcast on non-aggregate: {:?}", base_layout),
}
},
@@ -822,7 +818,7 @@ fn eval_lvalue(&mut self, lvalue: &mir::Lvalue<'tcx>) -> EvalResult<'tcx, Lvalue
let elem_size = match base_ty.sty {
ty::TyArray(elem_ty, _) |
ty::TySlice(elem_ty) => self.type_size(elem_ty),
_ => panic!("indexing expected an array or slice, got {:?}", base_ty),
_ => bug!("indexing expected an array or slice, got {:?}", base_ty),
};
let n_ptr = self.eval_operand(operand)?;
let n = self.memory.read_usize(n_ptr)?;
@@ -901,7 +897,7 @@ pub fn read_primval(&mut self, ptr: Pointer, ty: Ty<'tcx>) -> EvalResult<'tcx, P
}
}
_ => panic!("primitive read of non-primitive type: {:?}", ty),
_ => bug!("primitive read of non-primitive type: {:?}", ty),
};
Ok(val)
}
+2 -2
View File
@@ -198,7 +198,7 @@ fn eval_fn_call(
arg_srcs.push((src, ty));
}
}
ty => panic!("expected tuple as last argument in function with 'rust-call' ABI, got {:?}", ty),
ty => bug!("expected tuple as last argument in function with 'rust-call' ABI, got {:?}", ty),
}
}
@@ -523,7 +523,7 @@ fn trait_method(
// ty: def_ty(tcx, def_id, substs)
// }
}
vtable => unreachable!("resolved vtable bad vtable {:?} in trans", vtable),
vtable => bug!("resolved vtable bad vtable {:?} in trans", vtable),
}
}
+2 -2
View File
@@ -303,7 +303,7 @@ pub fn dump(&self, id: AllocId) {
println!("(deallocated)");
continue;
},
(Some(_), Some(_)) => unreachable!(),
(Some(_), Some(_)) => bug!("miri invariant broken: an allocation id exists that points to both a function and a memory location"),
};
for i in 0..alloc.bytes.len() {
@@ -481,7 +481,7 @@ fn int_align(&self, size: usize) -> EvalResult<'tcx, usize> {
2 => Ok(self.layout.i16_align.abi() as usize),
4 => Ok(self.layout.i32_align.abi() as usize),
8 => Ok(self.layout.i64_align.abi() as usize),
_ => panic!("bad integer size"),
_ => bug!("bad integer size"),
}
}
+12 -12
View File
@@ -49,8 +49,8 @@ macro_rules! int_binops {
BitOr => $v($l | $r),
// these have already been handled
Shl => unreachable!(),
Shr => unreachable!(),
Shl => bug!("`<<` operation should already have been handled"),
Shr => bug!("`>>` operation should already have been handled"),
Eq => Bool($l == $r),
Ne => Bool($l != $r),
@@ -72,11 +72,11 @@ macro_rules! float_binops {
Rem => $v($l % $r),
// invalid float ops
BitXor => unreachable!(),
BitAnd => unreachable!(),
BitOr => unreachable!(),
Shl => unreachable!(),
Shr => unreachable!(),
BitXor => bug!("`^` is not a valid operation on floats"),
BitAnd => bug!("`&` is not a valid operation on floats"),
BitOr => bug!("`|` is not a valid operation on floats"),
Shl => bug!("`<<` is not a valid operation on floats"),
Shr => bug!("`>>` is not a valid operation on floats"),
Eq => Bool($l == $r),
Ne => Bool($l != $r),
@@ -108,7 +108,7 @@ fn unrelated_ptr_ops<'tcx>(bin_op: mir::BinOp) -> EvalResult<'tcx, PrimVal> {
I16(_) | U16(_) => 16,
I32(_) | U32(_) => 32,
I64(_) | U64(_) => 64,
_ => unreachable!(),
_ => bug!("bad MIR: bitshift lhs is not integral"),
};
assert!(type_bits.is_power_of_two());
// turn into `u32` because `overflowing_sh{l,r}` only take `u32`
@@ -121,7 +121,7 @@ fn unrelated_ptr_ops<'tcx>(bin_op: mir::BinOp) -> EvalResult<'tcx, PrimVal> {
U16(i) => i as u32,
U32(i) => i as u32,
U64(i) => i as u32,
_ => panic!("bad MIR: bitshift rhs is not integral"),
_ => bug!("bad MIR: bitshift rhs is not integral"),
};
// apply mask
let r = r & (type_bits - 1);
@@ -130,7 +130,7 @@ macro_rules! shift {
match bin_op {
Shl => overflow!($v, U32, $l, overflowing_shl, $r),
Shr => overflow!($v, U32, $l, overflowing_shr, $r),
_ => unreachable!(),
_ => bug!("it has already been checked that this is a shift op"),
}
})
}
@@ -143,7 +143,7 @@ macro_rules! shift {
U16(l) => shift!(U16, l, r),
U32(l) => shift!(U32, l, r),
U64(l) => shift!(U64, l, r),
_ => unreachable!(),
_ => bug!("bad MIR: bitshift lhs is not integral (should already have been checked)"),
};
return Ok((val, false));
},
@@ -168,7 +168,7 @@ macro_rules! shift {
Le => Bool(l <= r),
Gt => Bool(l > r),
Ge => Bool(l >= r),
_ => panic!("invalid char op: {:?}", bin_op),
_ => bug!("invalid char op: {:?}", bin_op),
},
(Bool(l), Bool(r)) => {