Replace structurally_resolved_type in casts check.

The behaviour of `resolve_type_vars_if_possible` is simpler and
infallible.
This commit is contained in:
leonardo.yvens 2018-02-16 11:16:41 -02:00
parent 5092c6b01a
commit 7719f53419
2 changed files with 4 additions and 9 deletions

View file

@ -20,7 +20,6 @@ use syntax::ast;
pub enum IntTy {
U(ast::UintTy),
I,
Ivar,
CEnum,
Bool,
Char
@ -64,7 +63,7 @@ impl<'tcx> CastTy<'tcx> {
ty::TyBool => Some(CastTy::Int(IntTy::Bool)),
ty::TyChar => Some(CastTy::Int(IntTy::Char)),
ty::TyInt(_) => Some(CastTy::Int(IntTy::I)),
ty::TyInfer(ty::InferTy::IntVar(_)) => Some(CastTy::Int(IntTy::Ivar)),
ty::TyInfer(ty::InferTy::IntVar(_)) => Some(CastTy::Int(IntTy::I)),
ty::TyInfer(ty::InferTy::FloatVar(_)) => Some(CastTy::Float),
ty::TyUint(u) => Some(CastTy::Int(IntTy::U(u))),
ty::TyFloat(_) => Some(CastTy::Float),

View file

@ -389,8 +389,8 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
}
pub fn check(mut self, fcx: &FnCtxt<'a, 'gcx, 'tcx>) {
self.expr_ty = fcx.structurally_resolved_type(self.span, self.expr_ty);
self.cast_ty = fcx.structurally_resolved_type(self.span, self.cast_ty);
self.expr_ty = fcx.resolve_type_vars_if_possible(&self.expr_ty);
self.cast_ty = fcx.resolve_type_vars_if_possible(&self.cast_ty);
debug!("check_cast({}, {:?} as {:?})",
self.expr.id,
@ -484,11 +484,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
ty::TypeVariants::TyInfer(t) => {
match t {
ty::InferTy::IntVar(_) |
ty::InferTy::FloatVar(_) |
ty::InferTy::FreshIntTy(_) |
ty::InferTy::FreshFloatTy(_) => {
Err(CastError::NeedDeref)
}
ty::InferTy::FloatVar(_) => Err(CastError::NeedDeref),
_ => Err(CastError::NeedViaPtr),
}
}