diff --git a/src/bin/miri.rs b/src/bin/miri.rs index 4fc20c96d216..15a970586b80 100644 --- a/src/bin/miri.rs +++ b/src/bin/miri.rs @@ -44,7 +44,7 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls { 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() { diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index 0afca11c0ac5..d463cc69914b 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -187,9 +187,9 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { 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 @@ impl<'a, 'tcx> EvalContext<'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 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { 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 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { 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 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { .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 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { 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 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { 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 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { 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 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { 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 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { 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 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { 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 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { 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 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { 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 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { 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 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { 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 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { 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 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { 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 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { 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 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { } } - _ => panic!("primitive read of non-primitive type: {:?}", ty), + _ => bug!("primitive read of non-primitive type: {:?}", ty), }; Ok(val) } diff --git a/src/interpreter/terminator.rs b/src/interpreter/terminator.rs index 159cfd09ed36..1f45c36acd4b 100644 --- a/src/interpreter/terminator.rs +++ b/src/interpreter/terminator.rs @@ -198,7 +198,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { 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 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { // 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), } } diff --git a/src/memory.rs b/src/memory.rs index d99d2c8132e3..3cf0bc97557b 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -303,7 +303,7 @@ impl<'a, 'tcx> Memory<'a, 'tcx> { 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 @@ impl<'a, 'tcx> Memory<'a, 'tcx> { 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"), } } diff --git a/src/primval.rs b/src/primval.rs index 1ec751681703..0c26dac9ec91 100644 --- a/src/primval.rs +++ b/src/primval.rs @@ -49,8 +49,8 @@ pub fn binary_op<'tcx>(bin_op: mir::BinOp, left: PrimVal, right: PrimVal) -> Eva 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 @@ pub fn binary_op<'tcx>(bin_op: mir::BinOp, left: PrimVal, right: PrimVal) -> Eva 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 @@ pub fn binary_op<'tcx>(bin_op: mir::BinOp, left: PrimVal, right: PrimVal) -> Eva 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 @@ pub fn binary_op<'tcx>(bin_op: mir::BinOp, left: PrimVal, right: PrimVal) -> Eva 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 @@ pub fn binary_op<'tcx>(bin_op: mir::BinOp, left: PrimVal, right: PrimVal) -> Eva 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 @@ pub fn binary_op<'tcx>(bin_op: mir::BinOp, left: PrimVal, right: PrimVal) -> Eva 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 @@ pub fn binary_op<'tcx>(bin_op: mir::BinOp, left: PrimVal, right: PrimVal) -> Eva 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)) => {