Skip to content

Commit b2392aa

Browse files
committed
dont ICE in case of invalid drop fn
1 parent f284f8b commit b2392aa

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/librustc_mir/interpret/traits.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,18 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
140140
let fn_sig = drop_instance.ty(*self.tcx).fn_sig(*self.tcx);
141141
let fn_sig = self.tcx.normalize_erasing_late_bound_regions(self.param_env, &fn_sig);
142142
// The drop function takes `*mut T` where `T` is the type being dropped, so get that.
143-
let ty = fn_sig.inputs()[0].builtin_deref(true).unwrap().ty;
143+
let args = fn_sig.inputs();
144+
if args.len() != 1 {
145+
throw_ub_format!(
146+
"drop fn should have 1 argument, but signature is {:?}", fn_sig
147+
);
148+
}
149+
let ty = args[0].builtin_deref(true)
150+
.ok_or_else(|| err_ub_format!(
151+
"drop fn argument type {} is not a pointer type",
152+
args[0]
153+
))?
154+
.ty;
144155
Ok((drop_instance, ty))
145156
}
146157

0 commit comments

Comments
 (0)