1
Fork 0

prevent intrinsics from creating uninhabited types

This commit is contained in:
Oliver Schneider 2017-01-12 10:37:14 +01:00
parent b5f824fd9c
commit a58170a4c6
No known key found for this signature in database
GPG key ID: 56D6EEA0FC67AC46
2 changed files with 8 additions and 3 deletions

View file

@ -10,6 +10,7 @@ use rustc::ty::layout::{self, Layout, Size};
use rustc::ty::subst::{self, Subst, Substs};
use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
use rustc_data_structures::indexed_vec::Idx;
use rustc_data_structures::fx::FxHashSet;
use syntax::codemap::{self, DUMMY_SP};
use error::{EvalError, EvalResult};
@ -1468,3 +1469,7 @@ pub fn monomorphize_field_ty<'a, 'tcx:'a >(tcx: TyCtxt<'a, 'tcx, 'tcx>, f: &ty::
let substituted = &f.ty(tcx, substs);
tcx.normalize_associated_type(&substituted)
}
pub fn is_inhabited<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
ty.uninhabited_from(&mut FxHashSet::default(), tcx).is_empty()
}

View file

@ -9,7 +9,7 @@ use syntax::codemap::{DUMMY_SP, Span};
use syntax::{ast, attr};
use error::{EvalError, EvalResult};
use eval_context::{EvalContext, IntegerExt, StackPopCleanup, monomorphize_field_ty};
use eval_context::{EvalContext, IntegerExt, StackPopCleanup, monomorphize_field_ty, is_inhabited};
use lvalue::{Lvalue, LvalueExtra};
use memory::Pointer;
use value::PrimVal;
@ -201,8 +201,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
let ty = fn_ty.sig.0.output();
let layout = self.type_layout(ty)?;
let (ret, target) = match destination {
Some(dest) => dest,
None => return Err(EvalError::Unreachable),
Some(dest) if is_inhabited(self.tcx, ty) => dest,
_ => return Err(EvalError::Unreachable),
};
self.call_intrinsic(def_id, substs, arg_operands, ret, ty, layout, target)?;
Ok(())