Skip to content

Commit

Permalink
rustc_mir: disallow non-monomorphic reifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Aug 19, 2019
1 parent ceabe0d commit 7d9af83
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/librustc_mir/interpret/cast.rs
@@ -1,4 +1,4 @@
use rustc::ty::{self, Ty, TypeAndMut};
use rustc::ty::{self, Ty, TypeAndMut, TypeFoldable};
use rustc::ty::layout::{self, TyLayout, Size};
use rustc::ty::adjustment::{PointerCast};
use syntax::ast::FloatTy;
Expand Down Expand Up @@ -36,6 +36,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
// The src operand does not matter, just its type
match src.layout.ty.sty {
ty::FnDef(def_id, substs) => {
// All reifications must be monomorphic, bail out otherwise.
if src.layout.ty.needs_subst() {
throw_inval!(TooGeneric);
}

if self.tcx.has_attr(def_id, sym::rustc_args_required_const) {
bug!("reifying a fn ptr that requires const arguments");
}
Expand All @@ -62,6 +67,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
// The src operand does not matter, just its type
match src.layout.ty.sty {
ty::Closure(def_id, substs) => {
// All reifications must be monomorphic, bail out otherwise.
if src.layout.ty.needs_subst() {
throw_inval!(TooGeneric);
}

let instance = ty::Instance::resolve_closure(
*self.tcx,
def_id,
Expand Down

0 comments on commit 7d9af83

Please sign in to comment.