]> git.lizzy.rs Git - rust.git/commitdiff
Miri: replace many bug! by span_bug!
authorRalf Jung <post@ralfj.de>
Sun, 21 Jun 2020 14:13:31 +0000 (16:13 +0200)
committerRalf Jung <post@ralfj.de>
Sun, 21 Jun 2020 14:13:31 +0000 (16:13 +0200)
src/librustc_mir/interpret/cast.rs
src/librustc_mir/interpret/eval_context.rs
src/librustc_mir/interpret/intrinsics.rs
src/librustc_mir/interpret/operand.rs
src/librustc_mir/interpret/operator.rs
src/librustc_mir/interpret/terminator.rs

index cfe856abe36dda2ca6c6c073417d1c864c711138..60cf21552e9e91102bbd368bd6aa3511dd5bf95f 100644 (file)
@@ -52,7 +52,10 @@ pub fn cast(
                         }
 
                         if self.tcx.has_attr(def_id, sym::rustc_args_required_const) {
-                            bug!("reifying a fn ptr that requires const arguments");
+                            span_bug!(
+                                self.cur_span(),
+                                "reifying a fn ptr that requires const arguments"
+                            );
                         }
 
                         let instance = ty::Instance::resolve_for_fn_ptr(
@@ -66,7 +69,7 @@ pub fn cast(
                         let fn_ptr = self.memory.create_fn_alloc(FnVal::Instance(instance));
                         self.write_scalar(fn_ptr, dest)?;
                     }
-                    _ => bug!("reify fn pointer on {:?}", src.layout.ty),
+                    _ => span_bug!(self.cur_span(), "reify fn pointer on {:?}", src.layout.ty),
                 }
             }
 
@@ -77,7 +80,7 @@ pub fn cast(
                         // No change to value
                         self.write_immediate(*src, dest)?;
                     }
-                    _ => bug!("fn to unsafe fn cast on {:?}", cast_ty),
+                    _ => span_bug!(self.cur_span(), "fn to unsafe fn cast on {:?}", cast_ty),
                 }
             }
 
@@ -99,7 +102,7 @@ pub fn cast(
                         let fn_ptr = self.memory.create_fn_alloc(FnVal::Instance(instance));
                         self.write_scalar(fn_ptr, dest)?;
                     }
-                    _ => bug!("closure fn pointer on {:?}", src.layout.ty),
+                    _ => span_bug!(self.cur_span(), "closure fn pointer on {:?}", src.layout.ty),
                 }
             }
         }
@@ -162,7 +165,8 @@ fn misc_cast(
                 assert!(src.layout.ty.is_unsafe_ptr());
                 return match *src {
                     Immediate::ScalarPair(data, _) => Ok(data.into()),
-                    Immediate::Scalar(..) => bug!(
+                    Immediate::Scalar(..) => span_bug!(
+                        self.cur_span(),
                         "{:?} input to a fat-to-thin cast ({:?} -> {:?})",
                         *src,
                         src.layout.ty,
@@ -216,7 +220,7 @@ pub(super) fn cast_from_scalar(
             }
 
             // Casts to bool are not permitted by rustc, no need to handle them here.
-            _ => bug!("invalid int to {:?} cast", cast_ty),
+            _ => span_bug!(self.cur_span(), "invalid int to {:?} cast", cast_ty),
         }
     }
 
@@ -248,7 +252,7 @@ fn cast_from_float<F>(&self, f: F, dest_ty: Ty<'tcx>) -> Scalar<M::PointerTag>
             // float -> f64
             Float(FloatTy::F64) => Scalar::from_f64(f.convert(&mut false).value),
             // That's it.
-            _ => bug!("invalid float to {:?} cast", dest_ty),
+            _ => span_bug!(self.cur_span(), "invalid float to {:?} cast", dest_ty),
         }
     }
 
@@ -287,7 +291,9 @@ fn unsize_into_ptr(
                 self.write_immediate(val, dest)
             }
 
-            _ => bug!("invalid unsizing {:?} -> {:?}", src.layout.ty, cast_ty),
+            _ => {
+                span_bug!(self.cur_span(), "invalid unsizing {:?} -> {:?}", src.layout.ty, cast_ty)
+            }
         }
     }
 
@@ -307,7 +313,12 @@ fn unsize_into(
                 assert_eq!(def_a, def_b);
                 if def_a.is_box() || def_b.is_box() {
                     if !def_a.is_box() || !def_b.is_box() {
-                        bug!("invalid unsizing between {:?} -> {:?}", src.layout.ty, cast_ty.ty);
+                        span_bug!(
+                            self.cur_span(),
+                            "invalid unsizing between {:?} -> {:?}",
+                            src.layout.ty,
+                            cast_ty.ty
+                        );
                     }
                     return self.unsize_into_ptr(
                         src,
@@ -335,7 +346,12 @@ fn unsize_into(
                 }
                 Ok(())
             }
-            _ => bug!("unsize_into: invalid conversion: {:?} -> {:?}", src.layout, dest.layout),
+            _ => span_bug!(
+                self.cur_span(),
+                "unsize_into: invalid conversion: {:?} -> {:?}",
+                src.layout,
+                dest.layout
+            ),
         }
     }
 }
index 22f4691c22b3de81226fe406c8fafd6c427c04bd..ceacbbe5139bf3508587b2f9493896961923c1e8 100644 (file)
@@ -536,7 +536,10 @@ pub(super) fn size_and_align_of(
                         if sized_size == Size::ZERO {
                             return Ok(None);
                         } else {
-                            bug!("Fields cannot be extern types, unless they are at offset 0")
+                            span_bug!(
+                                self.cur_span(),
+                                "Fields cannot be extern types, unless they are at offset 0"
+                            )
                         }
                     }
                 };
@@ -584,7 +587,7 @@ pub(super) fn size_and_align_of(
 
             ty::Foreign(_) => Ok(None),
 
-            _ => bug!("size_and_align_of::<{:?}> not supported", layout.ty),
+            _ => span_bug!(self.cur_span(), "size_and_align_of::<{:?}> not supported", layout.ty),
         }
     }
     #[inline]
index ac28ccd181520f7092cb546e3fb83b014ef5f39e..31bdc45a2eab9432a901bec4cd87382355e5ed22 100644 (file)
@@ -135,7 +135,12 @@ pub fn emulate_intrinsic(
                 let bits = self.force_bits(val, layout_of.size)?;
                 let kind = match layout_of.abi {
                     Abi::Scalar(ref scalar) => scalar.value,
-                    _ => bug!("{} called on invalid type {:?}", intrinsic_name, ty),
+                    _ => span_bug!(
+                        self.cur_span(),
+                        "{} called on invalid type {:?}",
+                        intrinsic_name,
+                        ty
+                    ),
                 };
                 let (nonzero, intrinsic_name) = match intrinsic_name {
                     sym::cttz_nonzero => (true, sym::cttz),
index 35e433c4bd5cd28a3b20844619fce6db1f27297e..38948ee53846ae119bc4de38bf37612e1880d41d 100644 (file)
@@ -311,7 +311,7 @@ pub fn read_immediate(
         if let Ok(imm) = self.try_read_immediate(op)? {
             Ok(imm)
         } else {
-            bug!("primitive read failed for type: {:?}", op.layout.ty);
+            span_bug!(self.cur_span(), "primitive read failed for type: {:?}", op.layout.ty);
         }
     }
 
@@ -360,9 +360,12 @@ pub fn operand_field(
                 let val = if offset.bytes() == 0 { a } else { b };
                 Immediate::from(val)
             }
-            Immediate::Scalar(val) => {
-                bug!("field access on non aggregate {:#?}, {:#?}", val, op.layout)
-            }
+            Immediate::Scalar(val) => span_bug!(
+                self.cur_span(),
+                "field access on non aggregate {:#?}, {:#?}",
+                val,
+                op.layout
+            ),
         };
         Ok(OpTy { op: Operand::Immediate(immediate), layout: field_layout })
     }
@@ -545,7 +548,7 @@ pub(super) fn eval_operands(
             ty::ConstKind::Infer(..)
             | ty::ConstKind::Bound(..)
             | ty::ConstKind::Placeholder(..) => {
-                bug!("eval_const_to_op: Unexpected ConstKind {:?}", val)
+                span_bug!(self.cur_span(), "eval_const_to_op: Unexpected ConstKind {:?}", val)
             }
             ty::ConstKind::Value(val_val) => val_val,
         };
@@ -656,7 +659,7 @@ pub fn read_discriminant(
                             .discriminants(def_id, *self.tcx)
                             .find(|(_, var)| var.val == discr_bits)
                     }
-                    _ => bug!("tagged layout for non-adt non-generator"),
+                    _ => span_bug!(self.cur_span(), "tagged layout for non-adt non-generator"),
                 }
                 .ok_or_else(|| err_ub!(InvalidTag(tag_val.erase_tag())))?;
                 // Return the cast value, and the index.
index d651267f82b7943e38e43189186592267a75c5f9..607122935347e127537b59185385f0d7c44513cd 100644 (file)
@@ -61,7 +61,7 @@ fn binary_char_op(
             Le => l <= r,
             Gt => l > r,
             Ge => l >= r,
-            _ => bug!("Invalid operation on char: {:?}", bin_op),
+            _ => span_bug!(self.cur_span(), "Invalid operation on char: {:?}", bin_op),
         };
         (Scalar::from_bool(res), false, self.tcx.types.bool)
     }
@@ -84,7 +84,7 @@ fn binary_bool_op(
             BitAnd => l & r,
             BitOr => l | r,
             BitXor => l ^ r,
-            _ => bug!("Invalid operation on bool: {:?}", bin_op),
+            _ => span_bug!(self.cur_span(), "Invalid operation on bool: {:?}", bin_op),
         };
         (Scalar::from_bool(res), false, self.tcx.types.bool)
     }
@@ -110,7 +110,7 @@ fn binary_float_op<F: Float + Into<Scalar<M::PointerTag>>>(
             Mul => ((l * r).value.into(), ty),
             Div => ((l / r).value.into(), ty),
             Rem => ((l % r).value.into(), ty),
-            _ => bug!("invalid float op: `{:?}`", bin_op),
+            _ => span_bug!(self.cur_span(), "invalid float op: `{:?}`", bin_op),
         };
         (val, false, ty)
     }
@@ -154,7 +154,8 @@ fn binary_int_op(
 
         // For the remaining ops, the types must be the same on both sides
         if left_layout.ty != right_layout.ty {
-            bug!(
+            span_bug!(
+                self.cur_span(),
                 "invalid asymmetric binary op {:?}: {:?} ({:?}), {:?} ({:?})",
                 bin_op,
                 l,
@@ -251,7 +252,8 @@ fn binary_int_op(
                 ));
             }
 
-            _ => bug!(
+            _ => span_bug!(
+                self.cur_span(),
                 "invalid binary op {:?}: {:?}, {:?} (both {:?})",
                 bin_op,
                 l,
@@ -333,7 +335,11 @@ pub fn overflowing_binary_op(
 
                 M::binary_ptr_op(self, bin_op, left, right)
             }
-            _ => bug!("Invalid MIR: bad LHS type for binop: {:?}", left.layout.ty),
+            _ => span_bug!(
+                self.cur_span(),
+                "Invalid MIR: bad LHS type for binop: {:?}",
+                left.layout.ty
+            ),
         }
     }
 
@@ -367,7 +373,7 @@ pub fn overflowing_unary_op(
                 let val = val.to_bool()?;
                 let res = match un_op {
                     Not => !val,
-                    _ => bug!("Invalid bool op {:?}", un_op),
+                    _ => span_bug!(self.cur_span(), "Invalid bool op {:?}", un_op),
                 };
                 Ok((Scalar::from_bool(res), false, self.tcx.types.bool))
             }
@@ -375,7 +381,7 @@ pub fn overflowing_unary_op(
                 let res = match (un_op, fty) {
                     (Neg, FloatTy::F32) => Scalar::from_f32(-val.to_f32()?),
                     (Neg, FloatTy::F64) => Scalar::from_f64(-val.to_f64()?),
-                    _ => bug!("Invalid float op {:?}", un_op),
+                    _ => span_bug!(self.cur_span(), "Invalid float op {:?}", un_op),
                 };
                 Ok((res, false, layout.ty))
             }
index 1d57fce39734e9119c93f8cf8a21030a00fca6d7..0f3fbcf8195748e20ee222fe5f8ae850ccbdfb6d 100644 (file)
@@ -232,7 +232,7 @@ fn eval_fn_call(
                     ty::FnDef(..) => instance_ty.fn_sig(*self.tcx).abi(),
                     ty::Closure(..) => Abi::RustCall,
                     ty::Generator(..) => Abi::Rust,
-                    _ => bug!("unexpected callee ty: {:?}", instance_ty),
+                    _ => span_bug!(self.cur_span(), "unexpected callee ty: {:?}", instance_ty),
                 }
             };
             let normalize_abi = |abi| match abi {