prevent intrinsics from creating uninhabited types
This commit is contained in:
parent
b5f824fd9c
commit
a58170a4c6
2 changed files with 8 additions and 3 deletions
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue