Skip to content
Permalink
Browse files

dont ICE in case of invalid drop fn

  • Loading branch information
RalfJung committed Dec 12, 2019
1 parent f284f8b commit b2392aa2fcf0b4638b5db42fab12b1a4d2d98e28
Showing with 12 additions and 1 deletion.
  1. +12 −1 src/librustc_mir/interpret/traits.rs
@@ -140,7 +140,18 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
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))
}

0 comments on commit b2392aa

Please sign in to comment.
You can’t perform that action at this time.