Skip to content

Commit 7d9af83

Browse files
committed
rustc_mir: disallow non-monomorphic reifications.
1 parent ceabe0d commit 7d9af83

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/librustc_mir/interpret/cast.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc::ty::{self, Ty, TypeAndMut};
1+
use rustc::ty::{self, Ty, TypeAndMut, TypeFoldable};
22
use rustc::ty::layout::{self, TyLayout, Size};
33
use rustc::ty::adjustment::{PointerCast};
44
use syntax::ast::FloatTy;
@@ -36,6 +36,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
3636
// The src operand does not matter, just its type
3737
match src.layout.ty.sty {
3838
ty::FnDef(def_id, substs) => {
39+
// All reifications must be monomorphic, bail out otherwise.
40+
if src.layout.ty.needs_subst() {
41+
throw_inval!(TooGeneric);
42+
}
43+
3944
if self.tcx.has_attr(def_id, sym::rustc_args_required_const) {
4045
bug!("reifying a fn ptr that requires const arguments");
4146
}
@@ -62,6 +67,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
6267
// The src operand does not matter, just its type
6368
match src.layout.ty.sty {
6469
ty::Closure(def_id, substs) => {
70+
// All reifications must be monomorphic, bail out otherwise.
71+
if src.layout.ty.needs_subst() {
72+
throw_inval!(TooGeneric);
73+
}
74+
6575
let instance = ty::Instance::resolve_closure(
6676
*self.tcx,
6777
def_id,

0 commit comments

Comments
 (0)