]> git.lizzy.rs Git - rust.git/commitdiff
dont ICE in case of invalid drop fn
authorRalf Jung <post@ralfj.de>
Thu, 12 Dec 2019 14:23:27 +0000 (15:23 +0100)
committerRalf Jung <post@ralfj.de>
Thu, 12 Dec 2019 14:23:27 +0000 (15:23 +0100)
src/librustc_mir/interpret/traits.rs

index efa0d266cbc21c410e70a65c2ccd4634a09ad917..916ea3dc393e98294a6b43221c57ed48c07754a8 100644 (file)
@@ -140,7 +140,18 @@ pub fn read_drop_type_from_vtable(
         let fn_sig = drop_instance.ty(*self.tcx).fn_sig(*self.tcx);
         let fn_sig = self.tcx.normalize_erasing_late_bound_regions(self.param_env, &fn_sig);
         // The drop function takes `*mut T` where `T` is the type being dropped, so get that.
-        let ty = fn_sig.inputs()[0].builtin_deref(true).unwrap().ty;
+        let args = fn_sig.inputs();
+        if args.len() != 1 {
+            throw_ub_format!(
+                "drop fn should have 1 argument, but signature is {:?}", fn_sig
+            );
+        }
+        let ty = args[0].builtin_deref(true)
+            .ok_or_else(|| err_ub_format!(
+                "drop fn argument type {} is not a pointer type",
+                args[0]
+            ))?
+            .ty;
         Ok((drop_instance, ty))
     }