Skip to content

Commit 8529bda

Browse files
committed
Validate fn-sig and erased lifetimes in MIR validator.
1 parent 29adf97 commit 8529bda

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

compiler/rustc_const_eval/src/transform/validate.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,23 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
808808
TerminatorKind::Call { func, args, destination, target, cleanup, .. } => {
809809
let func_ty = func.ty(&self.body.local_decls, self.tcx);
810810
match func_ty.kind() {
811-
ty::FnPtr(..) | ty::FnDef(..) => {}
811+
ty::FnPtr(..) => {}
812+
ty::FnDef(def_id, substs) => {
813+
if cfg!(debug_assertions) {
814+
debug!(?def_id, ?substs);
815+
let generics = self.tcx.generics_of(def_id);
816+
debug_assert_eq!(generics.count(), substs.len());
817+
let fn_sig = self.tcx.bound_fn_sig(*def_id);
818+
let _ = fn_sig.subst(self.tcx, *substs);
819+
for arg in substs.iter() {
820+
if let ty::GenericArgKind::Lifetime(lt) = arg.unpack()
821+
&& lt != self.tcx.lifetimes.re_erased
822+
{
823+
panic!("{substs:?} contains non-erased lifetimes");
824+
}
825+
}
826+
}
827+
}
812828
_ => self.fail(
813829
location,
814830
format!("encountered non-callable type {} in `Call` terminator", func_ty),

0 commit comments

Comments
 (0)